From bf1368a34e4b8646b91cff0e44ad23995a84e7c5 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 6 May 2021 20:15:51 +0200 Subject: [PATCH 01/17] . --- 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 -- 2.39.5 From 1ede1c1101ae37451638dd444b2fceb62e5eb1de Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 19:19:03 +0200 Subject: [PATCH 02/17] 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 -- 2.39.5 From 309ba84865212ee3c541d3128e209354d30c0945 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:11:55 +0200 Subject: [PATCH 03/17] 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 { -- 2.39.5 From bb6dbff20b056fc2d6ccd3f63ce3715b87a5d10c Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:18:44 +0200 Subject: [PATCH 04/17] 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 -- 2.39.5 From bd224350a32d642ee24526d0caf6670a30457ae6 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:28:01 +0200 Subject: [PATCH 05/17] 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: -- 2.39.5 From a7693ee2f3f09adae0dafbe97eb2c7daa6353e08 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 May 2021 23:37:01 +0200 Subject: [PATCH 06/17] 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); } -- 2.39.5 From 7b0c10612888c36b0b593ecbeffc36bd1dfe7b50 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 13 May 2021 23:46:00 +0200 Subject: [PATCH 07/17] 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), -- 2.39.5 From bdbb4c510bd96c97062e184a5112f566e97dfb46 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 May 2021 23:47:10 +0200 Subject: [PATCH 08/17] 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(); } } -- 2.39.5 From 0ac33d0dd4513acbf859be17476485ae36500f38 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 14 May 2021 00:01:51 +0200 Subject: [PATCH 09/17] 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; -- 2.39.5 From cabb09a6742bf74f6d83344916fe7988f4691766 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 14 May 2021 00:18:59 +0200 Subject: [PATCH 10/17] 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() { -- 2.39.5 From 2c981f29ce0f677289fb50c1b0ec5366a9fcd66b Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 14 May 2021 00:30:49 +0200 Subject: [PATCH 11/17] 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); -- 2.39.5 From 25190098d6b2ef589b644f8116c6b5d402d1ab99 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 May 2021 19:58:31 +0200 Subject: [PATCH 12/17] 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; } } } -- 2.39.5 From 9d21214204174a463024120f5bed1cc11d11efea Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 18 May 2021 20:03:44 +0200 Subject: [PATCH 13/17] 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); -- 2.39.5 From e181c42b12fc9a0f51c7b6abd223e634503c023a Mon Sep 17 00:00:00 2001 From: Zeanon Date: Wed, 19 May 2021 10:19:31 +0200 Subject: [PATCH 14/17] 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; } } } -- 2.39.5 From 886fbbe535ec234800e006dce4702da2f9b10d9e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 23 May 2021 17:07:43 +0200 Subject: [PATCH 15/17] 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(); -- 2.39.5 From 6db428f13464d36f0d858a0d68a4d02a15e86260 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Wed, 16 Jun 2021 15:39:37 +0200 Subject: [PATCH 16/17] 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 -- 2.39.5 From ad0c811082a53f214d0e78ab1814d25edae22f60 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 21 Jun 2021 19:55:37 +0200 Subject: [PATCH 17/17] 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); -- 2.39.5