From bf1368a34e4b8646b91cff0e44ad23995a84e7c5 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 6 May 2021 20:15:51 +0200 Subject: [PATCH 01/26] . --- FightSystem_10/pom.xml | 4 +- FightSystem_12/pom.xml | 4 +- FightSystem_14/pom.xml | 4 +- FightSystem_15/pom.xml | 4 +- FightSystem_8/pom.xml | 4 +- FightSystem_9/pom.xml | 4 +- FightSystem_API/pom.xml | 2 +- .../winconditions/Winconditions.java | 3 +- FightSystem_Main/pom.xml | 4 +- .../fightsystem/event/Hells_Bells.java | 46 ++++++ .../winconditions/Hells_Bells.java | 135 ++++++++++++++++++ pom.xml | 4 +- 12 files changed, 200 insertions(+), 18 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java diff --git a/FightSystem_10/pom.xml b/FightSystem_10/pom.xml index 66633c1..1a33c29 100644 --- a/FightSystem_10/pom.xml +++ b/FightSystem_10/pom.xml @@ -46,14 +46,14 @@ WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.12.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar steamwar Spigot 1.10 system - ${main.basedir}/lib/Spigot-1.10.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.10.jar \ No newline at end of file diff --git a/FightSystem_12/pom.xml b/FightSystem_12/pom.xml index 0c0bcba..c318966 100644 --- a/FightSystem_12/pom.xml +++ b/FightSystem_12/pom.xml @@ -46,14 +46,14 @@ WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.12.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar steamwar Spigot 1.12 system - ${main.basedir}/lib/Spigot-1.12.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.12.jar \ No newline at end of file diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml index 3d7c934..632d071 100644 --- a/FightSystem_14/pom.xml +++ b/FightSystem_14/pom.xml @@ -36,14 +36,14 @@ Spigot 1.14 system - ${main.basedir}/lib/Spigot-1.14.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.14.jar steamwar WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.15.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.15.jar steamwar diff --git a/FightSystem_15/pom.xml b/FightSystem_15/pom.xml index 8858c54..7677777 100644 --- a/FightSystem_15/pom.xml +++ b/FightSystem_15/pom.xml @@ -36,14 +36,14 @@ Spigot 1.15 system - ${main.basedir}/lib/Spigot-1.15.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.15.jar steamwar WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.15.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.15.jar steamwar diff --git a/FightSystem_8/pom.xml b/FightSystem_8/pom.xml index 2fabd6f..b10607e 100644 --- a/FightSystem_8/pom.xml +++ b/FightSystem_8/pom.xml @@ -36,7 +36,7 @@ Spigot 1.8 system - ${main.basedir}/lib/Spigot-1.8.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.8.jar steamwar @@ -48,7 +48,7 @@ WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.12.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar \ No newline at end of file diff --git a/FightSystem_9/pom.xml b/FightSystem_9/pom.xml index 769e6c2..bdf448e 100644 --- a/FightSystem_9/pom.xml +++ b/FightSystem_9/pom.xml @@ -46,14 +46,14 @@ WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.12.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar steamwar Spigot 1.9 system - ${main.basedir}/lib/Spigot-1.9.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.9.jar \ No newline at end of file diff --git a/FightSystem_API/pom.xml b/FightSystem_API/pom.xml index a2faacd..02ae613 100644 --- a/FightSystem_API/pom.xml +++ b/FightSystem_API/pom.xml @@ -36,7 +36,7 @@ Spigot 1.12 system - ${main.basedir}/lib/Spigot-1.12.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.12.jar \ No newline at end of file diff --git a/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 0394ee7..604cc99 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -30,5 +30,6 @@ public enum Winconditions { POINTS, TIME_TECH_KO, WATER_TECH_KO, - PUMPKIN_TECH_KO + PUMPKIN_TECH_KO, + HELLS_BELLS } diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 3083862..a4a62e0 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -52,14 +52,14 @@ Spigot 1.15 system - ${main.basedir}/lib/Spigot-1.15.jar + ${main.basedir}/../SteamwarLibs/Spigot-1.15.jar steamwar WorldEdit 1.0 system - ${main.basedir}/lib/WorldEdit-1.12.jar + ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar steamwar diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java new file mode 100644 index 0000000..c5815ca --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java @@ -0,0 +1,46 @@ +package de.steamwar.fightsystem.event; + +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.winconditions.Winconditions; + + +public class Hells_Bells { + + public Hells_Bells() { + (new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { + + @Override + public void enable() { + + } + + @Override + public void disable() { + + } + }).register(); + } + + private static class Hells_Bells_Event { + + private static class Hells_Bells_Countdown extends Countdown { + + public Hells_Bells_Countdown(int time, SWSound sound, boolean level) { + super(time, sound, level); + } + + @Override + public String countdownCounting() { + return "bis die Bomben fallen"; + } + + @Override + public void countdownFinished() { + + } + } + } +} \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java new file mode 100644 index 0000000..096f9c4 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java @@ -0,0 +1,135 @@ +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.StateDependentCountdown; +import java.util.Random; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; + + +public class Hells_Bells extends WinconditionAllDead { + + private static int overlap = 5; + private static int distance = 3; + private static int width = 65; + private static int length = 40; + private static int height = 70; + + private static int startTime = 40; + private static int endTime = 20; + private static int warningTime = 10; + private static int steps = 20; + private static int currentStep = 0; + private static int nextTime = startTime; + + public static Random randomGenerator = new Random(); + public static boolean debug = false; + private static int scheduler1 = 0; + private static int scheduler2 = 0; + private static World world = null; //TODO Woher bekomm ich die? + + private static int getNextTime(int step) { + if (step == 0) { + return startTime; + } + else { + float temp = (startTime - (((startTime - endTime)/steps) * step)); + if ((temp <= startTime) && (temp >= endTime)) { + return ((int) temp + getNextTime(step - 1)); + } + else { + return endTime + getNextTime(step - 1); + } + } + } + + public static void hellsBells(int time) { + if (time == nextTime) { + if (randomGenerator.nextInt(2) == 1) { + Double temp = randomGenerator.nextDouble(); + if (debug) { + Bukkit.broadcastMessage("SideBombRun ; Route = " + temp.toString()); + } + + sideBombRun(temp); + } + else { + Double temp = randomGenerator.nextDouble(); + if (debug) { + Bukkit.broadcastMessage("FrontBombRun ; Route = " + temp.toString()); + } + frontBombRun(temp); + } + currentStep++; + nextTime = getNextTime(currentStep); + if (debug) { + Bukkit.broadcastMessage("currentStep = " + currentStep + " ; nextTime = " + nextTime); + + } + } + else if (time == nextTime - warningTime) { + Bukkit.broadcastMessage("Achtung! In " + warningTime + " Sekunden fallen Bomben!"); + } + } + + public static void sideBombRun(Double route) { + Location temp1 = new Location(world, Main.ArenaMidX + overlap + (int)(width/2), Main.ArenaMidY + height, Main.ArenaMidZ + 25 + distance + (int)(route * (length - (2 * distance)))); + Location temp2 = new Location(world, Main.ArenaMidX - overlap - (int)(width/2), Main.ArenaMidY + height, Main.ArenaMidZ - 25 - distance - (int)(route * (length - (2 * distance)))); + sideBomb(temp1, temp2, (int)((width + 2 * overlap)/2)); + } + + public static void sideBomb(Location loc1, Location loc2, int count){ + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() - 2), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() - 1), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() + 1), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() + 2), EntityType.PRIMED_TNT); + + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() - 2), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() - 1), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() + 1), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() + 2), EntityType.PRIMED_TNT); + + if (count >= 1) { + final Location temp1 = new Location(loc1.getWorld(), loc1.getX() - 2, loc1.getY(), loc1.getZ()); + final Location temp2 = new Location(loc2.getWorld(), loc2.getX() + 2, loc2.getY(), loc2.getZ()); + final int temp3 = count - 1; + scheduler1 = Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), () -> sideBomb(temp1, temp2, temp3), 4L); + // Bukkit.getScheduler().cancelTask(scheduler1); + // scheduler1 = 0; + } + } + + public static void frontBombRun(Double route) { + Location temp1 = new Location(world, Main.ArenaMidX + distance + (int)(route * (width - (2 * distance))) - (int) (width / 2), Main.ArenaMidY + height, Main.ArenaMidZ + 25 - overlap); + Location temp2 = new Location(world, Main.ArenaMidX - distance - (int)(route * (width - (2 * distance))) + (int) (width / 2), Main.ArenaMidY + height, Main.ArenaMidZ - 25 + overlap); + frontBomb(temp1, temp2, (int)((length + 2 * overlap) / 2)); + } + + public static void frontBomb(Location loc1, Location loc2, int count){ + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() - 2, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() - 1, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() + 1, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() + 2, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); + + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() - 2, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() - 1, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() + 1, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); + world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() + 2, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); + + if (count >= 1) { + final Location temp1 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() + 2); + final Location temp2 = new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() - 2); + final int temp3 = count - 1; + scheduler2 = Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), () -> frontBomb(temp1, temp2, temp3), 4L); + // Bukkit.getScheduler().cancelTask(scheduler2); + // scheduler2 = 0; + } + } + + public static void EndHellsBells() { + nextTime = startTime; + currentStep = 0; + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 455d1b6..58520e6 100644 --- a/pom.xml +++ b/pom.xml @@ -46,14 +46,14 @@ SpigotCore 1.0 system - ${main.basedir}/lib/SpigotCore.jar + ${main.basedir}/../SteamwarLibs/SpigotCore.jar steamwar ProtocolLib 1.0 system - ${main.basedir}/lib/ProtocolLib.jar + ${main.basedir}/../SteamwarLibs/ProtocolLib.jar From 1ede1c1101ae37451638dd444b2fceb62e5eb1de Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 19:19:03 +0200 Subject: [PATCH 02/26] First implementation of HellsBells --- .../de/steamwar/fightsystem/FightSystem.java | 4 + .../fightsystem/event/HellsBells.java | 288 ++++++++++++++++++ .../fightsystem/event/Hells_Bells.java | 46 --- .../winconditions/Hells_Bells.java | 135 -------- 4 files changed, 292 insertions(+), 181 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 16a8072..d4fc09c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -23,6 +23,7 @@ import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; +import de.steamwar.fightsystem.event.HellsBells; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; @@ -106,6 +107,9 @@ public class FightSystem extends JavaPlugin { new RankedPlayerLeftWincondition(); new WinconditionPercentTimeout(); + //noinspection InstantiationOfUtilityClass + new HellsBells(); + new NoPlayersOnlineCountdown(); new PreSchemCountdown(); new PostSchemCountdown(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java new file mode 100644 index 0000000..90691bc --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -0,0 +1,288 @@ +package de.steamwar.fightsystem.event; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.winconditions.Winconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.scheduler.BukkitRunnable; + + +public class HellsBells { + + public static final Random random = new Random(); + + public HellsBells() { + new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { + + private HellsBellsEvent event = null; + + @Override + public void enable() { + if (event != null) { + event.terminate(); + } + event = new HellsBellsEvent(); + event.init(); + } + + @Override + public void disable() { + if (event != null) { + event.terminate(); + } + event = null; + } + }.register(); + } + + private static class HellsBellsEvent { + + private final World world = Bukkit.getWorlds().get(0); + private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX(); + private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ(); + private State current = State.PRE; + private long stateStart = 0; + private HellsBellsCountdown currentCountdown; + private static final List startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.", + "§cBomber im Anflug, ca. eine Minute bis zur Ankunft.", + "§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.", + "§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.", + "§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.", + "§cBomber erschienen, Ankunft ca. eine Minute."); + + + public void init() { + stateStart = System.currentTimeMillis(); + startCountdown(); + } + + public void terminate() { + current = State.NONE; + currentCountdown.disable(); + } + + public void startCountdown() { + if (current != State.NONE) { + long currentTime = System.currentTimeMillis(); + if (current != State.LAST && currentTime >= stateStart + (current.switchAfter * 1000L)) { + if (current != State.PRE) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller."); + } + + current = current.getNext(); + stateStart = currentTime; + } + + int timer = current.minTime + random.nextInt(current.maxTime - current.minTime); + if (current == State.PRE) { + Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); + } + currentCountdown = new HellsBellsCountdown(timer, SWSound.BLOCK_NOTE_BASS, true); + currentCountdown.enable(); + } + } + + public void drop() { + if (random.nextBoolean()) { + sideRun(random.nextBoolean()); + } else { + frontRun(random.nextBoolean()); + } + } + + + private void sideRun(boolean invert) { + int length = 10 + random.nextInt(zLength - 10); + int xOffset = getWidthStart(xLength); + int zOffset = getLengthStart(zLength, length); + int yOffset = 25 + getHeightStart(); + + + Point redStart; + Point blueStart; + + if (invert) { + redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); + blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); + } else { + redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); + } + + dropSideBombPart(redStart, blueStart, new int[]{length}, invert); + } + + private void dropSideBombPart(Point redStart, Point blueStart, int[] x, boolean invert) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> new BukkitRunnable() { + @Override + public void run() { + for (int z = 0; z < 4; z++) { + if (invert) { + world.spawnEntity(redStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + + world.spawnEntity(blueStart.addAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + } else { + world.spawnEntity(redStart.addAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + + world.spawnEntity(blueStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + } + } + + if (x[0] < 2) { + this.cancel(); + return; + } + + x[0] -= 2; + } + }, 0, 4L); + } + + + private void frontRun(boolean invert) { + int length = 10 + random.nextInt(xLength - 10); + int xOffset = getWidthStart(zLength); + int zOffset = getLengthStart(xLength, length); + int yOffset = 25 + getHeightStart(); + + Point redStart; + Point blueStart; + + if (invert) { + redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); + blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); + } else { + redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); + } + + dropFrontBombPart(redStart, blueStart, new int[]{length}, invert); + } + + private void dropFrontBombPart(Point redStart, Point blueStart, int[] z, boolean invert) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> new BukkitRunnable() { + @Override + public void run() { + for (int x = 0; x < 4; x++) { + if (invert) { + world.spawnEntity(redStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); + + world.spawnEntity(blueStart.addAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); + } else { + world.spawnEntity(redStart.addAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); + + world.spawnEntity(blueStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); + } + } + + if (z[0] < 2) { + this.cancel(); + return; + } + + z[0] -= 2; + } + }, 0, 4L); + } + + private int getLengthStart(int regionSize, int length) { + return random.nextInt(regionSize - length); + } + + private int getWidthStart(int regionSize) { + return random.nextInt(regionSize - 4); + } + + private int getHeightStart() { + return random.nextInt(15); + } + + private class HellsBellsCountdown extends Countdown { + + public HellsBellsCountdown(int time, SWSound sound, boolean level) { + super(time, sound, level); + } + + @Override + public String countdownCounting() { + return "bis die Bomben fallen"; + } + + @Override + public void countdownFinished() { + drop(); + + startCountdown(); + } + } + + private static class Point { + + private final int x; + private final int y; + private final int z; + + public Point(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Location addAndToLocation(World world, int x, int y, int z) { + return new Location(world, this.x + x, this.y + y, this.z + z); + } + + public Location subtractAndToLocation(World world, int x, int y, int z) { + return new Location(world, this.x - x, this.y - y, this.z - z); + } + } + + private enum State { + + NONE(0, 0, -1), + PRE(60, 80, 50), + FIRST(40, 60, 5 * 60), + SECOND(30, 40, 4 * 60), + THIRD(20, 30, 3 * 60), + LAST(10, 20, -1); + + + State(int minTime, int maxTime, int switchAfter) { + this.minTime = minTime; + this.maxTime = maxTime; + this.switchAfter = switchAfter; + } + + private final int minTime; + private final int maxTime; + private final int switchAfter; + + + public State getNext() { + switch (this) { + case PRE: + return FIRST; + case FIRST: + return SECOND; + case SECOND: + return THIRD; + case THIRD: + case LAST: + return LAST; + default: + return NONE; + } + } + } + } +} \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java deleted file mode 100644 index c5815ca..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/Hells_Bells.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.steamwar.fightsystem.event; - -import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.countdown.SWSound; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.winconditions.Winconditions; - - -public class Hells_Bells { - - public Hells_Bells() { - (new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { - - @Override - public void enable() { - - } - - @Override - public void disable() { - - } - }).register(); - } - - private static class Hells_Bells_Event { - - private static class Hells_Bells_Countdown extends Countdown { - - public Hells_Bells_Countdown(int time, SWSound sound, boolean level) { - super(time, sound, level); - } - - @Override - public String countdownCounting() { - return "bis die Bomben fallen"; - } - - @Override - public void countdownFinished() { - - } - } - } -} \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java deleted file mode 100644 index 096f9c4..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Hells_Bells.java +++ /dev/null @@ -1,135 +0,0 @@ -package de.steamwar.fightsystem.winconditions; - -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.states.StateDependentCountdown; -import java.util.Random; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.EntityType; - - -public class Hells_Bells extends WinconditionAllDead { - - private static int overlap = 5; - private static int distance = 3; - private static int width = 65; - private static int length = 40; - private static int height = 70; - - private static int startTime = 40; - private static int endTime = 20; - private static int warningTime = 10; - private static int steps = 20; - private static int currentStep = 0; - private static int nextTime = startTime; - - public static Random randomGenerator = new Random(); - public static boolean debug = false; - private static int scheduler1 = 0; - private static int scheduler2 = 0; - private static World world = null; //TODO Woher bekomm ich die? - - private static int getNextTime(int step) { - if (step == 0) { - return startTime; - } - else { - float temp = (startTime - (((startTime - endTime)/steps) * step)); - if ((temp <= startTime) && (temp >= endTime)) { - return ((int) temp + getNextTime(step - 1)); - } - else { - return endTime + getNextTime(step - 1); - } - } - } - - public static void hellsBells(int time) { - if (time == nextTime) { - if (randomGenerator.nextInt(2) == 1) { - Double temp = randomGenerator.nextDouble(); - if (debug) { - Bukkit.broadcastMessage("SideBombRun ; Route = " + temp.toString()); - } - - sideBombRun(temp); - } - else { - Double temp = randomGenerator.nextDouble(); - if (debug) { - Bukkit.broadcastMessage("FrontBombRun ; Route = " + temp.toString()); - } - frontBombRun(temp); - } - currentStep++; - nextTime = getNextTime(currentStep); - if (debug) { - Bukkit.broadcastMessage("currentStep = " + currentStep + " ; nextTime = " + nextTime); - - } - } - else if (time == nextTime - warningTime) { - Bukkit.broadcastMessage("Achtung! In " + warningTime + " Sekunden fallen Bomben!"); - } - } - - public static void sideBombRun(Double route) { - Location temp1 = new Location(world, Main.ArenaMidX + overlap + (int)(width/2), Main.ArenaMidY + height, Main.ArenaMidZ + 25 + distance + (int)(route * (length - (2 * distance)))); - Location temp2 = new Location(world, Main.ArenaMidX - overlap - (int)(width/2), Main.ArenaMidY + height, Main.ArenaMidZ - 25 - distance - (int)(route * (length - (2 * distance)))); - sideBomb(temp1, temp2, (int)((width + 2 * overlap)/2)); - } - - public static void sideBomb(Location loc1, Location loc2, int count){ - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() - 2), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() - 1), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() + 1), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() + 2), EntityType.PRIMED_TNT); - - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() - 2), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() - 1), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() + 1), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() + 2), EntityType.PRIMED_TNT); - - if (count >= 1) { - final Location temp1 = new Location(loc1.getWorld(), loc1.getX() - 2, loc1.getY(), loc1.getZ()); - final Location temp2 = new Location(loc2.getWorld(), loc2.getX() + 2, loc2.getY(), loc2.getZ()); - final int temp3 = count - 1; - scheduler1 = Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), () -> sideBomb(temp1, temp2, temp3), 4L); - // Bukkit.getScheduler().cancelTask(scheduler1); - // scheduler1 = 0; - } - } - - public static void frontBombRun(Double route) { - Location temp1 = new Location(world, Main.ArenaMidX + distance + (int)(route * (width - (2 * distance))) - (int) (width / 2), Main.ArenaMidY + height, Main.ArenaMidZ + 25 - overlap); - Location temp2 = new Location(world, Main.ArenaMidX - distance - (int)(route * (width - (2 * distance))) + (int) (width / 2), Main.ArenaMidY + height, Main.ArenaMidZ - 25 + overlap); - frontBomb(temp1, temp2, (int)((length + 2 * overlap) / 2)); - } - - public static void frontBomb(Location loc1, Location loc2, int count){ - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() - 2, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() - 1, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() + 1, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc1.getWorld(), loc1.getX() + 2, loc1.getY(), loc1.getZ()), EntityType.PRIMED_TNT); - - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() - 2, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() - 1, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() + 1, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); - world.spawnEntity(new Location(loc2.getWorld(), loc2.getX() + 2, loc2.getY(), loc2.getZ()), EntityType.PRIMED_TNT); - - if (count >= 1) { - final Location temp1 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY(), loc1.getZ() + 2); - final Location temp2 = new Location(loc2.getWorld(), loc2.getX(), loc2.getY(), loc2.getZ() - 2); - final int temp3 = count - 1; - scheduler2 = Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), () -> frontBomb(temp1, temp2, temp3), 4L); - // Bukkit.getScheduler().cancelTask(scheduler2); - // scheduler2 = 0; - } - } - - public static void EndHellsBells() { - nextTime = startTime; - currentStep = 0; - } -} \ No newline at end of file From 309ba84865212ee3c541d3128e209354d30c0945 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:11:55 +0200 Subject: [PATCH 03/26] more random --- .../fightsystem/event/HellsBells.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 90691bc..b0cbf19 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -103,30 +103,31 @@ public class HellsBells { private void sideRun(boolean invert) { int length = 10 + random.nextInt(zLength - 10); - int xOffset = getWidthStart(xLength); + int width = 5 + random.nextInt(5); + int xOffset = getWidthStart(xLength, width); int zOffset = getLengthStart(zLength, length); - int yOffset = 25 + getHeightStart(); + int yOffset = getHeightStart(); Point redStart; Point blueStart; if (invert) { - redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); - blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); + redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); + blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); } else { - redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); - blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); + redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); } - dropSideBombPart(redStart, blueStart, new int[]{length}, invert); + dropSideBombs(redStart, blueStart, width, new int[]{length}, invert); } - private void dropSideBombPart(Point redStart, Point blueStart, int[] x, boolean invert) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> new BukkitRunnable() { + private void dropSideBombs(Point redStart, Point blueStart, int width, int[] x, boolean invert) { + new BukkitRunnable() { @Override public void run() { - for (int z = 0; z < 4; z++) { + for (int z = 0; z < width; z++) { if (invert) { world.spawnEntity(redStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); @@ -145,35 +146,36 @@ public class HellsBells { x[0] -= 2; } - }, 0, 4L); + }.runTaskTimer(FightSystem.getPlugin(), 0, 4L); } private void frontRun(boolean invert) { int length = 10 + random.nextInt(xLength - 10); - int xOffset = getWidthStart(zLength); - int zOffset = getLengthStart(xLength, length); - int yOffset = 25 + getHeightStart(); + int width = 5 + random.nextInt(5); + int xOffset = getWidthStart(zLength, length); + int zOffset = getLengthStart(xLength, width); + int yOffset = getHeightStart(); Point redStart; Point blueStart; if (invert) { - redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); - blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); + redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); + blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); } else { - redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedPasteRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); - blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BluePasteRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); + redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); } - dropFrontBombPart(redStart, blueStart, new int[]{length}, invert); + dropFrontBombs(redStart, blueStart, width, new int[]{length}, invert); } - private void dropFrontBombPart(Point redStart, Point blueStart, int[] z, boolean invert) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> new BukkitRunnable() { + private void dropFrontBombs(Point redStart, Point blueStart, int width, int[] z, boolean invert) { + new BukkitRunnable() { @Override public void run() { - for (int x = 0; x < 4; x++) { + for (int x = 0; x < width; x++) { if (invert) { world.spawnEntity(redStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); @@ -192,19 +194,19 @@ public class HellsBells { z[0] -= 2; } - }, 0, 4L); + }.runTaskTimer(FightSystem.getPlugin(), 0, 4L); } private int getLengthStart(int regionSize, int length) { return random.nextInt(regionSize - length); } - private int getWidthStart(int regionSize) { - return random.nextInt(regionSize - 4); + private int getWidthStart(int regionSize, int length) { + return random.nextInt(regionSize - length); } private int getHeightStart() { - return random.nextInt(15); + return 5 + random.nextInt(15); } private class HellsBellsCountdown extends Countdown { From bb6dbff20b056fc2d6ccd3f63ce3715b87a5d10c Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:18:44 +0200 Subject: [PATCH 04/26] fixed poms --- FightSystem_10/pom.xml | 4 ++-- FightSystem_12/pom.xml | 4 ++-- FightSystem_14/pom.xml | 4 ++-- FightSystem_15/pom.xml | 4 ++-- FightSystem_8/pom.xml | 4 ++-- FightSystem_9/pom.xml | 4 ++-- FightSystem_API/pom.xml | 2 +- FightSystem_Main/pom.xml | 4 ++-- pom.xml | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/FightSystem_10/pom.xml b/FightSystem_10/pom.xml index 1a33c29..66633c1 100644 --- a/FightSystem_10/pom.xml +++ b/FightSystem_10/pom.xml @@ -46,14 +46,14 @@ WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar + ${main.basedir}/lib/WorldEdit-1.12.jar steamwar Spigot 1.10 system - ${main.basedir}/../SteamwarLibs/Spigot-1.10.jar + ${main.basedir}/lib/Spigot-1.10.jar \ No newline at end of file diff --git a/FightSystem_12/pom.xml b/FightSystem_12/pom.xml index c318966..0c0bcba 100644 --- a/FightSystem_12/pom.xml +++ b/FightSystem_12/pom.xml @@ -46,14 +46,14 @@ WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar + ${main.basedir}/lib/WorldEdit-1.12.jar steamwar Spigot 1.12 system - ${main.basedir}/../SteamwarLibs/Spigot-1.12.jar + ${main.basedir}/lib/Spigot-1.12.jar \ No newline at end of file diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml index 632d071..3d7c934 100644 --- a/FightSystem_14/pom.xml +++ b/FightSystem_14/pom.xml @@ -36,14 +36,14 @@ Spigot 1.14 system - ${main.basedir}/../SteamwarLibs/Spigot-1.14.jar + ${main.basedir}/lib/Spigot-1.14.jar steamwar WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.15.jar + ${main.basedir}/lib/WorldEdit-1.15.jar steamwar diff --git a/FightSystem_15/pom.xml b/FightSystem_15/pom.xml index 7677777..8858c54 100644 --- a/FightSystem_15/pom.xml +++ b/FightSystem_15/pom.xml @@ -36,14 +36,14 @@ Spigot 1.15 system - ${main.basedir}/../SteamwarLibs/Spigot-1.15.jar + ${main.basedir}/lib/Spigot-1.15.jar steamwar WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.15.jar + ${main.basedir}/lib/WorldEdit-1.15.jar steamwar diff --git a/FightSystem_8/pom.xml b/FightSystem_8/pom.xml index b10607e..2fabd6f 100644 --- a/FightSystem_8/pom.xml +++ b/FightSystem_8/pom.xml @@ -36,7 +36,7 @@ Spigot 1.8 system - ${main.basedir}/../SteamwarLibs/Spigot-1.8.jar + ${main.basedir}/lib/Spigot-1.8.jar steamwar @@ -48,7 +48,7 @@ WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar + ${main.basedir}/lib/WorldEdit-1.12.jar \ No newline at end of file diff --git a/FightSystem_9/pom.xml b/FightSystem_9/pom.xml index bdf448e..769e6c2 100644 --- a/FightSystem_9/pom.xml +++ b/FightSystem_9/pom.xml @@ -46,14 +46,14 @@ WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar + ${main.basedir}/lib/WorldEdit-1.12.jar steamwar Spigot 1.9 system - ${main.basedir}/../SteamwarLibs/Spigot-1.9.jar + ${main.basedir}/lib/Spigot-1.9.jar \ No newline at end of file diff --git a/FightSystem_API/pom.xml b/FightSystem_API/pom.xml index 02ae613..a2faacd 100644 --- a/FightSystem_API/pom.xml +++ b/FightSystem_API/pom.xml @@ -36,7 +36,7 @@ Spigot 1.12 system - ${main.basedir}/../SteamwarLibs/Spigot-1.12.jar + ${main.basedir}/lib/Spigot-1.12.jar \ No newline at end of file diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index a4a62e0..3083862 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -52,14 +52,14 @@ Spigot 1.15 system - ${main.basedir}/../SteamwarLibs/Spigot-1.15.jar + ${main.basedir}/lib/Spigot-1.15.jar steamwar WorldEdit 1.0 system - ${main.basedir}/../SteamwarLibs/WorldEdit-1.12.jar + ${main.basedir}/lib/WorldEdit-1.12.jar steamwar diff --git a/pom.xml b/pom.xml index 58520e6..455d1b6 100644 --- a/pom.xml +++ b/pom.xml @@ -46,14 +46,14 @@ SpigotCore 1.0 system - ${main.basedir}/../SteamwarLibs/SpigotCore.jar + ${main.basedir}/lib/SpigotCore.jar steamwar ProtocolLib 1.0 system - ${main.basedir}/../SteamwarLibs/ProtocolLib.jar + ${main.basedir}/lib/ProtocolLib.jar From bd224350a32d642ee24526d0caf6670a30457ae6 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:28:01 +0200 Subject: [PATCH 05/26] fixed poms --- .../src/de/steamwar/fightsystem/event/HellsBells.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index b0cbf19..ca0d4c1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -256,7 +256,8 @@ public class HellsBells { FIRST(40, 60, 5 * 60), SECOND(30, 40, 4 * 60), THIRD(20, 30, 3 * 60), - LAST(10, 20, -1); + FOURTH(10, 20, 2 * 60), + LAST(5, 10, -1); State(int minTime, int maxTime, int switchAfter) { @@ -279,6 +280,8 @@ public class HellsBells { case SECOND: return THIRD; case THIRD: + return FOURTH; + case FOURTH: case LAST: return LAST; default: From a7693ee2f3f09adae0dafbe97eb2c7daa6353e08 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 May 2021 23:37:01 +0200 Subject: [PATCH 06/26] Remove code duplication --- .../fightsystem/event/HellsBells.java | 116 ++++++------------ 1 file changed, 38 insertions(+), 78 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index ca0d4c1..64faefa 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -7,20 +7,43 @@ import de.steamwar.fightsystem.countdown.SWSound; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.winconditions.Winconditions; -import java.util.Arrays; -import java.util.List; -import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitRunnable; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; + public class HellsBells { public static final Random random = new Random(); + private enum Direction { + NORTH(0, 0, 1, true), + SOUTH(0, 0, -1, true), + EAST(1, 0, 0, false), + WEST(-1, 0, 0, false); + + static final List DIRECTIONS = Arrays.asList(values()); + + int dx; + int dy; + int dz; + boolean zLength; + + Direction(int dx, int dy, int dz, boolean zLength) { + this.dx = dx; + this.dy = dy; + this.dz = dz; + this.zLength = zLength; + } + } + public HellsBells() { new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { @@ -93,26 +116,18 @@ public class HellsBells { } public void drop() { - if (random.nextBoolean()) { - sideRun(random.nextBoolean()); - } else { - frontRun(random.nextBoolean()); - } - } + Direction direction = Direction.DIRECTIONS.get(random.nextInt(Direction.DIRECTIONS.size())); - - private void sideRun(boolean invert) { - int length = 10 + random.nextInt(zLength - 10); + AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(xLength, width); - int zOffset = getLengthStart(zLength, length); + int xOffset = getWidthStart(direction.zLength ? xLength : zLength, width); + int zOffset = getLengthStart(direction.zLength ? zLength : xLength, length.get()); int yOffset = getHeightStart(); - Point redStart; Point blueStart; - if (invert) { + if (direction == Direction.NORTH || direction == Direction.WEST) { redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); } else { @@ -120,79 +135,24 @@ public class HellsBells { blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); } - dropSideBombs(redStart, blueStart, width, new int[]{length}, invert); - } - - private void dropSideBombs(Point redStart, Point blueStart, int width, int[] x, boolean invert) { new BukkitRunnable() { @Override public void run() { for (int z = 0; z < width; z++) { - if (invert) { - world.spawnEntity(redStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + if (direction == Direction.NORTH || direction == Direction.WEST) { + world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.addAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); } else { - world.spawnEntity(redStart.addAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); } } - if (x[0] < 2) { - this.cancel(); - return; + if (length.decrementAndGet() == 0) { + cancel(); } - - x[0] -= 2; - } - }.runTaskTimer(FightSystem.getPlugin(), 0, 4L); - } - - - private void frontRun(boolean invert) { - int length = 10 + random.nextInt(xLength - 10); - int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(zLength, length); - int zOffset = getLengthStart(xLength, width); - int yOffset = getHeightStart(); - - Point redStart; - Point blueStart; - - if (invert) { - redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); - blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); - } else { - redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); - blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); - } - - dropFrontBombs(redStart, blueStart, width, new int[]{length}, invert); - } - - private void dropFrontBombs(Point redStart, Point blueStart, int width, int[] z, boolean invert) { - new BukkitRunnable() { - @Override - public void run() { - for (int x = 0; x < width; x++) { - if (invert) { - world.spawnEntity(redStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); - - world.spawnEntity(blueStart.addAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); - } else { - world.spawnEntity(redStart.addAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); - - world.spawnEntity(blueStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT); - } - } - - if (z[0] < 2) { - this.cancel(); - return; - } - - z[0] -= 2; } }.runTaskTimer(FightSystem.getPlugin(), 0, 4L); } From 7b0c10612888c36b0b593ecbeffc36bd1dfe7b50 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:46:00 +0200 Subject: [PATCH 07/26] rework for start-message --- .../de/steamwar/fightsystem/event/HellsBells.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 64faefa..e4b1767 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -97,19 +97,22 @@ public class HellsBells { public void startCountdown() { if (current != State.NONE) { long currentTime = System.currentTimeMillis(); - if (current != State.LAST && currentTime >= stateStart + (current.switchAfter * 1000L)) { - if (current != State.PRE) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller."); - } + + + if (current != State.LAST && current != State.PRE && currentTime >= stateStart + (current.switchAfter * 1000L)) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller."); current = current.getNext(); stateStart = currentTime; } int timer = current.minTime + random.nextInt(current.maxTime - current.minTime); + if (current == State.PRE) { Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); + current = current.getNext(); } + currentCountdown = new HellsBellsCountdown(timer, SWSound.BLOCK_NOTE_BASS, true); currentCountdown.enable(); } @@ -212,7 +215,7 @@ public class HellsBells { private enum State { NONE(0, 0, -1), - PRE(60, 80, 50), + PRE(60, 80, 0), FIRST(40, 60, 5 * 60), SECOND(30, 40, 4 * 60), THIRD(20, 30, 3 * 60), From bdbb4c510bd96c97062e184a5112f566e97dfb46 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 May 2021 23:47:10 +0200 Subject: [PATCH 08/26] Remove code duplication --- .../fightsystem/event/HellsBells.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index e4b1767..56816c0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -42,6 +42,21 @@ public class HellsBells { this.dz = dz; this.zLength = zLength; } + + Direction other() { + switch (this) { + case NORTH: + return EAST; + case SOUTH: + return WEST; + case EAST: + return NORTH; + case WEST: + return SOUTH; + default: + return this; + } + } } public HellsBells() { @@ -141,19 +156,20 @@ public class HellsBells { new BukkitRunnable() { @Override public void run() { - for (int z = 0; z < width; z++) { + for (int w = 0; w < width; w++) { if (direction == Direction.NORTH || direction == Direction.WEST) { - world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); } else { - world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); } } - if (length.decrementAndGet() == 0) { + length.decrementAndGet(); + if (length.decrementAndGet() <= 0) { cancel(); } } From 0ac33d0dd4513acbf859be17476485ae36500f38 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 14 May 2021 00:01:51 +0200 Subject: [PATCH 09/26] Fix HellsBells --- .../src/de/steamwar/fightsystem/event/HellsBells.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 56816c0..7a3268c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -138,8 +138,8 @@ public class HellsBells { AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(direction.zLength ? xLength : zLength, width); - int zOffset = getLengthStart(direction.zLength ? zLength : xLength, length.get()); + int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); + int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); int yOffset = getHeightStart(); Point redStart; From cabb09a6742bf74f6d83344916fe7988f4691766 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 14 May 2021 00:18:59 +0200 Subject: [PATCH 10/26] State switches are now dependent on amount od bombs dropped, rather than time --- .../fightsystem/event/HellsBells.java | 63 +++++++++---------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 7a3268c..c5c8409 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -88,8 +88,8 @@ public class HellsBells { private final World world = Bukkit.getWorlds().get(0); private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX(); private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ(); - private State current = State.PRE; - private long stateStart = 0; + private State current = State.NONE; + private int currentDrops = 0; private HellsBellsCountdown currentCountdown; private static final List startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.", "§cBomber im Anflug, ca. eine Minute bis zur Ankunft.", @@ -100,35 +100,31 @@ public class HellsBells { public void init() { - stateStart = System.currentTimeMillis(); + current = State.PRE; + currentDrops = 0; + currentCountdown = null; startCountdown(); } public void terminate() { current = State.NONE; - currentCountdown.disable(); + if (currentCountdown != null) { + currentCountdown.disable(); + } } public void startCountdown() { if (current != State.NONE) { - long currentTime = System.currentTimeMillis(); - - - if (current != State.LAST && current != State.PRE && currentTime >= stateStart + (current.switchAfter * 1000L)) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller."); - - current = current.getNext(); - stateStart = currentTime; - } - - int timer = current.minTime + random.nextInt(current.maxTime - current.minTime); - if (current == State.PRE) { Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); current = current.getNext(); + } else if (current != State.LAST && currentDrops >= current.SWITCH_AFTER) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller."); + currentDrops = 0; } - currentCountdown = new HellsBellsCountdown(timer, SWSound.BLOCK_NOTE_BASS, true); + currentDrops++; + currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true); currentCountdown.enable(); } } @@ -168,8 +164,7 @@ public class HellsBells { } } - length.decrementAndGet(); - if (length.decrementAndGet() <= 0) { + if (length.addAndGet(-2) <= 0) { cancel(); } } @@ -220,34 +215,34 @@ public class HellsBells { } public Location addAndToLocation(World world, int x, int y, int z) { - return new Location(world, this.x + x, this.y + y, this.z + z); + return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR } public Location subtractAndToLocation(World world, int x, int y, int z) { - return new Location(world, this.x - x, this.y - y, this.z - z); + return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR } } private enum State { - NONE(0, 0, -1), - PRE(60, 80, 0), - FIRST(40, 60, 5 * 60), - SECOND(30, 40, 4 * 60), - THIRD(20, 30, 3 * 60), - FOURTH(10, 20, 2 * 60), - LAST(5, 10, -1); + NONE(0, 0, 0), + PRE(60, 80, 1), + FIRST(40, 60, 5), + SECOND(30, 40, 6), + THIRD(20, 30, 6), + FOURTH(10, 20, 7), + LAST(5, 10, 0); State(int minTime, int maxTime, int switchAfter) { - this.minTime = minTime; - this.maxTime = maxTime; - this.switchAfter = switchAfter; + this.MIN_TIME = minTime; + this.MAX_TIME = maxTime; + this.SWITCH_AFTER = switchAfter; } - private final int minTime; - private final int maxTime; - private final int switchAfter; + private final int MIN_TIME; //NOSONAR + private final int MAX_TIME; //NOSONAR + private final int SWITCH_AFTER; //NOSONAR public State getNext() { From 2c981f29ce0f677289fb50c1b0ec5366a9fcd66b Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 14 May 2021 00:30:49 +0200 Subject: [PATCH 11/26] code cleanup --- .../src/de/steamwar/fightsystem/event/HellsBells.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index c5c8409..c74f225 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -29,7 +29,7 @@ public class HellsBells { EAST(1, 0, 0, false), WEST(-1, 0, 0, false); - static final List DIRECTIONS = Arrays.asList(values()); + static final Direction[] DIRECTIONS = values(); int dx; int dy; @@ -43,6 +43,10 @@ public class HellsBells { this.zLength = zLength; } + public static Direction getRandom() { + return Direction.DIRECTIONS[random.nextInt(Direction.DIRECTIONS.length)]; + } + Direction other() { switch (this) { case NORTH: @@ -130,7 +134,7 @@ public class HellsBells { } public void drop() { - Direction direction = Direction.DIRECTIONS.get(random.nextInt(Direction.DIRECTIONS.size())); + Direction direction = Direction.getRandom(); AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); int width = 5 + random.nextInt(5); From 25190098d6b2ef589b644f8116c6b5d402d1ab99 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 May 2021 19:58:31 +0200 Subject: [PATCH 12/26] code cleanup --- .../fightsystem/event/HellsBells.java | 286 +++++++++--------- 1 file changed, 137 insertions(+), 149 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index c74f225..02b5ccc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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.event; import de.steamwar.fightsystem.Config; @@ -17,6 +36,7 @@ import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; +import org.bukkit.scheduler.BukkitTask; public class HellsBells { @@ -66,59 +86,21 @@ public class HellsBells { public HellsBells() { new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { - private HellsBellsEvent event = null; + private final World world = Bukkit.getWorlds().get(0); + private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX(); + private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ(); + private State current = State.PRE; + private int currentDrops = 0; + private HellsBellsCountdown currentCountdown; + private BukkitTask currentDropping; + private final List startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.", + "§cBomber im Anflug, ca. eine Minute bis zur Ankunft.", + "§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.", + "§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.", + "§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.", + "§cBomber erschienen, Ankunft ca. eine Minute."); - @Override - public void enable() { - if (event != null) { - event.terminate(); - } - event = new HellsBellsEvent(); - event.init(); - } - - @Override - public void disable() { - if (event != null) { - event.terminate(); - } - event = null; - } - }.register(); - } - - private static class HellsBellsEvent { - - private final World world = Bukkit.getWorlds().get(0); - private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX(); - private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ(); - private State current = State.NONE; - private int currentDrops = 0; - private HellsBellsCountdown currentCountdown; - private static final List startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.", - "§cBomber im Anflug, ca. eine Minute bis zur Ankunft.", - "§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.", - "§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.", - "§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.", - "§cBomber erschienen, Ankunft ca. eine Minute."); - - - public void init() { - current = State.PRE; - currentDrops = 0; - currentCountdown = null; - startCountdown(); - } - - public void terminate() { - current = State.NONE; - if (currentCountdown != null) { - currentCountdown.disable(); - } - } - - public void startCountdown() { - if (current != State.NONE) { + public void startCountdown() { if (current == State.PRE) { Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); current = current.getNext(); @@ -131,31 +113,28 @@ public class HellsBells { currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true); currentCountdown.enable(); } - } - public void drop() { - Direction direction = Direction.getRandom(); + public void drop() { + Direction direction = Direction.getRandom(); - AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); - int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); - int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); - int yOffset = getHeightStart(); + AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); + int width = 5 + random.nextInt(5); + int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); + int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); + int yOffset = getHeightStart(); - Point redStart; - Point blueStart; + Point redStart; + Point blueStart; - if (direction == Direction.NORTH || direction == Direction.WEST) { - redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); - blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); - } else { - redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); - blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); - } + if (direction == Direction.NORTH || direction == Direction.WEST) { + redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); + blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); + } else { + redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); + } - new BukkitRunnable() { - @Override - public void run() { + currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { for (int w = 0; w < width; w++) { if (direction == Direction.NORTH || direction == Direction.WEST) { world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); @@ -167,104 +146,113 @@ public class HellsBells { world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); } } - if (length.addAndGet(-2) <= 0) { - cancel(); + currentDropping.cancel(); } + }, 0L, 4L); + } + + private int getLengthStart(int regionSize, int length) { + return random.nextInt(regionSize - length); + } + + private int getWidthStart(int regionSize, int length) { + return random.nextInt(regionSize - length); + } + + private int getHeightStart() { + return 5 + random.nextInt(15); + } + + class HellsBellsCountdown extends Countdown { + + public HellsBellsCountdown(int time, SWSound sound, boolean level) { + super(time, sound, level); } - }.runTaskTimer(FightSystem.getPlugin(), 0, 4L); - } - private int getLengthStart(int regionSize, int length) { - return random.nextInt(regionSize - length); - } + @Override + public String countdownCounting() { + return "bis die Bomben fallen"; + } - private int getWidthStart(int regionSize, int length) { - return random.nextInt(regionSize - length); - } + @Override + public void countdownFinished() { + drop(); - private int getHeightStart() { - return 5 + random.nextInt(15); - } - - private class HellsBellsCountdown extends Countdown { - - public HellsBellsCountdown(int time, SWSound sound, boolean level) { - super(time, sound, level); + startCountdown(); + } } @Override - public String countdownCounting() { - return "bis die Bomben fallen"; - } - - @Override - public void countdownFinished() { - drop(); - + public void enable() { startCountdown(); } + + @Override + public void disable() { + currentCountdown.disable(); + } + }.register(); + } + + private static class Point { + + private final int x; + private final int y; + private final int z; + + public Point(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; } - private static class Point { - - private final int x; - private final int y; - private final int z; - - public Point(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Location addAndToLocation(World world, int x, int y, int z) { - return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR - } - - public Location subtractAndToLocation(World world, int x, int y, int z) { - return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR - } + public Location addAndToLocation(World world, int x, int y, int z) { + return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR } - private enum State { + public Location subtractAndToLocation(World world, int x, int y, int z) { + return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR + } + } - NONE(0, 0, 0), - PRE(60, 80, 1), - FIRST(40, 60, 5), - SECOND(30, 40, 6), - THIRD(20, 30, 6), - FOURTH(10, 20, 7), - LAST(5, 10, 0); + private enum State { + + NONE(0, 0, 0), + PRE(60, 80, 1), + FIRST(40, 60, 5), + SECOND(30, 40, 6), + THIRD(20, 30, 6), + FOURTH(10, 20, 7), + LAST(5, 10, 0); - State(int minTime, int maxTime, int switchAfter) { - this.MIN_TIME = minTime; - this.MAX_TIME = maxTime; - this.SWITCH_AFTER = switchAfter; - } + State(int minTime, int maxTime, int switchAfter) { + this.MIN_TIME = minTime; + this.MAX_TIME = maxTime; + this.SWITCH_AFTER = switchAfter; + } - private final int MIN_TIME; //NOSONAR - private final int MAX_TIME; //NOSONAR - private final int SWITCH_AFTER; //NOSONAR + private final int MIN_TIME; //NOSONAR + private final int MAX_TIME; //NOSONAR + private final int SWITCH_AFTER; //NOSONAR - public State getNext() { - switch (this) { - case PRE: - return FIRST; - case FIRST: - return SECOND; - case SECOND: - return THIRD; - case THIRD: - return FOURTH; - case FOURTH: - case LAST: - return LAST; - default: - return NONE; - } + public State getNext() { + switch (this) { + case PRE: + return FIRST; + case FIRST: + return SECOND; + case SECOND: + return THIRD; + case THIRD: + return FOURTH; + case FOURTH: + case LAST: + return LAST; + default: + return NONE; } } } From 9d21214204174a463024120f5bed1cc11d11efea Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 18 May 2021 20:03:44 +0200 Subject: [PATCH 13/26] Fix HellsBells direction code --- .../fightsystem/event/HellsBells.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 02b5ccc..353c2b4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -30,13 +30,12 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.EntityType; -import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; -import org.bukkit.scheduler.BukkitTask; public class HellsBells { @@ -44,23 +43,21 @@ public class HellsBells { public static final Random random = new Random(); private enum Direction { - NORTH(0, 0, 1, true), - SOUTH(0, 0, -1, true), - EAST(1, 0, 0, false), - WEST(-1, 0, 0, false); + NORTH(0, 0, 1), + SOUTH(0, 0, -1), + EAST(1, 0, 0), + WEST(-1, 0, 0); static final Direction[] DIRECTIONS = values(); int dx; int dy; int dz; - boolean zLength; - Direction(int dx, int dy, int dz, boolean zLength) { + Direction(int dx, int dy, int dz) { this.dx = dx; this.dy = dy; this.dz = dz; - this.zLength = zLength; } public static Direction getRandom() { @@ -81,6 +78,18 @@ public class HellsBells { return this; } } + + public int getLength(int length1, int length2) { + return isNorthOrSouth() ? length1 : length2; + } + + public boolean isNorthOrSouth() { + return this == NORTH || this == SOUTH; + } + + public boolean isNorthOrWest() { + return this == NORTH || this == WEST; + } } public HellsBells() { @@ -117,16 +126,16 @@ public class HellsBells { public void drop() { Direction direction = Direction.getRandom(); - AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); + AtomicInteger length = new AtomicInteger(10 + random.nextInt(direction.getLength(zLength, xLength) - 10)); int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); - int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); + int xOffset = getWidthStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width)); + int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get())); int yOffset = getHeightStart(); Point redStart; Point blueStart; - if (direction == Direction.NORTH || direction == Direction.WEST) { + if (direction.isNorthOrWest()) { redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); } else { @@ -136,7 +145,7 @@ public class HellsBells { currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { for (int w = 0; w < width; w++) { - if (direction == Direction.NORTH || direction == Direction.WEST) { + if (direction.isNorthOrWest()) { world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); From e181c42b12fc9a0f51c7b6abd223e634503c023a Mon Sep 17 00:00:00 2001 From: Zeanon Date: Wed, 19 May 2021 10:19:31 +0200 Subject: [PATCH 14/26] no State.NONE --- .../src/de/steamwar/fightsystem/event/HellsBells.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 353c2b4..91415fa 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -119,7 +119,7 @@ public class HellsBells { } currentDrops++; - currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true); + currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME)); currentCountdown.enable(); } @@ -175,8 +175,8 @@ public class HellsBells { class HellsBellsCountdown extends Countdown { - public HellsBellsCountdown(int time, SWSound sound, boolean level) { - super(time, sound, level); + public HellsBellsCountdown(int time) { + super(time, SWSound.BLOCK_NOTE_BASS, true); } @Override @@ -227,7 +227,6 @@ public class HellsBells { private enum State { - NONE(0, 0, 0), PRE(60, 80, 1), FIRST(40, 60, 5), SECOND(30, 40, 6), @@ -261,7 +260,7 @@ public class HellsBells { case LAST: return LAST; default: - return NONE; + return PRE; } } } From 886fbbe535ec234800e006dce4702da2f9b10d9e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 23 May 2021 17:07:43 +0200 Subject: [PATCH 15/26] Update HellsBells --- .../fightsystem/event/HellsBells.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 91415fa..2a1ef1d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -132,28 +132,14 @@ public class HellsBells { int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get())); int yOffset = getHeightStart(); - Point redStart; - Point blueStart; - - if (direction.isNorthOrWest()) { - redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); - blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); - } else { - redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); - blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); - } + Point redStart = direction.isNorthOrWest() ? new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset) : new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + Point blueStart = direction.isNorthOrWest() ? new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset) : new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { + int factor = direction.isNorthOrWest() ? 1 : -1; for (int w = 0; w < width; w++) { - if (direction.isNorthOrWest()) { - world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - - world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - } else { - world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - - world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - } + world.spawnEntity(redStart.subtractAndToLocation(world, (direction.dx * length.get() + w * direction.other().dx) * factor, 0, (direction.dz * length.get() + w * direction.other().dz) * factor), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.addAndToLocation(world, (direction.dx * length.get() + w * direction.other().dx) * factor, 0, (direction.dz * length.get() + w * direction.other().dz) * factor), EntityType.PRIMED_TNT); } if (length.addAndGet(-2) <= 0) { currentDropping.cancel(); From 5945f3c14830125fd5e3274b006cb87b1c614335 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 08:36:25 +0200 Subject: [PATCH 16/26] Fix prepare recoloring Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/FightSchematic.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index fb63943..4e5790d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -118,7 +118,7 @@ public class FightSchematic extends StateDependent { private void paste(){ FreezeWorld freezer = new FreezeWorld(); - DyeColor c = ColorConverter.chat2dye(team.getColor()); + DyeColor c = ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK; try { VersionedRunnable.call(new VersionedRunnable(() -> { @@ -126,25 +126,25 @@ public class FightSchematic extends StateDependent { FightTeam_8.replaceTeamColor(clipboard, c); FightTeam_8.pasteSchematic(clipboard, region, rotate); } catch (NoClipboardException | WorldEditException ex) { - throw new SecurityException("Error pasting arena in schematic", ex); + throw new SecurityException("Error pasting schematic", ex); } }, 8), new VersionedRunnable(() -> { try { FightTeam_12.replaceTeamColor(clipboard, c); FightTeam_8.pasteSchematic(clipboard, region, rotate); } catch (NoClipboardException | WorldEditException ex) { - throw new SecurityException("Error pasting arena in schematic", ex); + throw new SecurityException("Error pasting schematic", ex); } }, 12), new VersionedRunnable(() -> { try { FightTeam_14.replaceTeamColor(clipboard, c); FightTeam_14.pasteSchematic(clipboard, region, rotate); } catch (NoClipboardException | WorldEditException ex) { - throw new SecurityException("Error pasting arena in schematic", ex); + throw new SecurityException("Error pasting schematic", ex); } }, 14)); } catch (SecurityException securityException) { - team.broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); + FightSystem.shutdown(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); throw securityException; } From 27d853af19d9847e9b04ed3a8fc595841b4e8cb0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 08:51:08 +0200 Subject: [PATCH 17/26] Fix ranked player does not join arena Signed-off-by: Lixfel --- .../steamwar/fightsystem/fight/FightTeam.java | 4 ++++ .../fightsystem/utils/FightStatistics.java | 20 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index bc0dfc7..f2a477f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -94,6 +94,10 @@ public class FightTeam implements IFightTeam{ team.setAllowFriendlyFire(false); } + public UUID getDesignatedLeader(){ + return designatedLeader; + } + public Region getSchemRegion() { return schemRegion; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index ade520e..4e7928f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -50,12 +50,8 @@ public class FightStatistics { public static void saveStats(FightTeam winner, String windescription){ String gameMode = Config.SchematicType.toDB(); - int blueLeader = 0; - int redLeader = 0; - if(Fight.getBlueTeam().getLeader() != null) - blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()).getId(); - if(Fight.getRedTeam().getLeader() != null) - redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()).getId(); + int blueLeader = getLeader(Fight.getBlueTeam()); + int redLeader = getLeader(Fight.getRedTeam()); int win = 0; double blueResult; @@ -109,11 +105,19 @@ public class FightStatistics { int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)); Elo.setElo(blueLeader, gameMode, newBlueElo); Elo.setElo(redLeader, gameMode, newRedElo); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + Fight.getBlueTeam().getLeader().getPlayer().getName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + Fight.getRedTeam().getLeader().getPlayer().getName() + "§8: §7" + redElo + "§8»§e" + newRedElo); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + SteamwarUser.get(blueLeader).getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + SteamwarUser.get(redLeader).getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo); } } + private static int getLeader(FightTeam team){ + if(team.getLeader() != null) + return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId(); + else if(team.getDesignatedLeader() != null) + return SteamwarUser.get(team.getDesignatedLeader()).getId(); + return 0; + } + private static void savePlayerStats(FightPlayer fp, int fightId){ SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId()); de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); From 9cef84f7b3f38ce86cfd557084d69d8ca5a68fe6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 08:54:25 +0200 Subject: [PATCH 18/26] Fix spectators below (M)WGs Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/ArenaBorder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java index d0ceee8..5c39bd4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -51,8 +51,11 @@ public class ArenaBorder implements Listener { } FightTeam team = Fight.getPlayerTeam(player); - if(team == null || player.getGameMode() == GameMode.SPECTATOR) + if(team == null || player.getGameMode() == GameMode.SPECTATOR){ + if(to.getY() <= Config.ArenaRegion.getMinY()) + reset(event); return; + } if(to.getY() <= Config.ArenaRegion.getMinY()) { if(FightState.infight()) From fa8f6c4265c7c20d7f742a56d124b7866eefd817 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 08:57:34 +0200 Subject: [PATCH 19/26] Remove debug output Signed-off-by: Lixfel --- FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index e31673f..a4f9953 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -19,12 +19,10 @@ package de.steamwar.fightsystem.utils; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import java.util.function.ObjIntConsumer; -import java.util.logging.Level; public class Region { @@ -41,7 +39,6 @@ public class Region { } public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { - Bukkit.getLogger().log(Level.INFO, minX + " " + minY + " " + minZ + " " + sizeX + " " + sizeY + " " + sizeZ); this.minX = minX; this.minY = minY; this.minZ = minZ; From 14986aedd8e0732a6a82c4fb700341ad02693a7d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 09:06:00 +0200 Subject: [PATCH 20/26] Dont db-log players moving into team area anymore Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/TeamArea.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java index b397645..db88f9f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -82,7 +82,7 @@ public class TeamArea implements Listener { private void checkInInnerArea(Player player, Location to, FightTeam team){ if(team.getSchemRegion().playerInRegion(to) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension player.kickPlayer(null); - Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen."); + Bukkit.getLogger().log(Level.INFO, player.getName() + " ist in einen Teambereich eingedrungen."); } } From e408aac608a7745437a3dabd9815b6150804bfd8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 09:31:58 +0200 Subject: [PATCH 21/26] Make it harder to accidentialy move/equip items in the HotbarGUI Signed-off-by: Lixfel --- .../listener/DenyWorldInteraction_10.java | 32 +++++++++++++++++++ .../listener/DenyWorldInteraction.java | 10 ++++-- .../fightsystem/listener/HotbarGUI.java | 4 +-- .../listener/PersonalKitCreator.java | 4 +-- 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java diff --git a/FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java b/FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java new file mode 100644 index 0000000..5a805c9 --- /dev/null +++ b/FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 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.listener; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; + +public class DenyWorldInteraction_10 implements Listener { + + @EventHandler + public void onSwapItems(PlayerSwapHandItemsEvent event) { + event.setCancelled(true); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java index ca0d01c..78b5d50 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; @@ -39,6 +40,11 @@ public class DenyWorldInteraction implements Listener { public DenyWorldInteraction() { new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this); new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this); + if(Core.getVersion() > 9){ + Listener listener = new DenyWorldInteraction_10(); + new StateDependentListener(ArenaMode.Test, FightState.PreRunning, listener); + new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, listener); + } } @EventHandler @@ -68,13 +74,13 @@ public class DenyWorldInteraction implements Listener { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if(PersonalKitCreator.notInKitCreator(event.getWhoClicked())) + if(!PersonalKitCreator.inKitCreator(event.getWhoClicked())) event.setCancelled(true); } @EventHandler public void onInventoryDrag(InventoryDragEvent event) { - if(PersonalKitCreator.notInKitCreator(event.getWhoClicked())) + if(!PersonalKitCreator.inKitCreator(event.getWhoClicked())) event.setCancelled(true); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java index 2827c50..6b52db4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java @@ -42,9 +42,10 @@ public class HotbarGUI implements Listener { public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if(!PersonalKitCreator.notInKitCreator(player)) + if(PersonalKitCreator.inKitCreator(player)) return; + event.setCancelled(true); if(event.getItem() == null) return; @@ -52,7 +53,6 @@ public class HotbarGUI implements Listener { if(fightTeam == null) return; - event.setCancelled(true); ItemMeta itemMeta = event.getItem().getItemMeta(); String displayName = itemMeta.getDisplayName(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index 3007ee1..297834f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -61,8 +61,8 @@ public class PersonalKitCreator implements Listener { BasicListener.toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!")); } - public static boolean notInKitCreator(HumanEntity player){ - return !openKitCreators.containsKey(player); + public static boolean inKitCreator(HumanEntity player){ + return openKitCreators.containsKey(player); } public static void closeIfInKitCreator(HumanEntity player){ From 3b2857d60d806b59007e7710ccbb658285054779 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 09:47:32 +0200 Subject: [PATCH 22/26] Set to preschemstate Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightSchematic.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 4e5790d..172a8b7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -144,7 +144,8 @@ public class FightSchematic extends StateDependent { } }, 14)); } catch (SecurityException securityException) { - FightSystem.shutdown(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); throw securityException; } From 394ccc251e5e54d303d81ecd905fced1695c300c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 15:24:07 +0200 Subject: [PATCH 23/26] Hotfix hotbargui Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/HotbarGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java index 6b52db4..94ff28a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java @@ -45,10 +45,10 @@ public class HotbarGUI implements Listener { if(PersonalKitCreator.inKitCreator(player)) return; - event.setCancelled(true); if(event.getItem() == null) return; + event.setCancelled(true); FightTeam fightTeam = Fight.getPlayerTeam(player); if(fightTeam == null) return; From 03f815ecfac49db1fa4431ed2cb3191bfb29b55a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 5 Jun 2021 13:33:34 +0200 Subject: [PATCH 24/26] Fix ArrowStopper.java --- .../src/de/steamwar/fightsystem/listener/ArrowStopper.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 696d0e7..35d8af1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -21,7 +21,6 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -29,17 +28,15 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; -import org.bukkit.event.Listener; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -public class ArrowStopper implements Listener { +public class ArrowStopper { private static final Vector NULL_VECTOR = new Vector(0, 0, 0); private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; public ArrowStopper() { - new StateDependentListener(Config.TechhiderActive, FightState.Running, this); new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } @@ -85,7 +82,7 @@ public class ArrowStopper implements Listener { } private boolean checkBlock(Block block) { - return Config.HiddenBlocks.contains(block.getType().name()); + return Config.HiddenBlocks.contains(block.getType().name().toLowerCase()); } private boolean invalidEntity(Arrow entity) { From 6db428f13464d36f0d858a0d68a4d02a15e86260 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Wed, 16 Jun 2021 15:39:37 +0200 Subject: [PATCH 25/26] Fixed stuff from PR --- .../fightsystem/event/HellsBells.java | 266 +++++++++--------- 1 file changed, 139 insertions(+), 127 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 2a1ef1d..e26ede9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -42,142 +42,90 @@ public class HellsBells { public static final Random random = new Random(); - private enum Direction { - NORTH(0, 0, 1), - SOUTH(0, 0, -1), - EAST(1, 0, 0), - WEST(-1, 0, 0); + private final World world = Bukkit.getWorlds().get(0); + private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX(); + private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ(); + private State current = State.PRE; + private int currentDrops = 0; + private HellsBellsCountdown currentCountdown; + private BukkitTask currentDropping; + private final List startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.", + "§cBomber im Anflug, ca. eine Minute bis zur Ankunft.", + "§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.", + "§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.", + "§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.", + "§cBomber erschienen, Ankunft ca. eine Minute."); + private final List stateSwapMessages = Arrays.asList("§aDie Bomben fallen nun schneller.", + "§aMehr Bomber im Anflug.", + "§aZusätzliche Bomber gesichtet.", + "§aDas Bombardement scheint sich zu erhöhen."); - static final Direction[] DIRECTIONS = values(); - - int dx; - int dy; - int dz; - - Direction(int dx, int dy, int dz) { - this.dx = dx; - this.dy = dy; - this.dz = dz; + public void startCountdown() { + if (current == State.PRE) { + Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); + current = current.getNext(); + } else if (current != State.LAST && currentDrops >= current.SWITCH_AFTER) { + Bukkit.broadcastMessage(FightSystem.PREFIX + (stateSwapMessages.get(random.nextInt(stateSwapMessages.size())))); + currentDrops = 0; } - public static Direction getRandom() { - return Direction.DIRECTIONS[random.nextInt(Direction.DIRECTIONS.length)]; + currentDrops++; + currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME)); + currentCountdown.enable(); + } + + public void drop() { + Direction direction = Direction.getRandom(); + + AtomicInteger length = new AtomicInteger(10 + random.nextInt(direction.getLength(zLength, xLength) - 10)); + int width = 5 + random.nextInt(5); + int xOffset = getWidthStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width)); + int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get())); + int yOffset = getHeightStart(); + + Point redStart; + Point blueStart; + + if (direction.isNorthOrWest()) { + redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); + blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); + } else { + redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); + blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); } - Direction other() { - switch (this) { - case NORTH: - return EAST; - case SOUTH: - return WEST; - case EAST: - return NORTH; - case WEST: - return SOUTH; - default: - return this; + currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { + for (int w = 0; w < width; w++) { + if (direction.isNorthOrWest()) { + world.spawnEntity(redStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT); + + world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); + } else { + world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); + + world.spawnEntity(blueStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT); + } } - } + if (length.addAndGet(-2) <= 0) { + currentDropping.cancel(); + } + }, 0L, 4L); + } - public int getLength(int length1, int length2) { - return isNorthOrSouth() ? length1 : length2; - } + private int getLengthStart(int regionSize, int length) { + return random.nextInt(regionSize - length); + } - public boolean isNorthOrSouth() { - return this == NORTH || this == SOUTH; - } + private int getWidthStart(int regionSize, int length) { + return random.nextInt(regionSize - length); + } - public boolean isNorthOrWest() { - return this == NORTH || this == WEST; - } + private int getHeightStart() { + return 5 + random.nextInt(15); } public HellsBells() { new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { - - private final World world = Bukkit.getWorlds().get(0); - private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX(); - private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ(); - private State current = State.PRE; - private int currentDrops = 0; - private HellsBellsCountdown currentCountdown; - private BukkitTask currentDropping; - private final List startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.", - "§cBomber im Anflug, ca. eine Minute bis zur Ankunft.", - "§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.", - "§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.", - "§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.", - "§cBomber erschienen, Ankunft ca. eine Minute."); - - public void startCountdown() { - if (current == State.PRE) { - Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); - current = current.getNext(); - } else if (current != State.LAST && currentDrops >= current.SWITCH_AFTER) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller."); - currentDrops = 0; - } - - currentDrops++; - currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME)); - currentCountdown.enable(); - } - - public void drop() { - Direction direction = Direction.getRandom(); - - AtomicInteger length = new AtomicInteger(10 + random.nextInt(direction.getLength(zLength, xLength) - 10)); - int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width)); - int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get())); - int yOffset = getHeightStart(); - - Point redStart = direction.isNorthOrWest() ? new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset) : new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); - Point blueStart = direction.isNorthOrWest() ? new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset) : new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); - - currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { - int factor = direction.isNorthOrWest() ? 1 : -1; - for (int w = 0; w < width; w++) { - world.spawnEntity(redStart.subtractAndToLocation(world, (direction.dx * length.get() + w * direction.other().dx) * factor, 0, (direction.dz * length.get() + w * direction.other().dz) * factor), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.addAndToLocation(world, (direction.dx * length.get() + w * direction.other().dx) * factor, 0, (direction.dz * length.get() + w * direction.other().dz) * factor), EntityType.PRIMED_TNT); - } - if (length.addAndGet(-2) <= 0) { - currentDropping.cancel(); - } - }, 0L, 4L); - } - - private int getLengthStart(int regionSize, int length) { - return random.nextInt(regionSize - length); - } - - private int getWidthStart(int regionSize, int length) { - return random.nextInt(regionSize - length); - } - - private int getHeightStart() { - return 5 + random.nextInt(15); - } - - class HellsBellsCountdown extends Countdown { - - public HellsBellsCountdown(int time) { - super(time, SWSound.BLOCK_NOTE_BASS, true); - } - - @Override - public String countdownCounting() { - return "bis die Bomben fallen"; - } - - @Override - public void countdownFinished() { - drop(); - - startCountdown(); - } - } - @Override public void enable() { startCountdown(); @@ -190,6 +138,25 @@ public class HellsBells { }.register(); } + class HellsBellsCountdown extends Countdown { + + public HellsBellsCountdown(int time) { + super(time, SWSound.BLOCK_NOTE_BASS, true); + } + + @Override + public String countdownCounting() { + return "bis die Bomben fallen"; + } + + @Override + public void countdownFinished() { + drop(); + + startCountdown(); + } + } + private static class Point { private final int x; @@ -205,10 +172,6 @@ public class HellsBells { public Location addAndToLocation(World world, int x, int y, int z) { return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR } - - public Location subtractAndToLocation(World world, int x, int y, int z) { - return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR - } } private enum State { @@ -250,4 +213,53 @@ public class HellsBells { } } } + + private enum Direction { + NORTH(0, 0, 1), + SOUTH(0, 0, -1), + EAST(1, 0, 0), + WEST(-1, 0, 0); + + + int dx; + int dy; + int dz; + + Direction(int dx, int dy, int dz) { + this.dx = dx; + this.dy = dy; + this.dz = dz; + } + + public static Direction getRandom() { + return Direction.values()[random.nextInt(Direction.values().length)]; + } + + Direction other() { + switch (this) { + case NORTH: + return EAST; + case SOUTH: + return WEST; + case EAST: + return NORTH; + case WEST: + return SOUTH; + default: + return this; + } + } + + public int getLength(int length1, int length2) { + return isNorthOrSouth() ? length1 : length2; + } + + public boolean isNorthOrSouth() { + return this == NORTH || this == SOUTH; + } + + public boolean isNorthOrWest() { + return this == NORTH || this == WEST; + } + } } \ No newline at end of file From ad0c811082a53f214d0e78ab1814d25edae22f60 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 21 Jun 2021 19:55:37 +0200 Subject: [PATCH 26/26] Countdown is now private static --- .../src/de/steamwar/fightsystem/event/HellsBells.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index e26ede9..27912ae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -138,7 +138,7 @@ public class HellsBells { }.register(); } - class HellsBellsCountdown extends Countdown { + private static class HellsBellsCountdown extends Countdown { public HellsBellsCountdown(int time) { super(time, SWSound.BLOCK_NOTE_BASS, true);