diff --git a/BauSystem/BauSystem_15/build.gradle.kts b/BauSystem/BauSystem_15/build.gradle.kts index 46aaa27a..2cbe19e6 100644 --- a/BauSystem/BauSystem_15/build.gradle.kts +++ b/BauSystem/BauSystem_15/build.gradle.kts @@ -27,8 +27,8 @@ java { } dependencies { - compileOnly(project(":BauSystem:BauSystem_Main")) - compileOnly(project(":SpigotCore")) + compileOnly(project(":BauSystem:BauSystem_Main", "default")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.nms15) compileOnly(libs.worldedit15) diff --git a/BauSystem/BauSystem_18/build.gradle.kts b/BauSystem/BauSystem_18/build.gradle.kts index 08a1a218..d3ad4f8e 100644 --- a/BauSystem/BauSystem_18/build.gradle.kts +++ b/BauSystem/BauSystem_18/build.gradle.kts @@ -27,8 +27,8 @@ java { } dependencies { - compileOnly(project(":BauSystem:BauSystem_Main")) - compileOnly(project(":SpigotCore")) + compileOnly(project(":BauSystem:BauSystem_Main", "default")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) compileOnly(libs.nms18) diff --git a/BauSystem/BauSystem_19/build.gradle.kts b/BauSystem/BauSystem_19/build.gradle.kts index f67105e7..b72cbf08 100644 --- a/BauSystem/BauSystem_19/build.gradle.kts +++ b/BauSystem/BauSystem_19/build.gradle.kts @@ -27,8 +27,8 @@ java { } dependencies { - compileOnly(project(":BauSystem:BauSystem_Main")) - compileOnly(project(":SpigotCore")) + compileOnly(project(":BauSystem:BauSystem_Main", "default")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) compileOnly(libs.paperapi) diff --git a/BauSystem/BauSystem_20/build.gradle.kts b/BauSystem/BauSystem_20/build.gradle.kts index 5ec08958..b1756244 100644 --- a/BauSystem/BauSystem_20/build.gradle.kts +++ b/BauSystem/BauSystem_20/build.gradle.kts @@ -27,8 +27,8 @@ java { } dependencies { - compileOnly(project(":BauSystem:BauSystem_Main")) - compileOnly(project(":SpigotCore")) + compileOnly(project(":BauSystem:BauSystem_Main", "default")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) diff --git a/BauSystem/BauSystem_Main/build.gradle.kts b/BauSystem/BauSystem_Main/build.gradle.kts index 5138608b..63d6f026 100644 --- a/BauSystem/BauSystem_Main/build.gradle.kts +++ b/BauSystem/BauSystem_Main/build.gradle.kts @@ -33,7 +33,7 @@ java { dependencies { compileOnly(libs.classindex) annotationProcessor(libs.classindex) - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) compileOnly(libs.axiom) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 67a16a47..c9116dce 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -271,6 +271,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Change your simulator wand SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Deletes the simulator SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Starts the simulator SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Copy the simulator +SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-rename§8] §8[§7name§8] §8-§7 Rename the simulator SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator SIMULATOR_NO_SIM_IN_HAND=§cNo simulator item selected SIMULATOR_GUI_SELECT_SIM=Simulator selection @@ -307,6 +308,7 @@ SIMULATOR_POSITION_Z=§7z-Position SIMULATOR_BACK=§eBack SIMULATOR_GUI_TOTAL_TNT=§7Total TNT§8: §e{0} SIMULATOR_DELETED=§cSimulator deleted +SIMULATOR_RENAMED=§cSimulator renamed from {0} to {1} ## GUI SIMULATOR_POSITION_EDIT=§eEdit position SIMULATOR_POSITION_ADD=§eSet position diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 4013f3b2..45e60f84 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -254,6 +254,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Wechsel zu einem anderen S SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Löscht den Simulator SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Startet die Simulation SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Kopiert einen Simulator +SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-rename§8] §8[§7name§8] §8-§7 Benennt einen Simulator um SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator SIMULATOR_NO_SIM_IN_HAND=§cKein Simulator Item gewählt SIMULATOR_GUI_SELECT_SIM=Simulator wählen @@ -290,6 +291,7 @@ SIMULATOR_POSITION_Z=§7z-Position SIMULATOR_BACK=§eZurück SIMULATOR_GUI_TOTAL_TNT=§7Gesamt TNT§8: §e{0} SIMULATOR_DELETED=§cSimulator gelöscht +SIMULATOR_RENAMED=§cSimulator von {0} zu {1} umbenannt ## GUI SIMULATOR_POSITION_EDIT=§ePosition bearbeiten SIMULATOR_POSITION_ADD=§ePosition setzen diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 0b1b160c..0d5fa43c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.configplayer.ConfigConverter; import de.steamwar.bausystem.features.gui.BauGUI; import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin; import de.steamwar.bausystem.features.script.lua.libs.LuaLib; +import de.steamwar.bausystem.features.slaves.laufbau.BoundingBoxLoader; import de.steamwar.bausystem.features.slaves.panzern.Panzern; import de.steamwar.bausystem.features.slaves.panzern.PanzernAlgorithm; import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; @@ -184,6 +185,9 @@ public class BauSystem extends JavaPlugin { if (any instanceof ConfigConverter) { Config.addConfigConverter((ConfigConverter) any); } + if (any instanceof BoundingBoxLoader) { + ((BoundingBoxLoader) any).load(); + } }); instances.forEach((clazz, o) -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index d8489a0f..0ce38b9a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -93,6 +93,7 @@ public class Loader implements Listener { element.execute(delay -> waitTime = delay); if (waitTime > 0) { if (element instanceof LoaderTNT) currentElement--; + waitTime--; return; } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index 06af3e68..de0c4b74 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; @@ -63,15 +62,7 @@ public class SimulatorCommand extends SWCommand { } @Register(value = "copy", description = "SIMULATOR_COPY_HELP") - public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) { - if (SimulatorStorage.getSimulator(name) != null) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); - return; - } - if (!name.matches("[a-zA-Z_0-9-]+")) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); - return; - } + public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, @Validator("simulatorName") String name) { if (!SimulatorStorage.copy(simulator, name)) { BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p); } @@ -88,6 +79,17 @@ public class SimulatorCommand extends SWCommand { SimulatorExecutor.run(simulator); } + @Register(value = "rename", description = "SIMULATOR_RENAME_HELP") + public void rename(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, @Validator("simulatorName") String name) { + String oldName = simulator.getName(); + if (SimulatorStorage.copy(simulator, name)) { + SimulatorStorage.delete(simulator); + BauSystem.MESSAGE.send("SIMULATOR_RENAMED", p, oldName, name); + } else { + BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p); + } + } + @ClassMapper(value = Simulator.class, local = true) public TypeMapper allSimulators() { return new TypeMapper<>() { @@ -102,4 +104,19 @@ public class SimulatorCommand extends SWCommand { } }; } + + @Validator(value = "simulatorName", local = true) + public TypeValidator simulatorName() { + return (commandSender, name, messageSender) -> { + if (SimulatorStorage.getSimulator(name) != null) { + messageSender.send("SIMULATOR_NAME_ALREADY_EXISTS"); + return false; + } + if (!name.matches("[a-zA-Z_0-9-]+")) { + messageSender.send("SIMULATOR_NAME_INVALID"); + return false; + } + return true; + }; + } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java index b3fbcba8..434e112d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -44,6 +44,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; @Linked @MinVersion(19) @@ -130,7 +131,7 @@ public class SimulatorStorage implements Enable { } public static void openSimulatorSelector(Player player) { - SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6 * 9, new ArrayList<>(simulatorMap.values())) { + SimulatorPageGui simulatorPageGui = new SimulatorPageGui(player, null, 6 * 9, simulatorMap.values().stream().sorted(Comparator.comparing(Simulator::getName)).collect(Collectors.toList())) { @Override public String baseTitle() { return "Simulators"; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java index c2893964..94eb6549 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox; import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; import de.steamwar.bausystem.features.tracer.TNTPoint; +import de.steamwar.bausystem.features.tracer.Trace; import de.steamwar.bausystem.features.tracer.TraceManager; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.utils.FlatteningWrapper; @@ -34,7 +35,6 @@ import org.bukkit.util.Vector; import java.util.*; import java.util.function.BiPredicate; -import java.util.stream.Collectors; public class ProcessingTracesState implements LaufbauState { @@ -45,8 +45,9 @@ public class ProcessingTracesState implements LaufbauState { private final List elements; private final int factor; - private final List TNTPoints; - private final int totalTntRecords; + private final List Traces; + private final List TNTPoints = new ArrayList<>(); + private final int totalTraces; private final Set affectedBlocks = new HashSet<>(); private final Map> cuboidsPerChunk = new HashMap<>(); @@ -58,18 +59,13 @@ public class ProcessingTracesState implements LaufbauState { this.elements = elements; this.factor = factor; - // TODO: Optimize only retrieving traces inside of the affected regions! - TNTPoints = TraceManager.instance.getAll() - .stream() - .flatMap(trace -> trace.getHistories().stream()) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - totalTntRecords = TNTPoints.size(); + Traces = new ArrayList<>(TraceManager.instance.getAll()); + totalTraces = Traces.size(); } @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTntRecords - TNTPoints.size(), totalTntRecords, eta(p, start, totalTntRecords - TNTPoints.size(), totalTntRecords)); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTraces - Traces.size(), totalTraces, eta(p, start, totalTraces - Traces.size(), totalTraces)); } private boolean inRegion(Vector location, int expansion) { @@ -78,11 +74,17 @@ public class ProcessingTracesState implements LaufbauState { @Override public boolean hasNext() { - return !TNTPoints.isEmpty(); + return !Traces.isEmpty() || !TNTPoints.isEmpty(); } @Override public void next() { + if (TNTPoints.isEmpty()) { + Trace trace = Traces.remove(0); + trace.getHistories().stream().flatMap(Collection::stream).forEach(TNTPoints::add); + return; + } + TNTPoint current = TNTPoints.remove(0); if (FlatteningWrapper.impl.inWater(world, current.getLocation().toVector())) return; if (!(inRegion(current.getLocation().toVector(), 1) || (current.getPrevious().isPresent() && inRegion(current.getPrevious().get().getLocation().toVector(), 1)))) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index 31308830..c8a6d2de 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -39,12 +39,12 @@ public class SpeedCommand extends SWCommand { @Register public void speedCommand(Player p, float speed) { - speed = speed / 10F; - if (speed < -1F) { + if (speed < -10F) { BauSystem.MESSAGE.send("SPEED_TOO_SMALL", p, speed); - } else if (speed > 1F) { + } else if (speed > 10F) { BauSystem.MESSAGE.send("SPEED_TOO_HIGH", p, speed); } else { + speed = speed / 10F; p.setFlySpeed(speed); p.setWalkSpeed(Math.min(speed + 0.1F, 1F)); BauSystem.MESSAGE.send("SPEED_CURRENT", p, (p.getFlySpeed() * 10F)); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java index b0479f90..ef6b912b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java @@ -24,6 +24,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.Point; @@ -34,9 +35,7 @@ import lombok.NonNull; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.function.BiConsumer; import java.util.function.BiPredicate; @@ -106,51 +105,28 @@ public class PasteBuilder { public PasteBuilder color(Color color) { if (color == Color.PINK) return this; - BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); - BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); - BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock(); - BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(); - BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(); - BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(); - BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(); - BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(); - - BaseBlock wool = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock(); - BaseBlock clay = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock(); - BaseBlock glazed = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_glazed_terracotta")).getDefaultState().toBaseBlock(); - BaseBlock glass = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock(); - BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock(); - BaseBlock carpet = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock(); - BaseBlock concrete = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete")).getDefaultState().toBaseBlock(); - BaseBlock concretePowder = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete_powder")).getDefaultState().toBaseBlock(); - + Map blockCache = new HashMap<>(); return map((clipboard, blockVector3) -> { BaseBlock block = clipboard.getFullBlock(blockVector3); - if (block.equals(WOOL)) { - clipboard.setBlock(blockVector3, wool); - } else if (block.equals(CLAY)) { - clipboard.setBlock(blockVector3, clay); - } else if (block.equals(GLAZED)) { - clipboard.setBlock(blockVector3, glazed); - } else if (block.equals(GLASS)) { - clipboard.setBlock(blockVector3, glass); - } else if (block.equals(GLASS_PANE)) { - clipboard.setBlock(blockVector3, glassPane); - } else if (block.equals(CARPET)) { - clipboard.setBlock(blockVector3, carpet); - } else if (block.equals(CONCRETE)) { - clipboard.setBlock(blockVector3, concrete); - } else if (block.equals(CONCRETE_POWDER)) { - clipboard.setBlock(blockVector3, concretePowder); + if (block.getBlockType().getId().startsWith("minecraft:pink_")) { + BaseBlock baseBlock = blockCache.computeIfAbsent(block.getBlockType().getId(), s -> { + String replaced = s.replace("minecraft:pink_", "minecraft:" + color.name().toLowerCase() + "_"); + BlockType blockType = BlockTypes.get(replaced); + if (blockType == null) return null; + return blockType.getDefaultState().toBaseBlock(); + }); + if (baseBlock == null) return; + clipboard.setBlock(blockVector3, baseBlock); } }); } + /** + * Can only be used before {@link #color(Color)}. + */ public PasteBuilder onlyColors(boolean onlyColors) { if (!onlyColors) return this; - return only((baseBlock, s) -> { - return s.endsWith("_wool") || s.endsWith("_terracotta") || s.endsWith("_glazed_terracotta") || s.endsWith("_stained_glass") || s.endsWith("_stained_glass_pane") || s.endsWith("_carpet") || s.endsWith("_concrete") || s.endsWith("_concrete_powder"); - }); + return only((baseBlock, s) -> s.startsWith("minecraft:pink_")); } public PasteBuilder removeTNT(boolean removeTNT) { diff --git a/CommonCore/SQL/src/de/steamwar/sql/Punishment.java b/CommonCore/SQL/src/de/steamwar/sql/Punishment.java index 73278452..4e0c1665 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Punishment.java +++ b/CommonCore/SQL/src/de/steamwar/sql/Punishment.java @@ -121,11 +121,11 @@ public class Punishment { public enum PunishmentType { Ban(false, "BAN_TEAM", "BAN_PERMA", "BAN_UNTIL", "UNBAN_ERROR", "UNBAN"), Mute( false, "MUTE_TEAM", "MUTE_PERMA", "MUTE_UNTIL", "UNMUTE_ERROR", "UNMUTE"), - NoSchemReceiving(false, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"), - NoSchemSharing(false, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"), - NoSchemSubmitting(true, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"), + NoSchemReceiving(true, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"), + NoSchemSharing(true, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"), + NoSchemSubmitting(false, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"), NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER"), - NoFightServer(false, "NOFIGHTSERVER_TEAM", "NOFIGHTSERVER_PERMA", "NOFIGHTSERVER_UNTIL", "UNNOFIGHTSERVER_ERROR", "UNNOFIGHTSERVER"), + NoFightServer(true, "NOFIGHTSERVER_TEAM", "NOFIGHTSERVER_PERMA", "NOFIGHTSERVER_UNTIL", "UNNOFIGHTSERVER_ERROR", "UNNOFIGHTSERVER"), NoTeamServer(true, "NOTEAMSERVER_TEAM", "NOTEAMSERVER_PERMA", "NOTEAMSERVER_UNTIL", "UNNOTEAMSERVER_ERROR", "UNNOTEAMSERVER"), Note(false, "NOTE_TEAM", null, null, null, null, true); diff --git a/FightSystem/FightSystem_10/build.gradle.kts b/FightSystem/FightSystem_10/build.gradle.kts index 882668ff..d34e28f4 100644 --- a/FightSystem/FightSystem_10/build.gradle.kts +++ b/FightSystem/FightSystem_10/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) compileOnly(libs.nms10) } diff --git a/FightSystem/FightSystem_12/build.gradle.kts b/FightSystem/FightSystem_12/build.gradle.kts index c172455a..8ec0f834 100644 --- a/FightSystem/FightSystem_12/build.gradle.kts +++ b/FightSystem/FightSystem_12/build.gradle.kts @@ -22,9 +22,9 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) - compileOnly(project(":FightSystem:FightSystem_8")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) + compileOnly(project(":FightSystem:FightSystem_8", "default")) compileOnly(libs.nms12) compileOnly(libs.worldedit12) diff --git a/FightSystem/FightSystem_14/build.gradle.kts b/FightSystem/FightSystem_14/build.gradle.kts index 2c8e52d5..4fc15121 100644 --- a/FightSystem/FightSystem_14/build.gradle.kts +++ b/FightSystem/FightSystem_14/build.gradle.kts @@ -22,10 +22,10 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) - compileOnly(project(":FightSystem:FightSystem_8")) - compileOnly(project(":FightSystem:FightSystem_9")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) + compileOnly(project(":FightSystem:FightSystem_8", "default")) + compileOnly(project(":FightSystem:FightSystem_9", "default")) compileOnly(libs.nms14) compileOnly(libs.worldedit15) diff --git a/FightSystem/FightSystem_15/build.gradle.kts b/FightSystem/FightSystem_15/build.gradle.kts index c1556233..4b16dc73 100644 --- a/FightSystem/FightSystem_15/build.gradle.kts +++ b/FightSystem/FightSystem_15/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) compileOnly(libs.nms15) compileOnly(libs.worldedit15) diff --git a/FightSystem/FightSystem_18/build.gradle.kts b/FightSystem/FightSystem_18/build.gradle.kts index c6a938e0..fa12144d 100644 --- a/FightSystem/FightSystem_18/build.gradle.kts +++ b/FightSystem/FightSystem_18/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) compileOnly(libs.spigotapi) diff --git a/FightSystem/FightSystem_19/build.gradle.kts b/FightSystem/FightSystem_19/build.gradle.kts index 0dc7a095..6ccb56c9 100644 --- a/FightSystem/FightSystem_19/build.gradle.kts +++ b/FightSystem/FightSystem_19/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":FightSystem:FightSystem_Core")) - compileOnly(project(":FightSystem:FightSystem_18")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) + compileOnly(project(":FightSystem:FightSystem_18", "default")) compileOnly(libs.spigotapi) diff --git a/FightSystem/FightSystem_20/build.gradle.kts b/FightSystem/FightSystem_20/build.gradle.kts index 99c4a656..13eb77cf 100644 --- a/FightSystem/FightSystem_20/build.gradle.kts +++ b/FightSystem/FightSystem_20/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":FightSystem:FightSystem_Core")) - compileOnly(project(":FightSystem:FightSystem_18")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) + compileOnly(project(":FightSystem:FightSystem_18", "default")) compileOnly(libs.spigotapi) diff --git a/FightSystem/FightSystem_8/build.gradle.kts b/FightSystem/FightSystem_8/build.gradle.kts index d98e4045..7fb2f827 100644 --- a/FightSystem/FightSystem_8/build.gradle.kts +++ b/FightSystem/FightSystem_8/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) compileOnly(libs.nms8) compileOnly(libs.worldedit12) diff --git a/FightSystem/FightSystem_9/build.gradle.kts b/FightSystem/FightSystem_9/build.gradle.kts index 21c34e22..5edfa1e3 100644 --- a/FightSystem/FightSystem_9/build.gradle.kts +++ b/FightSystem/FightSystem_9/build.gradle.kts @@ -22,9 +22,9 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":FightSystem:FightSystem_Core")) - compileOnly(project(":FightSystem:FightSystem_8")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":FightSystem:FightSystem_Core", "default")) + compileOnly(project(":FightSystem:FightSystem_8", "default")) compileOnly(libs.nms9) } diff --git a/FightSystem/FightSystem_Core/build.gradle.kts b/FightSystem/FightSystem_Core/build.gradle.kts index 8b1d5ece..2f044447 100644 --- a/FightSystem/FightSystem_Core/build.gradle.kts +++ b/FightSystem/FightSystem_Core/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 3c220d64..9f80ab7e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -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 diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 06b07d18..6723bcfb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -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 diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java index 6f5cb005..0b681fc2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java @@ -19,32 +19,38 @@ 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.record.GlobalRecorder; 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; import org.bukkit.Note; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Lectern; import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.FaceAttachable; import org.bukkit.block.data.Openable; import org.bukkit.block.data.Powerable; import org.bukkit.block.data.type.Comparator; import org.bukkit.block.data.type.NoteBlock; 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; @@ -55,10 +61,16 @@ import java.util.logging.Level; public abstract class AI { + public static final int MOVEMENT_DELAY = 4; + public static final double INTERACTION_RANGE = 5.0; + private static final Map 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(); }); @@ -68,7 +80,9 @@ public abstract class AI { return ais.get(uuid); } - private final FightTeam team; + @Getter + protected final FightTeam team; + @Getter private final LivingEntity entity; private final BukkitTask task; private final Queue queue = new ArrayDeque<>(); @@ -83,11 +97,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; } @@ -101,11 +119,7 @@ public abstract class AI { task.cancel(); } - public LivingEntity getEntity() { - return entity; - } - - protected void setReady() { + public void setReady() { if(FightState.getFightState() != FightState.POST_SCHEM_SETUP) return; @@ -115,12 +129,12 @@ public abstract class AI { team.setReady(true); } - protected void chat(String message) { + public void chat(String message) { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + "» " + message); Chat.broadcastChat("PARTICIPANT_CHAT", team.getColoredName(), entity.getName(), message); } - protected Vector getPosition() { + public Vector getPosition() { Location location = entity.getLocation(); Region extend = team.getExtendRegion(); if(Fight.getUnrotated() == team) @@ -137,26 +151,28 @@ public abstract class AI { ); } - protected Material getBlock(Vector pos) { + public Material getBlock(Vector pos) { queue.add(new Action(1)); - return translate(pos, true).getBlock().getType(); + return translate(pos).getBlock().getType(); } - protected boolean isPowered(Vector pos) { + public BlockData getBlockData(Vector pos) { queue.add(new Action(1)); - return translate(pos, true).getBlock().isBlockPowered(); + return translate(pos).getBlock().getBlockData(); } - protected void setTNT(Vector pos) { + public void setTNT(Vector pos) { queue.add(new Action(1) { @Override public void run() { if(FightState.getFightState() != FightState.RUNNING) return; - Location location = translate(pos, true); - if(interactionDistanceViolation(location)) + Location location = translate(pos); + if(interactionDistanceViolation(location)) { + chat("InteractionDistanceViolation: setTNT"); return; + } Block block = location.getBlock(); if(block.getType() == Material.AIR) @@ -165,24 +181,26 @@ public abstract class AI { }); } - protected void interact(Vector pos) { + public void interact(Vector pos) { queue.add(new Action(1) { @Override public void run() { - Location location = translate(pos, true); - if(interactionDistanceViolation(location)) + Location location = translate(pos); + if(interactionDistanceViolation(location)) { + chat("InteractionDistanceViolation: interact"); return; + } interact(location.getBlock()); } }); } - protected void interact(Vector pos, int n) { + public void interact(Vector pos, int n) { queue.add(new Action(1) { @Override public void run() { - Location location = translate(pos, true); + Location location = translate(pos); if (interactionDistanceViolation(location)) return; Block block = location.getBlock(); @@ -199,13 +217,18 @@ public abstract class AI { }); } - protected void move(Vector pos) { - queue.add(new Action(2) { + public void move(Vector pos) { + queue.add(new Action(MOVEMENT_DELAY) { @Override public void run() { Location location = entity.getLocation(); - Location target = translate(pos, false); - if(Math.abs(location.getX() - target.getX()) > 1 || Math.abs(location.getY() - target.getY()) > 1.2 || Math.abs(location.getZ() - target.getZ()) > 1) { + if(!entity.isOnGround() && location.getBlock().getType() != Material.LADDER) { + FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity falling"); + return; + } + + Location target = translate(pos); + if(Math.abs(location.getX() - target.getX()) > 1.0 || Math.abs(location.getY() - target.getY()) > 1.5 || Math.abs(location.getZ() - target.getZ()) > 1.0) { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + ": Overdistance movement " + location.toVector() + " " + target.toVector()); return; } @@ -213,13 +236,16 @@ public abstract class AI { if(!team.getFightPlayer(entity).canEntern() && !team.getExtendRegion().inRegion(target)) return; - entity.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND); + if(!entity.teleport(target, PlayerTeleportEvent.TeleportCause.PLUGIN)) + FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity not teleported: " + entity.isValid()); + + GlobalRecorder.getInstance().entityMoves(entity); } }); } private boolean interactionDistanceViolation(Location location) { - return location.distance(entity.getEyeLocation()) > 5; + return location.distance(entity.getEyeLocation()) > INTERACTION_RANGE; } private void interact(Block block) { @@ -249,23 +275,51 @@ public abstract class AI { powerable.setPowered(false); block.setBlockData(powerable); + updateButton(block); }, type.name().endsWith("STONE_BUTTON") ? 20 : 30); } powerable.setPowered(!isPowered); } block.setBlockData(data); + if(data instanceof Switch) { + updateButton(block); + } + } + + private void updateButton(Block block) { + Switch sw = (Switch) block.getBlockData(); + FaceAttachable.AttachedFace face = sw.getAttachedFace(); + if (face == FaceAttachable.AttachedFace.FLOOR) { + update(block.getRelative(BlockFace.DOWN)); + } else if (face == FaceAttachable.AttachedFace.CEILING) { + update(block.getRelative(BlockFace.UP)); + } else { + update(block.getRelative(sw.getFacing().getOppositeFace())); + } + } + + private void update(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER); + block.setBlockData(data); } private void run() { - if(queue.isEmpty()) - plan(); + if(queue.isEmpty()) { + try { + plan(); + } catch (Throwable t) { + stop(); + throw t; + } + } if(!queue.isEmpty() && --queue.peek().delay == 0) queue.poll().run(); } - private Location translate(Vector pos, boolean blockPos) { + public Location translate(Vector pos) { Region extend = team.getExtendRegion(); if(Fight.getUnrotated() == team) return new Location( @@ -277,9 +331,9 @@ public abstract class AI { else return new Location( Config.world, - extend.getMaxX() - pos.getX() - (blockPos ? 1 : 0), + extend.getMaxX() - pos.getX(), pos.getY() + team.getSchemRegion().getMinY(), - extend.getMaxZ() - pos.getZ() - (blockPos ? 1 : 0) + extend.getMaxZ() - pos.getZ() ); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java new file mode 100644 index 00000000..2cb13f65 --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java @@ -0,0 +1,57 @@ +/* + * 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 . + */ + +package de.steamwar.fightsystem.ai; + +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +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 AIs = Arrays.asList( + new AIManager(DummyAI.class, Material.STONE, () -> ArenaMode.Test.contains(Config.mode)) + ); + + public static List availableAIs() { + return AIs.stream().filter(manager -> manager.available.getAsBoolean()).collect(Collectors.toList()); + } + + private final Class 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); + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java similarity index 63% rename from FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java rename to FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java index 2a89353c..90fcd3d0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java @@ -19,42 +19,42 @@ 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; -import org.bukkit.util.Vector; import java.util.List; import java.util.Random; -public class LixfelAI extends AI { +public class DummyAI extends AI { - private final Random random = new Random(); - private LixfelPathplanner pathplanner; + private static final Random random = new Random(); - public LixfelAI(FightTeam team, String user) { - super(team, SteamwarUser.get(user)); + public DummyAI(FightTeam team) { + super(team, SteamwarUser.get("public")); + + FightStatistics.unrank(); + getEntity().setInvulnerable(true); } - @Override public SchematicNode chooseSchematic() { List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); - SchematicNode schem = publics.get(new Random().nextInt(publics.size())); - pathplanner = new LixfelPathplanner(schem); - return schem; + return publics.get(random.nextInt(publics.size())); + } + + @Override + public void schematic(Clipboard clipboard) { + //does nothing } @Override protected void plan() { - setReady(); - Vector destination = pathplanner.getWalkable().get(random.nextInt(pathplanner.getWalkable().size())); - List path = pathplanner.plan(getPosition(), destination); - if(!path.isEmpty()) - chat("Path size: " + path.size()); - for(Vector p : path) { - move(p); - } + if(FightState.getFightState() == FightState.POST_SCHEM_SETUP) + setReady(); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java deleted file mode 100644 index b2e593e8..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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 . - */ - -package de.steamwar.fightsystem.ai; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.block.BlockType; -import de.steamwar.fightsystem.Config; -import de.steamwar.sql.SchematicData; -import de.steamwar.sql.SchematicNode; -import org.bukkit.util.Vector; - -import java.io.IOException; -import java.util.*; - -public class LixfelPathplanner { - - private static BlockType getBlockType(Clipboard clipboard, BlockVector3 vector) { - return clipboard.getBlock(vector).getBlockType(); - } - - private static boolean nonsolid(Clipboard clipboard, BlockVector3 vector) { - return !getBlockType(clipboard, vector).getMaterial().isSolid(); - } - - private static Vector toBukkit(BlockVector3 vector) { - return new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5); - } - - private final List walkable = new ArrayList<>(); - private final Map neighbours = new HashMap<>(); - - public LixfelPathplanner(SchematicNode schem) { - try { - fillWalkable(new SchematicData(schem).load()); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - public List getWalkable() { - return walkable; - } - - private void fillWalkable(Clipboard clipboard) { - BlockVector3 min = clipboard.getRegion().getMinimumPoint().subtract(Config.PreperationArea, 0, Config.PreperationArea); //TODO assumes nonextended Schematic with maximal size - Region region = clipboard.getRegion(); - clipboard.getRegion().forEach(vector -> { - BlockVector3 below = vector.subtract(0, 1, 0); - if(!region.contains(below)) - return; - - BlockType belowMaterial = getBlockType(clipboard, below); - BlockVector3 above = vector.add(0, 1, 0); - if(nonsolid(clipboard, vector)) { - if( - (belowMaterial.getMaterial().isSolid() || belowMaterial.getId().equals("minecraft:ladder")) && - (!region.contains(above) || nonsolid(clipboard, above)) - ) - walkable.add(toBukkit(vector.subtract(min))); - } else { - if(!region.contains(above)) - walkable.add(toBukkit(above.subtract(min))); - } - }); - - for(Vector vector : walkable) { - neighbours.put(vector, walkable.stream().filter(neighbour -> neighbouring(neighbour, vector)).filter(neighbour -> neighbour != vector).toArray(Vector[]::new)); - } - } - - public List planToAnywhere(Vector start, Vector destination) { - Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null); - - if(intermediate == null) - return Collections.emptyList(); - - List plan = plan(start, intermediate); - plan.add(destination); - - return plan; - } - - public List plan(Vector start, Vector destination) { - if(neighbouring(start, destination)) - return Collections.singletonList(destination); - - Map approach = new HashMap<>(); - Set checking = Collections.singleton(destination); - - while(!checking.isEmpty()) { - Set toCheck = new HashSet<>(); - for(Vector current : checking) { - Vector firstStep = Arrays.stream(neighbours.get(current)) - .filter(vector -> !approach.containsKey(vector)) - .filter(next -> { - approach.put(next, current); - toCheck.add(next); - return neighbouring(next, start); - }) - .findAny().orElse(null); - - if(firstStep != null) { - List path = new ArrayList<>(); - path.add(firstStep); - - while(path.get(path.size()-1) != destination) { - path.add(approach.get(path.get(path.size()-1))); - } - - return path; - } - } - checking = toCheck; - } - - return Collections.emptyList(); - } - - private boolean neighbouring(Vector a, Vector b) { - return Math.abs(a.getX() - b.getX()) <= 1 && Math.abs(a.getY() - b.getY()) <= 1 && Math.abs(a.getZ() - b.getZ()) <= 1; - } -} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 0fba5388..4834bb0a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -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 addAI(Player p) { + SWListInv 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(); + } + ); + inv.setCallback(-999, (ClickType click) -> p.closeInventory()); + inv.open(); + } + public static void chooseJoinRequests(Player p){ - List> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p)); - SWListInv inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, Player player) -> { + List> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p)); + SWListInv inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, JoinRequest request) -> { p.closeInventory(); - RequestsCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); + RequestsCommand.onJoinRequest(p, request, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java index 36c2a1e3..131cc898 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java @@ -59,13 +59,7 @@ public class RequestsCommand implements CommandExecutor { return false; } - public static void onJoinRequest(Player player, Player target, BiConsumer 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 handleJoinRequest) { FightTeam team = Fight.getPlayerTeam(player); if(!request.required(team)) { FightSystem.getMessage().send("NO_CONFIRMATION", player); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 20c304d7..5e84ccdc 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -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,11 +152,11 @@ 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))); if(ArenaMode.Check.contains(Config.mode) && !team.isBlue()) - replaceSync(Material.TNT, Material.OBSIDIAN); + replaceSync(Material.TNT, Material.RED_WOOL); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } @Override diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 853646fc..334f3f83 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -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; @@ -70,9 +71,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(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java index a7756e4c..e4e349c7 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -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 activeRequests = new HashMap<>(); + private static final Map playerRequests = new HashMap<>(); + private static final List activeRequests = new ArrayList<>(); + public static JoinRequest get(Player player) { + return playerRequests.get(player); + } - public static List> openRequests(Player p, FightTeam team) { - return activeRequests.values().stream().filter( + public static List> 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 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 function) { function.accept(player); } + @Override public void ifAI(Consumer 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 function) {} + @Override public void ifAI(Consumer function) { function.accept(manager); } + }, team, Collections.singleton(Fight.getOpposite(team))); + } + + private final Enquirer enquirer; private final FightTeam team; private final Set waitOnApproval; - public JoinRequest(Player player, FightTeam team) { - this.player = player; + private JoinRequest(Enquirer enquirer, FightTeam team, Collection waitOnApproval) { + this.enquirer = enquirer; this.team = team; - this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team)); + this.waitOnApproval = new HashSet<>(waitOnApproval); Set 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 function); + void ifAI(Consumer function); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java index 1ed3fe8b..45121cf7 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java @@ -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(); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index f77c1904..889c3c1c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -43,6 +43,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -70,7 +71,7 @@ public class Recording implements Listener { return stack; } - public static boolean isNotSent(Player p){ + public static boolean isNotSent(LivingEntity p){ FightPlayer fp = Fight.getFightPlayer(p); return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } @@ -193,10 +194,10 @@ public class Recording implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent e) { - if(e.getEntityType() != EntityType.PLAYER) + if(!e.getEntityType().isAlive()) return; - Player p = (Player) e.getEntity(); + LivingEntity p = (LivingEntity) e.getEntity(); if(isNotSent(p)) return; @@ -208,10 +209,10 @@ public class Recording implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityCombust(EntityCombustEvent e) { - if(e.getEntityType() != EntityType.PLAYER) + if(!e.getEntityType().isAlive()) return; - Player p = (Player) e.getEntity(); + LivingEntity p = (LivingEntity) e.getEntity(); if(isNotSent(p)) return; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index d57a29b9..73821e6f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -204,7 +204,7 @@ public interface Recorder { write(0x0a, e.getEntityId(), start, offHand); } - default void damageAnimation(Player p) { + default void damageAnimation(LivingEntity p) { write(0x0b, p.getEntityId()); } diff --git a/LobbySystem/build.gradle.kts b/LobbySystem/build.gradle.kts index 3ad7a776..aa511a0c 100644 --- a/LobbySystem/build.gradle.kts +++ b/LobbySystem/build.gradle.kts @@ -27,7 +27,7 @@ java { } dependencies { - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties index 4530aaaf..2d1f31c0 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties @@ -4,8 +4,12 @@ DATE=........ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- # ServerTeamNPC's -NPC_CHAT_1 = §fHello, I''m {0} and I''m a(n) {1}§f. -NPC_CHAT_2 = §fWelcome on §eSteam§8War§f, have fun. +NPC_CHAT_0 = §fHello, I''m {0} and I''m a(n) {1}§f. +NPC_CHAT_1 = §fWelcome on §eSteam§8War§f, have fun. +NPC_CHAT_2 = §eSteam§8War§f was established in 2019. +NPC_CHAT_3 = &fBecome a part of our team by applying via our Discord server (https://steamwar.de/discord). +NPC_CHAT_4 = &fYou can develop your own buildserver features with our Lua script system. +NPC_CHAT_5 = &fThere are many secrets to discover in this lobby. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Lists all portals diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties index 969270ee..f1c02955 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties @@ -4,8 +4,12 @@ DATE=........ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- # ServerTeamNPC's -NPC_CHAT_1 = §fHallo, ich bin {0} und bin ein {1}§f. -NPC_CHAT_2 = §fWillkommen auf §eSteam§8War§f, viel Spaß dir. +NPC_CHAT_0 = §fHallo, ich bin {0} und bin ein {1}§f. +NPC_CHAT_1 = §fWillkommen auf §eSteam§8War§f, viel Spaß dir. +NPC_CHAT_2 = §eSteam§8War§f gibt es seit 2019. +NPC_CHAT_3 = &fBewerbe dich gerne für unser Team über unseren Discord-Server (https://steamwar.de/discord). +NPC_CHAT_4 = &fDu kannst mit unserm Lua Script-System deine eigenen Bau Features programmieren. +NPC_CHAT_5 = &fAuf dieser Lobby sind so einige secrets versteckt. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf diff --git a/LobbySystem/src/de/steamwar/lobby/portal/FightserverPortal.java b/LobbySystem/src/de/steamwar/lobby/portal/FightserverPortal.java index 08f03bb3..7d82cfdc 100644 --- a/LobbySystem/src/de/steamwar/lobby/portal/FightserverPortal.java +++ b/LobbySystem/src/de/steamwar/lobby/portal/FightserverPortal.java @@ -222,11 +222,13 @@ public class FightserverPortal implements PortalHandler, Comparable players = new HashSet<>(); private Random random = new Random(); - private List strings = new ArrayList<>(); - { - strings.add("NPC_CHAT_1"); - strings.add("NPC_CHAT_2"); - } public static void spawnTeamPlayer(World world, SteamwarUser steamwarUser) { Location location = new Location(world, 2790.5, 69, 1311.5); @@ -149,8 +144,9 @@ public class TeamPlayer extends BasicListener { players.remove(event.getPlayer()); return; } + + String message = "NPC_Chat_" + random.nextInt(6); SteamwarUser user = SteamwarUser.get(event.getRightClicked().getName()); - String message = strings.get(random.nextInt(strings.size())); UserPerm.Prefix prefix = user.prefix(); LobbySystem.getMessage().send(message, event.getPlayer(), event.getRightClicked().getName(), prefix.getColorCode() + prefix.getChatPrefix()); } diff --git a/MissileWars/build.gradle.kts b/MissileWars/build.gradle.kts index 755e1c46..f393ea31 100644 --- a/MissileWars/build.gradle.kts +++ b/MissileWars/build.gradle.kts @@ -27,7 +27,7 @@ java { } dependencies { - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) diff --git a/SchematicSystem/SchematicSystem_15/build.gradle.kts b/SchematicSystem/SchematicSystem_15/build.gradle.kts index bfb78f90..df407384 100644 --- a/SchematicSystem/SchematicSystem_15/build.gradle.kts +++ b/SchematicSystem/SchematicSystem_15/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":SchematicSystem:SchematicSystem_Core")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":SchematicSystem:SchematicSystem_Core", "default")) compileOnly(libs.nms15) compileOnly(libs.worldedit15) diff --git a/SchematicSystem/SchematicSystem_8/build.gradle.kts b/SchematicSystem/SchematicSystem_8/build.gradle.kts index f0e3ade3..5f0f9c62 100644 --- a/SchematicSystem/SchematicSystem_8/build.gradle.kts +++ b/SchematicSystem/SchematicSystem_8/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) - compileOnly(project(":SchematicSystem:SchematicSystem_Core")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":SchematicSystem:SchematicSystem_Core", "default")) compileOnly(libs.nms8) compileOnly(libs.worldedit12) diff --git a/SchematicSystem/SchematicSystem_Core/build.gradle.kts b/SchematicSystem/SchematicSystem_Core/build.gradle.kts index 3c08c5d2..df9415f2 100644 --- a/SchematicSystem/SchematicSystem_Core/build.gradle.kts +++ b/SchematicSystem/SchematicSystem_Core/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) compileOnly(libs.worldedit15) diff --git a/SpigotCore/SpigotCore_10/build.gradle.kts b/SpigotCore/SpigotCore_10/build.gradle.kts index 38bce259..9606f5c6 100644 --- a/SpigotCore/SpigotCore_10/build.gradle.kts +++ b/SpigotCore/SpigotCore_10/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore:SpigotCore_Main")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(libs.nms10) } diff --git a/SpigotCore/SpigotCore_12/build.gradle.kts b/SpigotCore/SpigotCore_12/build.gradle.kts index a4c6acd3..da6a46c9 100644 --- a/SpigotCore/SpigotCore_12/build.gradle.kts +++ b/SpigotCore/SpigotCore_12/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":CommonCore")) - compileOnly(project(":SpigotCore:SpigotCore_Main")) + compileOnly(project(":CommonCore", "default")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(libs.nms12) } diff --git a/SpigotCore/SpigotCore_14/build.gradle.kts b/SpigotCore/SpigotCore_14/build.gradle.kts index 8586caeb..5ffc8c1c 100644 --- a/SpigotCore/SpigotCore_14/build.gradle.kts +++ b/SpigotCore/SpigotCore_14/build.gradle.kts @@ -22,10 +22,10 @@ plugins { } dependencies { - compileOnly(project(":CommonCore")) - compileOnly(project(":SpigotCore:SpigotCore_Main")) - compileOnly(project(":SpigotCore:SpigotCore_8")) - compileOnly(project(":SpigotCore:SpigotCore_9")) + compileOnly(project(":CommonCore", "default")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) + compileOnly(project(":SpigotCore:SpigotCore_8", "default")) + compileOnly(project(":SpigotCore:SpigotCore_9", "default")) compileOnly(libs.nms14) compileOnly(libs.worldedit15) diff --git a/SpigotCore/SpigotCore_15/build.gradle.kts b/SpigotCore/SpigotCore_15/build.gradle.kts index b637545e..1e49db83 100644 --- a/SpigotCore/SpigotCore_15/build.gradle.kts +++ b/SpigotCore/SpigotCore_15/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore:SpigotCore_Main")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(libs.nms15) } diff --git a/SpigotCore/SpigotCore_18/build.gradle.kts b/SpigotCore/SpigotCore_18/build.gradle.kts index b27c3aed..a3d4fb44 100644 --- a/SpigotCore/SpigotCore_18/build.gradle.kts +++ b/SpigotCore/SpigotCore_18/build.gradle.kts @@ -26,9 +26,9 @@ tasks.compileJava { } dependencies { - compileOnly(project(":CommonCore")) - compileOnly(project(":SpigotCore:SpigotCore_Main")) - compileOnly(project(":SpigotCore:SpigotCore_14")) + compileOnly(project(":CommonCore", "default")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) + compileOnly(project(":SpigotCore:SpigotCore_14", "default")) compileOnly(libs.spigotapi) compileOnly(libs.nms18) diff --git a/SpigotCore/SpigotCore_19/build.gradle.kts b/SpigotCore/SpigotCore_19/build.gradle.kts index da876e7e..ce9922e4 100644 --- a/SpigotCore/SpigotCore_19/build.gradle.kts +++ b/SpigotCore/SpigotCore_19/build.gradle.kts @@ -22,9 +22,9 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore:SpigotCore_Main")) - compileOnly(project(":SpigotCore:SpigotCore_14")) - compileOnly(project(":SpigotCore:SpigotCore_18")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) + compileOnly(project(":SpigotCore:SpigotCore_14", "default")) + compileOnly(project(":SpigotCore:SpigotCore_18", "default")) compileOnly(libs.worldedit15) compileOnly(libs.nms19) diff --git a/SpigotCore/SpigotCore_20/build.gradle.kts b/SpigotCore/SpigotCore_20/build.gradle.kts index a2a54c32..3e894ccc 100644 --- a/SpigotCore/SpigotCore_20/build.gradle.kts +++ b/SpigotCore/SpigotCore_20/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore:SpigotCore_Main")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(libs.spigotapi) diff --git a/SpigotCore/SpigotCore_8/build.gradle.kts b/SpigotCore/SpigotCore_8/build.gradle.kts index 0ec4a191..f03254dd 100644 --- a/SpigotCore/SpigotCore_8/build.gradle.kts +++ b/SpigotCore/SpigotCore_8/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":CommonCore")) - compileOnly(project(":SpigotCore:SpigotCore_Main")) + compileOnly(project(":CommonCore", "default")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(libs.nms8) compileOnly(libs.worldedit12) diff --git a/SpigotCore/SpigotCore_9/build.gradle.kts b/SpigotCore/SpigotCore_9/build.gradle.kts index 31209477..3463498a 100644 --- a/SpigotCore/SpigotCore_9/build.gradle.kts +++ b/SpigotCore/SpigotCore_9/build.gradle.kts @@ -22,8 +22,8 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore:SpigotCore_Main")) - compileOnly(project(":SpigotCore:SpigotCore_8")) + compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) + compileOnly(project(":SpigotCore:SpigotCore_8", "default")) compileOnly(libs.nms9) diff --git a/SpigotCore/SpigotCore_Main/build.gradle.kts b/SpigotCore/SpigotCore_Main/build.gradle.kts index c70479e5..88825bc9 100644 --- a/SpigotCore/SpigotCore_Main/build.gradle.kts +++ b/SpigotCore/SpigotCore_Main/build.gradle.kts @@ -26,9 +26,9 @@ tasks.compileJava { } dependencies { - compileOnly(project(":CommonCore")) - compileOnly(project(":CommandFramework")) - compileOnly(project(":SpigotCore:CRIUDummy")) + compileOnly(project(":CommonCore", "default")) + compileOnly(project(":CommandFramework", "default")) + compileOnly(project(":SpigotCore:CRIUDummy", "default")) compileOnly(libs.worldedit12) diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index b01690ec..7019c26d 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -36,6 +36,7 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BiFunction; import java.util.logging.Level; @@ -102,7 +103,7 @@ public class TinyProtocol implements Listener { } public void addFilter(Class packetType, BiFunction filter) { - packetFilters.computeIfAbsent(packetType, c -> Collections.synchronizedList(new ArrayList<>(1))).add(filter); + packetFilters.computeIfAbsent(packetType, c -> new CopyOnWriteArrayList<>()).add(filter); } public void removeFilter(Class packetType, BiFunction filter) { diff --git a/TNTLeague/build.gradle.kts b/TNTLeague/build.gradle.kts index b9689d85..0d7fc472 100644 --- a/TNTLeague/build.gradle.kts +++ b/TNTLeague/build.gradle.kts @@ -4,6 +4,6 @@ plugins { dependencies { compileOnly(libs.paperapi21) - compileOnly(project(":SpigotCore")) - compileOnly(project(":KotlinCore")) + compileOnly(project(":SpigotCore", "default")) + compileOnly(project(":KotlinCore", "default")) } \ No newline at end of file diff --git a/Teamserver/build.gradle.kts b/Teamserver/build.gradle.kts index a2b2a4bb..44d3e49d 100644 --- a/Teamserver/build.gradle.kts +++ b/Teamserver/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.spigotapi) diff --git a/TowerRun/build.gradle.kts b/TowerRun/build.gradle.kts index ad7532f4..8eacd66e 100644 --- a/TowerRun/build.gradle.kts +++ b/TowerRun/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { annotationProcessor(libs.spigotannotations) compileOnly(libs.spigotannotations) - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.nms19) compileOnly(libs.worldedit15) diff --git a/TowerRun/src/de/steamwar/towerrun/FightInfoPacketSender.java b/TowerRun/src/de/steamwar/towerrun/FightInfoPacketSender.java new file mode 100644 index 00000000..da8c913b --- /dev/null +++ b/TowerRun/src/de/steamwar/towerrun/FightInfoPacketSender.java @@ -0,0 +1,66 @@ +/* + * + * 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 . + * / + */ + +package de.steamwar.towerrun; + +import de.steamwar.network.NetworkSender; +import de.steamwar.network.packets.common.FightInfoPacket; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.towerrun.config.Config; +import de.steamwar.towerrun.game.TowerRunGame; +import de.steamwar.towerrun.state.GameState; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class FightInfoPacketSender implements Runnable { + + private final World world = Bukkit.getWorlds().get(0); + + private final String serverName = Bukkit.getServer().getName(); + private final String gameMode = "towerrun"; + private final String worldName = world.getName(); + private final String blueName = "§3Escaped"; + private final String redName = "§cAlive"; + + @Override + public void run() { + if (Config.test()) { + return; + } + + List alivePlayers = TowerRunGame.PLAYERS_ALIVE.stream().map(player -> SteamwarUser.get(player.player().getUniqueId()).getId()).collect(Collectors.toList()); + List escapedPlayers = TowerRunGame.PLAYERS_ESCAPED.stream().map(player -> SteamwarUser.get(player.player().getUniqueId()).getId()).collect(Collectors.toList()); + List spectatorPlayers = new ArrayList<>(); + for (Player player : Bukkit.getOnlinePlayers()) { + int id = SteamwarUser.get(player.getUniqueId()).getId(); + if (!alivePlayers.contains(id) && !escapedPlayers.contains(id)) { + spectatorPlayers.add(id); + } + } + + NetworkSender.send(new FightInfoPacket(serverName, gameMode, worldName, blueName, redName, GameState.getCurrentState().name().toLowerCase(), TowerRun.getGameCountdown().getPlayTimeInSeconds(), 0, 0, 0, 0, escapedPlayers, alivePlayers, spectatorPlayers)); + } +} diff --git a/TowerRun/src/de/steamwar/towerrun/TowerRun.java b/TowerRun/src/de/steamwar/towerrun/TowerRun.java index c0717b2f..23f00488 100644 --- a/TowerRun/src/de/steamwar/towerrun/TowerRun.java +++ b/TowerRun/src/de/steamwar/towerrun/TowerRun.java @@ -32,6 +32,7 @@ import de.steamwar.towerrun.listener.IngameListener; import de.steamwar.towerrun.listener.LobbyListener; import de.steamwar.towerrun.listener.NotLobbyListener; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.annotation.dependency.Dependency; import org.bukkit.plugin.java.annotation.plugin.ApiVersion; @@ -79,6 +80,8 @@ public class TowerRun extends JavaPlugin { new StartCommand(lobbyCountdown); gameCountdown = new GameCountdown(); + Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20); + TowerRunGame.reset(); } } diff --git a/TowerRun/src/de/steamwar/towerrun/config/Config.java b/TowerRun/src/de/steamwar/towerrun/config/Config.java index 7890e785..91fb02b4 100644 --- a/TowerRun/src/de/steamwar/towerrun/config/Config.java +++ b/TowerRun/src/de/steamwar/towerrun/config/Config.java @@ -39,6 +39,8 @@ public class Config { public static final int GAME_TIMER; public static final int GAME_ESCAPE_TIMER; + private static final int EVENT_KAMPF_ID; + static { File configFile = new File(TowerRun.getInstance().getDataFolder(), "config.yml"); if (!configFile.exists()) { @@ -53,6 +55,11 @@ public class Config { GAME_TIMER = config.getInt("gameTimer", 20 * 60); GAME_ESCAPE_TIMER = config.getInt("gameEscapeTimer", 60); DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet())); + + EVENT_KAMPF_ID = Integer.parseInt(System.getProperty("fightID", "0")); } + public static boolean test() { + return EVENT_KAMPF_ID == -1; + } } diff --git a/TowerRun/src/de/steamwar/towerrun/countdowns/EndCountdown.java b/TowerRun/src/de/steamwar/towerrun/countdowns/EndCountdown.java index 95aa3675..dbe0d40d 100644 --- a/TowerRun/src/de/steamwar/towerrun/countdowns/EndCountdown.java +++ b/TowerRun/src/de/steamwar/towerrun/countdowns/EndCountdown.java @@ -35,7 +35,7 @@ public class EndCountdown extends Countdown { private static final boolean RESETS = Objects.requireNonNull(Bukkit.getWorlds().get(0).getWorldFolder().list((dir, name) -> name.equals("backup"))).length > 0; public EndCountdown(LobbyCountdown lobbyCountdown) { - super(EnumSet.of(GameStates.ENDING)); + super(EnumSet.of(GameStates.END)); this.lobbyCountdown = lobbyCountdown; } diff --git a/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java b/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java index b56c1f3b..b1d25110 100644 --- a/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java +++ b/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java @@ -28,8 +28,10 @@ import java.util.EnumSet; public class GameCountdown extends Countdown { + private long startTime = 0; + public GameCountdown() { - super(EnumSet.of(GameStates.INGAME)); + super(EnumSet.of(GameStates.RUNNING)); } @Override @@ -59,9 +61,21 @@ public class GameCountdown extends Countdown { TowerRun.getMessage().broadcastActionbar("GAME_TIME", String.format("%02d", timeMinutes), String.format("%02d", timeSeconds)); } + @Override + public void enable() { + super.enable(); + startTime = System.currentTimeMillis(); + } + @Override public void disable() { super.disable(); setTime(defaultTime()); + startTime = 0; + } + + public int getPlayTimeInSeconds() { + if (startTime == 0) return 0; + return (int) ((System.currentTimeMillis() - startTime) / 1000); } } diff --git a/TowerRun/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java b/TowerRun/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java index 40808f1e..a655c4c3 100644 --- a/TowerRun/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java +++ b/TowerRun/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java @@ -37,7 +37,7 @@ public class LobbyCountdown extends Countdown { private boolean override = false; public LobbyCountdown() { - super(EnumSet.of(GameStates.LOBBY)); + super(EnumSet.of(GameStates.WAITING)); } @Override diff --git a/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java b/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java index 2d71ef1d..c83138d4 100644 --- a/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/TowerRun/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -49,7 +49,7 @@ public class TowerRunGame { } public static void prepareTowerOrStart() { - if (GameState.getCurrentState() == GameStates.LOBBY) { + if (GameState.getCurrentState() == GameStates.WAITING) { GameState.nextState(); if (TowerRun.getTowerGenerator() == null) { start(); diff --git a/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java b/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java index ea07eb04..9e30cf07 100644 --- a/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java @@ -52,7 +52,7 @@ public class IngameListener extends GameStateBukkitListener { private BukkitRunnable antiCampRunnable; public IngameListener() { - super(EnumSet.of(GameStates.INGAME)); + super(EnumSet.of(GameStates.RUNNING)); } @Override diff --git a/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java b/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java index eb2cb157..52d600ca 100644 --- a/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java +++ b/TowerRun/src/de/steamwar/towerrun/listener/LobbyListener.java @@ -37,7 +37,7 @@ import java.util.EnumSet; public class LobbyListener extends GameStateBukkitListener { public LobbyListener() { - super(EnumSet.of(GameStates.LOBBY)); + super(EnumSet.of(GameStates.WAITING)); } @EventHandler diff --git a/TowerRun/src/de/steamwar/towerrun/listener/NotLobbyListener.java b/TowerRun/src/de/steamwar/towerrun/listener/NotLobbyListener.java index 4d3525e5..6bfb1623 100644 --- a/TowerRun/src/de/steamwar/towerrun/listener/NotLobbyListener.java +++ b/TowerRun/src/de/steamwar/towerrun/listener/NotLobbyListener.java @@ -31,7 +31,7 @@ import java.util.EnumSet; public class NotLobbyListener extends GameStateBukkitListener { public NotLobbyListener() { - super(EnumSet.complementOf(EnumSet.of(GameStates.LOBBY))); + super(EnumSet.complementOf(EnumSet.of(GameStates.WAITING))); } @EventHandler diff --git a/TowerRun/src/de/steamwar/towerrun/state/GameState.java b/TowerRun/src/de/steamwar/towerrun/state/GameState.java index 3c3a55e0..46b7e93a 100644 --- a/TowerRun/src/de/steamwar/towerrun/state/GameState.java +++ b/TowerRun/src/de/steamwar/towerrun/state/GameState.java @@ -28,7 +28,7 @@ import java.util.List; @UtilityClass public class GameState { @Getter - private static GameStates currentState = GameStates.LOBBY; + private static GameStates currentState = GameStates.WAITING; private static final List gameStateListeners = new ArrayList<>(); public static void addGameStateListener(GameStateListener gameStateListener) { @@ -49,7 +49,7 @@ public class GameState { public static void reset() { final GameStates oldState = currentState; - currentState = GameStates.LOBBY; + currentState = GameStates.WAITING; gameStateChanges(oldState, currentState); } diff --git a/TowerRun/src/de/steamwar/towerrun/state/GameStates.java b/TowerRun/src/de/steamwar/towerrun/state/GameStates.java index 347e9814..4fe32829 100644 --- a/TowerRun/src/de/steamwar/towerrun/state/GameStates.java +++ b/TowerRun/src/de/steamwar/towerrun/state/GameStates.java @@ -25,10 +25,10 @@ import lombok.Getter; @AllArgsConstructor @Getter public enum GameStates { - ENDING(null), - INGAME(ENDING), - GENERATING_TOWER(INGAME), - LOBBY(GENERATING_TOWER); + END(null), + RUNNING(END), + GENERATING_TOWER(RUNNING), + WAITING(GENERATING_TOWER); private final GameStates nextState; } diff --git a/TowerRun/src/de/steamwar/towerrun/winconditions/WinCondition.java b/TowerRun/src/de/steamwar/towerrun/winconditions/WinCondition.java index 4a736dd5..21e0e860 100644 --- a/TowerRun/src/de/steamwar/towerrun/winconditions/WinCondition.java +++ b/TowerRun/src/de/steamwar/towerrun/winconditions/WinCondition.java @@ -34,7 +34,7 @@ public abstract class WinCondition extends GameStateBukkitListener { private boolean active = false; protected WinCondition(String name) { - super(EnumSet.of(GameStates.INGAME)); + super(EnumSet.of(GameStates.RUNNING)); this.name = name; } diff --git a/TutorialSystem/build.gradle.kts b/TutorialSystem/build.gradle.kts index 4b7a557a..0336de23 100644 --- a/TutorialSystem/build.gradle.kts +++ b/TutorialSystem/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } dependencies { - compileOnly(project(":SpigotCore")) + compileOnly(project(":SpigotCore", "default")) compileOnly(libs.nms15) } diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 2255dc08..e9d6386e 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -48,7 +48,7 @@ dependencies { annotationProcessor(libs.velocityapi) compileOnly(libs.velocity) - compileOnly(project(":VelocityCore:Persistent")) + compileOnly(project(":VelocityCore:Persistent", "default")) implementation(project(":CommonCore")) implementation(project(":CommandFramework")) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 5bb5238b..2535aaf3 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -739,6 +739,7 @@ DC_TICKETINTRO_IDEA=Describe your idea as detailed as possible. Hereto belongs: DC_TICKETINTRO_BUG=Please describe the observed unexpected or incorrect behaviour of our software. If necessary describe steps to reproduce the error. DC_TICKETINTRO_QUESTION=Please ask your question. A staff member will address the question soon. DC_TICKETINTRO_APPEAL=Asking creates wonders. +DC_TICKETINTRO_SCHEMATIC=Please answer the following questions as precisely as possible for the locking of the Schematic and, if possible, add evidence:\n - Which player(s)?\n - On which Arena Server\n - At what time?\n - Rules which the Schematic violates (rules/code of conduct) DC_TICKET_CLOSE=Close DC_SCHEMUPLOAD_NOPERM=You\'re not allowed to upload schematics. diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index edc46c77..786ad244 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -692,6 +692,7 @@ DC_TICKETINTRO_IDEA=Beschreibe deine Idee möglichst detailiert. Hierzu gehört: DC_TICKETINTRO_BUG=Bitte beschreibe das beobachtete unerwartete bzw. inkorrekte Verhalten der Serversoftware. Falls notwendig, beschreibe die Schritte, mit denen der Fehler reproduziert werden kann. DC_TICKETINTRO_QUESTION=Bitte stelle deine Frage, ein Serverteammitglied wird sich dieser zeitnah annehmen. DC_TICKETINTRO_APPEAL=Fragen wirkt Wunder! +DC_TICKETINTRO_SCHEMATIC=Bitte beantworte für die sperrung der Schematic möglichst genau folgende Fragen und füge nach Möglichkeit Beweismaterial hinzu:\n - Welche(r) Spieler?\n - Auf welchem Arena Server\n - Zu welchem Zeitpunkt?\n - Regeln, gegen welche die Schematic verstößt (Regelwerk/ Verhaltensrichtlinien) DC_TICKET_CLOSE=Schließen DC_SCHEMUPLOAD_NOPERM=Du darfst keine Schematics hochladen. diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java index 32b65e93..928d6e78 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java @@ -478,6 +478,7 @@ public class TeamCommand extends SWCommand { } @Register("color") + @Register("changecolor") public void changeColor(@Validator("isLeader") PlayerChatter sender) { Team team = Team.get(sender.user().getTeam()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 3928da7b..10cb773f 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -30,20 +30,29 @@ import de.steamwar.velocitycore.discord.listeners.DiscordTeamEvent; import de.steamwar.velocitycore.discord.listeners.DiscordTicketHandler; import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; -import net.dv8tion.jda.api.*; -import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; +import net.dv8tion.jda.api.OnlineStatus; +import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; +import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; import net.dv8tion.jda.api.utils.MemberCachePolicy; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import javax.security.auth.login.LoginException; import java.awt.*; import java.util.List; import java.util.*; @@ -87,15 +96,12 @@ public class DiscordBot { public DiscordBot(DiscordConfig config) { this.config = config; - try { - jda = JDABuilder - .createDefault(config.getToken()) - .setStatus(OnlineStatus.ONLINE) - .setMemberCachePolicy(MemberCachePolicy.ONLINE) - .build(); - } catch (LoginException e) { - throw new SecurityException("Could not login", e); - } + jda = JDABuilder + .createDefault(config.getToken()) + .setStatus(OnlineStatus.ONLINE) + .setMemberCachePolicy(MemberCachePolicy.ONLINE) + .enableIntents(GatewayIntent.MESSAGE_CONTENT) + .build(); instance = this; VelocityCore.schedule(this::asyncInit).schedule(); @@ -109,9 +115,9 @@ public class DiscordBot { } activity(); - new StaticMessageChannel(config.channel("roles"), () -> new MessageBuilder() + new StaticMessageChannel(config.channel("roles"), () -> new MessageCreateBuilder() .setContent("**Rollenvergabe**\nKlicke um eine Rolle zu bekommen:") - .setActionRows(ActionRow.of(config.getRoles().values().stream().map(DiscordConfig.DiscordRole::toButton).toArray(Button[]::new))), event -> InteractionReply.reply(event, reply -> { + .setComponents(ActionRow.of(config.getRoles().values().stream().map(DiscordConfig.DiscordRole::toButton).toArray(Button[]::new))), event -> InteractionReply.reply(event, reply -> { Member member = event.getMember(); Guild guild = event.getGuild(); Role role = guild.getRoleById(event.getComponentId()); @@ -124,33 +130,45 @@ public class DiscordBot { reply.system("DC_ROLE_ADDED", role.getAsMention()); } })); - new StaticMessageChannel(config.channel("rules"), () -> new MessageBuilder() + new StaticMessageChannel(config.channel("rules"), () -> new MessageCreateBuilder() .setEmbeds(new EmbedBuilder() .setDescription(String.join("\n", config.getRules())) .setColor(Color.GRAY) .setAuthor("SteamWar", "https://steamwar.de") .setTitle("Regeln und Infos") .build()) - .setActionRows( + .setComponents( ActionRow.of(Button.link("https://steamwar.de", "Website"), Button.link("https://steamwar.de/youtube", "YouTube")), ActionRow.of(Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen")) ), event -> { if(event.getComponentId().equals("auth")) event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + AuthManager.createDiscordAuthToken(event.getUser()) + "`` auf dem Minecraft Server ein").setEphemeral(true).queue(); }); - new StaticMessageChannel(config.channel("ticket"), () -> new MessageBuilder() + List actionRows = new ArrayList<>(); + List