Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
db365b161b
Commit
5cc2e7e7b5
@ -21,8 +21,6 @@ package de.steamwar.fightsystem;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.ai.DummyAI;
|
||||
import de.steamwar.fightsystem.ai.lixfel.LixfelAI;
|
||||
import de.steamwar.fightsystem.commands.*;
|
||||
import de.steamwar.fightsystem.countdown.*;
|
||||
import de.steamwar.fightsystem.event.HellsBells;
|
||||
@ -183,14 +181,6 @@ public class FightSystem extends JavaPlugin {
|
||||
}else if(Config.mode == ArenaMode.PREPARE) {
|
||||
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
|
||||
}
|
||||
|
||||
//TODO REMOVE PRIOR TO MERGE
|
||||
FightStatistics.unrank();
|
||||
FightWorld.forceLoad();
|
||||
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> {
|
||||
new LixfelAI(Fight.getBlueTeam(), "Lixfel.AI");
|
||||
new DummyAI(Fight.getRedTeam(), "public");
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,6 +83,8 @@ SCHEM_PRIVATE=§ePrivate {0}
|
||||
SCHEM_NO_PRIVATE=§7No private {0} present
|
||||
SCHEM_PRIVATE_FORBIDDEN=§7No private {0} allowed
|
||||
|
||||
ADD_AI_TITLE=Add AI
|
||||
|
||||
|
||||
# Countdowns
|
||||
COUNTDOWN_MINUTES=§e{0} §7Minutes {1}
|
||||
@ -114,6 +116,7 @@ RESPAWN=§eRespawn
|
||||
REMOVE_PLAYERS=§cKick player
|
||||
CHOOSE_SCHEMATIC=§eChoose {0}
|
||||
SCHEMATIC_REQUIRED=§cChoose a schematic first
|
||||
ADD_AI=§eAdd AI
|
||||
|
||||
KIT_PREVIEW_EDIT=§7Edit kit
|
||||
KIT_PREVIEW_CHOOSE=§aSelect kit
|
||||
|
@ -77,6 +77,8 @@ SCHEM_PRIVATE=§ePrivates {0}
|
||||
SCHEM_NO_PRIVATE=§7Kein privates {0} vorhanden
|
||||
SCHEM_PRIVATE_FORBIDDEN=§7Kein privates {0} erlaubt
|
||||
|
||||
ADD_AI_TITLE=KI hinzufügen
|
||||
|
||||
|
||||
# Countdowns
|
||||
COUNTDOWN_MINUTES=§e{0} §7Minuten {1}
|
||||
@ -107,6 +109,7 @@ RESPAWN=§eRespawn
|
||||
REMOVE_PLAYERS=§cSpieler rauswerfen
|
||||
CHOOSE_SCHEMATIC=§e{0} wählen
|
||||
SCHEMATIC_REQUIRED=§cZuerst muss eine Schematic gewählt sein
|
||||
ADD_AI=§eKI hinzufügen
|
||||
|
||||
KIT_PREVIEW_EDIT=§7Kit bearbeiten
|
||||
KIT_PREVIEW_CHOOSE=§aKit wählen
|
||||
|
@ -19,17 +19,20 @@
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.fight.JoinRequest;
|
||||
import de.steamwar.fightsystem.listener.Chat;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.utils.Region;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -47,7 +50,6 @@ import org.bukkit.block.data.type.Repeater;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -62,9 +64,12 @@ public abstract class AI {
|
||||
public static final double INTERACTION_RANGE = 5.0;
|
||||
|
||||
private static final Map<UUID, AI> ais = new HashMap<>();
|
||||
public static void printPos() {
|
||||
ais.values().forEach(ai -> ai.chat(ai.entity.isValid() + " " + ai.entity.isDead() + " " + ai.entity.getLocation()));
|
||||
}
|
||||
|
||||
static {
|
||||
new OneShotStateDependent(ArenaMode.All, FightState.Spectate, () -> {
|
||||
new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Spectate, () -> {
|
||||
ais.values().forEach(AI::stop);
|
||||
ais.clear();
|
||||
});
|
||||
@ -75,6 +80,7 @@ public abstract class AI {
|
||||
}
|
||||
|
||||
protected final FightTeam team;
|
||||
@Getter
|
||||
private final LivingEntity entity;
|
||||
private final BukkitTask task;
|
||||
private final Queue<Action> queue = new ArrayDeque<>();
|
||||
@ -89,11 +95,15 @@ public abstract class AI {
|
||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
|
||||
ais.put(entity.getUniqueId(), this);
|
||||
team.addMember(entity, user);
|
||||
|
||||
if(FightState.Schem.contains(FightState.getFightState()))
|
||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> schematic(team.getClipboard()));
|
||||
}
|
||||
|
||||
public abstract SchematicNode chooseSchematic();
|
||||
public abstract void schematic(Clipboard clipboard);
|
||||
|
||||
public boolean acceptJoinRequest(Player player, FightTeam team) {
|
||||
public boolean acceptJoinRequest(JoinRequest.Enquirer enquirer, FightTeam team) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -107,10 +117,6 @@ public abstract class AI {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
public LivingEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setReady() {
|
||||
if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||
return;
|
||||
@ -162,7 +168,7 @@ public abstract class AI {
|
||||
|
||||
Location location = translate(pos, true);
|
||||
if(interactionDistanceViolation(location)) {
|
||||
chat("2 smoll pepe hönds!");
|
||||
chat("InteractionDistanceViolation: setTNT");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -179,7 +185,7 @@ public abstract class AI {
|
||||
public void run() {
|
||||
Location location = translate(pos, true);
|
||||
if(interactionDistanceViolation(location)) {
|
||||
chat("Ich komme da nicht dran!");
|
||||
chat("InteractionDistanceViolation: interact");
|
||||
return;
|
||||
}
|
||||
|
||||
|
60
FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java
Normale Datei
60
FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java
Normale Datei
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.ai.chaos.ChaosAI;
|
||||
import de.steamwar.fightsystem.ai.lixfel.LixfelAI;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class AIManager {
|
||||
private static final List<AIManager> AIs = Arrays.asList(
|
||||
new AIManager(DummyAI.class, Material.STONE, () -> true),
|
||||
new AIManager(LixfelAI.class, Material.TNT, () -> Config.SchematicType.toDB().equals("miniwargear")),
|
||||
new AIManager(ChaosAI.class, Material.SLIME_BLOCK, () -> Config.SchematicType.toDB().equals("miniwargear"))
|
||||
);
|
||||
|
||||
public static List<AIManager> availableAIs() {
|
||||
return AIs.stream().filter(manager -> manager.available.getAsBoolean()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private final Class<? extends AI> aiClass;
|
||||
@Getter
|
||||
private final Material icon;
|
||||
private final BooleanSupplier available;
|
||||
|
||||
public String name() {
|
||||
return aiClass.getSimpleName();
|
||||
}
|
||||
|
||||
public void join(FightTeam team) {
|
||||
Reflection.getConstructor(aiClass, FightTeam.class).invoke(team);
|
||||
}
|
||||
}
|
@ -19,9 +19,11 @@
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.FightStatistics;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
|
||||
@ -30,8 +32,10 @@ import java.util.Random;
|
||||
|
||||
public class DummyAI extends AI {
|
||||
|
||||
public DummyAI(FightTeam team, String user) {
|
||||
super(team, SteamwarUser.get(user));
|
||||
public DummyAI(FightTeam team) {
|
||||
super(team, SteamwarUser.get("public"));
|
||||
|
||||
FightStatistics.unrank();
|
||||
getEntity().setInvulnerable(true);
|
||||
}
|
||||
|
||||
@ -41,6 +45,11 @@ public class DummyAI extends AI {
|
||||
return publics.get(new Random().nextInt(publics.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schematic(Clipboard clipboard) {
|
||||
//does nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void plan() {
|
||||
if(FightState.getFightState() == FightState.POST_SCHEM_SETUP)
|
||||
|
@ -24,15 +24,13 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.ai.AI;
|
||||
import de.steamwar.fightsystem.ai.lixfel.LixfelPathplanner;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.fight.JoinRequest;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.sql.SchematicData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ChaosAI extends AI {
|
||||
@ -70,16 +68,12 @@ public class ChaosAI extends AI {
|
||||
|
||||
@Override
|
||||
public SchematicNode chooseSchematic() {
|
||||
SchematicNode schem = SchematicNode.getSchematicNode(111476);
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
clipboard = new SchematicData(schem).load();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
return SchematicNode.getSchematicNode(111476);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schematic(Clipboard clipboard) {
|
||||
pathplanner = new LixfelPathplanner(this, clipboard);
|
||||
return schem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,7 +140,7 @@ public class ChaosAI extends AI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptJoinRequest(Player player, FightTeam team) {
|
||||
public boolean acceptJoinRequest(JoinRequest.Enquirer enquirer, FightTeam team) {
|
||||
return team == this.team;
|
||||
}
|
||||
|
||||
|
@ -26,15 +26,14 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.ai.AI;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.sql.SchematicData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -42,25 +41,23 @@ public class LixfelAI extends AI {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private List<Supplier<PlanResult>> plans;
|
||||
private List<Supplier<PlanResult>> plans = new ArrayList<>();
|
||||
private LixfelPathplanner pathplanner;
|
||||
private MovementEmergency movementEmergency;
|
||||
|
||||
public LixfelAI(FightTeam team, String user) {
|
||||
super(team, SteamwarUser.get(user));
|
||||
public LixfelAI(FightTeam team) {
|
||||
super(team, SteamwarUser.get("Lixfel.AI"));
|
||||
//getEntity().setGlowing(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode chooseSchematic() {
|
||||
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB());
|
||||
SchematicNode schem = publics.stream().filter(s -> s.getName().equals("TheUnderground")).findAny().orElseGet(() -> publics.get(random.nextInt(publics.size())));
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
clipboard = new SchematicData(schem).load();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
return publics.stream().filter(s -> s.getName().equals("TheUnderground")).findAny().orElseGet(() -> publics.get(random.nextInt(publics.size())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schematic(Clipboard clipboard) {
|
||||
pathplanner = new LixfelPathplanner(this, clipboard);
|
||||
movementEmergency = new MovementEmergency();
|
||||
|
||||
@ -68,6 +65,7 @@ public class LixfelAI extends AI {
|
||||
plans = new ArrayList<>();
|
||||
plans.add(movementEmergency);
|
||||
plans.add(new ReadyPlan());
|
||||
|
||||
plans.add(new TimedInteraction(200.0, -1, new Vector(25, 15, 25)));
|
||||
plans.add(new TimedInteraction(210.0, 420, new Vector(21, 15, 24)));
|
||||
|
||||
@ -82,8 +80,6 @@ public class LixfelAI extends AI {
|
||||
));
|
||||
assignWater(cannons, clipboard);
|
||||
plans.addAll(cannons);
|
||||
|
||||
return schem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,13 +117,10 @@ public class LixfelAI extends AI {
|
||||
}
|
||||
}
|
||||
|
||||
@Setter
|
||||
private class MovementEmergency implements Supplier<PlanResult> {
|
||||
private Vector plannedPosition;
|
||||
|
||||
public void setPlannedPosition(Vector plannedPosition) {
|
||||
this.plannedPosition = plannedPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanResult get() {
|
||||
if(plannedPosition == null)
|
||||
|
@ -22,6 +22,7 @@ package de.steamwar.fightsystem.commands;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.ai.AIManager;
|
||||
import de.steamwar.fightsystem.fight.*;
|
||||
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
@ -38,9 +39,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GUI {
|
||||
private GUI(){}
|
||||
@ -53,7 +53,7 @@ public class GUI {
|
||||
String name = team.getLeader() != null ? team.getLeader().getEntity().getName() : team.getName();
|
||||
inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + name), click -> {
|
||||
p.closeInventory();
|
||||
new JoinRequest(p, team);
|
||||
JoinRequest.forPlayer(p, team);
|
||||
});
|
||||
}
|
||||
|
||||
@ -89,11 +89,29 @@ public class GUI {
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public static void chooseJoinRequests(Player p){
|
||||
List<SWListInv.SWListEntry<Player>> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p));
|
||||
SWListInv<Player> inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, Player player) -> {
|
||||
public static void addAI(Player p) {
|
||||
SWListInv<AIManager> inv = new SWListInv<>(
|
||||
p, msg.parse("ADD_AI_TITLE", p),
|
||||
AIManager.availableAIs().stream().map(manager -> new SWListInv.SWListEntry<>(new SWItem(manager.getIcon(), manager.name()), manager)).collect(Collectors.toList()),
|
||||
(click, manager) -> {
|
||||
FightTeam team = Fight.getPlayerTeam(p);
|
||||
if(FightState.PreLeaderSetup.contains(FightState.getFightState())) {
|
||||
manager.join(Fight.getOpposite(team));
|
||||
} else {
|
||||
JoinRequest.forAI(manager, team);
|
||||
}
|
||||
p.closeInventory();
|
||||
RequestsCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline);
|
||||
}
|
||||
);
|
||||
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public static void chooseJoinRequests(Player p){
|
||||
List<SWListInv.SWListEntry<JoinRequest>> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p));
|
||||
SWListInv<JoinRequest> inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, JoinRequest request) -> {
|
||||
p.closeInventory();
|
||||
RequestsCommand.onJoinRequest(p, request, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline);
|
||||
});
|
||||
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
||||
inv.open();
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.ai.AI;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import org.bukkit.command.Command;
|
||||
@ -35,6 +36,7 @@ public class KitCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
AI.printPos();
|
||||
if(!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -59,13 +59,7 @@ public class RequestsCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void onJoinRequest(Player player, Player target, BiConsumer<JoinRequest, FightTeam> handleJoinRequest) {
|
||||
JoinRequest request = JoinRequest.get(target);
|
||||
if(request == null) {
|
||||
FightSystem.getMessage().send("NO_JOIN_REQUEST", player);
|
||||
return;
|
||||
}
|
||||
|
||||
public static void onJoinRequest(Player player, JoinRequest request, BiConsumer<JoinRequest, FightTeam> handleJoinRequest) {
|
||||
FightTeam team = Fight.getPlayerTeam(player);
|
||||
if(!request.required(team)) {
|
||||
FightSystem.getMessage().send("NO_CONFIRMATION", player);
|
||||
|
@ -34,6 +34,7 @@ import de.steamwar.fightsystem.utils.WorldeditWrapper;
|
||||
import de.steamwar.sql.SchematicData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
@ -52,6 +53,7 @@ public class FightSchematic extends StateDependent {
|
||||
private final Region region;
|
||||
private final boolean rotate;
|
||||
|
||||
@Getter
|
||||
private Clipboard clipboard = null;
|
||||
private int schematic = 0;
|
||||
|
||||
@ -137,6 +139,7 @@ public class FightSchematic extends StateDependent {
|
||||
private void paste(){
|
||||
FreezeWorld freezer = new FreezeWorld();
|
||||
|
||||
team.teleportToSpawn();
|
||||
Vector dims = WorldeditWrapper.impl.getDimensions(clipboard);
|
||||
WorldeditWrapper.impl.pasteClipboard(
|
||||
clipboard,
|
||||
@ -149,9 +152,9 @@ public class FightSchematic extends StateDependent {
|
||||
new AffineTransform().rotateY(rotate ? 180 : 0)
|
||||
);
|
||||
FightSystem.getHullHider().initialize(team);
|
||||
team.getPlayers().forEach(fightPlayer -> fightPlayer.ifAI(ai -> ai.schematic(clipboard)));
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3);
|
||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.ai.AIManager;
|
||||
import de.steamwar.fightsystem.commands.GUI;
|
||||
import de.steamwar.fightsystem.countdown.Countdown;
|
||||
import de.steamwar.fightsystem.events.TeamLeaveEvent;
|
||||
@ -71,9 +72,11 @@ public class FightTeam {
|
||||
static {
|
||||
setKitButton(notReadyKit, true);
|
||||
|
||||
if(!ArenaMode.RankedEvent.contains(Config.mode)){
|
||||
if(ArenaMode.VariableTeams.contains(Config.mode)){
|
||||
notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).build(), GUI::chooseJoinRequests);
|
||||
notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).build(), GUI::chooseRemove);
|
||||
if(!AIManager.availableAIs().isEmpty())
|
||||
notReadyKit.setItem(6, "ADD_AI", new ItemBuilder(Material.REDSTONE).build(), GUI::addAI);
|
||||
}
|
||||
|
||||
if(Config.test())
|
||||
@ -452,6 +455,10 @@ public class FightTeam {
|
||||
return schematic.getId();
|
||||
}
|
||||
|
||||
public Clipboard getClipboard() {
|
||||
return schematic.getClipboard();
|
||||
}
|
||||
|
||||
public double getCurrentHearts() {
|
||||
return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getEntity().getHealth()).sum();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.fightsystem.fight;
|
||||
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.ai.AIManager;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
@ -28,44 +29,66 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JoinRequest {
|
||||
|
||||
private static final Map<Player, JoinRequest> activeRequests = new HashMap<>();
|
||||
private static final Map<Player, JoinRequest> playerRequests = new HashMap<>();
|
||||
private static final List<JoinRequest> activeRequests = new ArrayList<>();
|
||||
public static JoinRequest get(Player player) {
|
||||
return playerRequests.get(player);
|
||||
}
|
||||
|
||||
public static List<SWListInv.SWListEntry<Player>> openRequests(Player p, FightTeam team) {
|
||||
return activeRequests.values().stream().filter(
|
||||
public static List<SWListInv.SWListEntry<JoinRequest>> openRequests(Player p, FightTeam team) {
|
||||
return activeRequests.stream().filter(
|
||||
request -> request.waitOnApproval.contains(team)
|
||||
).map(request -> {
|
||||
SWItem item = SWItem.getPlayerSkull(request.player);
|
||||
item.setLore(Arrays.asList(
|
||||
AtomicReference<SWItem> item = new AtomicReference<>();
|
||||
request.enquirer.ifPlayer(player -> item.set(SWItem.getPlayerSkull(player)));
|
||||
request.enquirer.ifAI(manager -> item.set(new SWItem(manager.getIcon(), manager.name())));
|
||||
item.get().setLore(Arrays.asList(
|
||||
FightSystem.getMessage().parse("REQUESTS_LEFT_CLICK", p),
|
||||
FightSystem.getMessage().parse("REQUESTS_RIGHT_CLICK", p)
|
||||
));
|
||||
return new SWListInv.SWListEntry<>(item, request.player);
|
||||
return new SWListInv.SWListEntry<>(item.get(), request);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void clearRequests() {
|
||||
playerRequests.clear();
|
||||
activeRequests.clear();
|
||||
}
|
||||
|
||||
public static JoinRequest get(Player player) {
|
||||
return activeRequests.get(player);
|
||||
public static void forPlayer(Player player, FightTeam team) {
|
||||
new JoinRequest(new Enquirer() {
|
||||
@Override public String name() { return player.getName(); }
|
||||
@Override public void ifPlayer(Consumer<Player> function) { function.accept(player); }
|
||||
@Override public void ifAI(Consumer<AIManager> function) {}
|
||||
}, team, FightState.ingame() ? Fight.teams() : Collections.singleton(team));
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
public static void forAI(AIManager manager, FightTeam team) {
|
||||
new JoinRequest(new Enquirer() {
|
||||
@Override public String name() { return manager.name(); }
|
||||
@Override public void ifPlayer(Consumer<Player> function) {}
|
||||
@Override public void ifAI(Consumer<AIManager> function) { function.accept(manager); }
|
||||
}, team, Collections.singleton(Fight.getOpposite(team)));
|
||||
}
|
||||
|
||||
private final Enquirer enquirer;
|
||||
private final FightTeam team;
|
||||
private final Set<FightTeam> waitOnApproval;
|
||||
|
||||
public JoinRequest(Player player, FightTeam team) {
|
||||
this.player = player;
|
||||
private JoinRequest(Enquirer enquirer, FightTeam team, Collection<FightTeam> waitOnApproval) {
|
||||
this.enquirer = enquirer;
|
||||
this.team = team;
|
||||
this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team));
|
||||
this.waitOnApproval = new HashSet<>(waitOnApproval);
|
||||
Set<FightTeam> alreadyAccepted = new HashSet<>();
|
||||
|
||||
activeRequests.put(player, this);
|
||||
enquirer.ifPlayer(player -> playerRequests.put(player, this));
|
||||
activeRequests.add(this);
|
||||
for(FightTeam t : waitOnApproval) {
|
||||
FightPlayer leader = t.getLeader();
|
||||
if(leader == null)
|
||||
@ -74,14 +97,14 @@ public class JoinRequest {
|
||||
if(leader.getEntity() == null)
|
||||
continue;
|
||||
|
||||
leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()));
|
||||
leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), enquirer.name(), team.getColoredName()));
|
||||
leader.ifAI(ai -> {
|
||||
if(ai.acceptJoinRequest(player, team))
|
||||
if(ai.acceptJoinRequest(enquirer, team))
|
||||
alreadyAccepted.add(t);
|
||||
});
|
||||
}
|
||||
|
||||
FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR);
|
||||
enquirer.ifPlayer(player -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR));
|
||||
alreadyAccepted.forEach(this::accept);
|
||||
}
|
||||
|
||||
@ -93,18 +116,26 @@ public class JoinRequest {
|
||||
waitOnApproval.remove(acceptor);
|
||||
|
||||
if(waitOnApproval.isEmpty()) {
|
||||
team.addMember(player);
|
||||
activeRequests.remove(player);
|
||||
enquirer.ifPlayer(team::addMember);
|
||||
enquirer.ifAI(manager -> manager.join(team));
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public void decline(FightTeam declinor) {
|
||||
FightSystem.getMessage().sendPrefixless("REQUEST_YOUR_DECLINED", player, ChatMessageType.ACTION_BAR);
|
||||
waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", player.getName()));
|
||||
silentDecline();
|
||||
enquirer.ifPlayer(player -> FightSystem.getMessage().sendPrefixless("REQUEST_YOUR_DECLINED", player, ChatMessageType.ACTION_BAR));
|
||||
waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", enquirer.name()));
|
||||
close();
|
||||
}
|
||||
|
||||
public void silentDecline() {
|
||||
activeRequests.remove(player);
|
||||
public void close() {
|
||||
enquirer.ifPlayer(playerRequests::remove);
|
||||
activeRequests.remove(this);
|
||||
}
|
||||
|
||||
public interface Enquirer {
|
||||
String name();
|
||||
void ifPlayer(Consumer<Player> function);
|
||||
void ifAI(Consumer<AIManager> function);
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,6 @@ public class JoinRequestListener implements Listener {
|
||||
public void onLeave(PlayerQuitEvent event) {
|
||||
JoinRequest request = JoinRequest.get(event.getPlayer());
|
||||
if(request != null)
|
||||
request.silentDecline();
|
||||
request.close();
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren