diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java index abd0ba1..099c96f 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java @@ -31,12 +31,4 @@ public class TNTSimulator_12 { return Material.CONCRETE; } - public static Material repeater() { - return Material.DIODE; - } - - public static Material comparator() { - return Material.REDSTONE_COMPARATOR; - } - } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java index 7042a86..8fea70d 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java @@ -32,12 +32,4 @@ public class TNTSimulator_15 { return Material.RED_CONCRETE; } - public static Material repeater() { - return Material.REPEATER; - } - - public static Material comparator() { - return Material.COMPARATOR; - } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 8a9f47d..458504e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -33,9 +33,10 @@ import org.bukkit.entity.Player; public class CommandSimulator implements CommandExecutor { private void help(Player player) { - player.sendMessage("§8/§esimulator §8- §7Öffnet das Simulations GUI"); + player.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI"); player.sendMessage("§8/§esimulator start §8- §7Startet die Simulation"); - player.sendMessage("§8/§esimulator wand §8- §7Legt den Simulatorstab ins Inventar"); + player.sendMessage("§8/§esimulator wand §8- §7Legt dir den Simulatorstab ins Inventar"); + player.sendMessage("§8/§esimulator delete §8- §7Lösche alle TNT"); } private boolean permissionCheck(Player player) { @@ -68,6 +69,8 @@ public class CommandSimulator implements CommandExecutor { case "start": TNTSimulator.get(player).start(); break; + case "delete": + TNTSimulator.get(player).delete(); default: help(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index dc02da4..4240621 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -271,9 +271,9 @@ public class TNTSimulator { private static Material comparatorOrNot(boolean b) { if (b) { - return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::comparator, 8), new VersionedCallable<>(TNTSimulator_15::comparator, 14)); + return SWItem.getMaterial("REDSTONE_COMPARATOR"); } else { - return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::repeater, 8), new VersionedCallable<>(TNTSimulator_15::repeater, 14)); + return SWItem.getMaterial("DIODE"); } } @@ -319,25 +319,32 @@ public class TNTSimulator { return (int)(d * 10000) * 0.0001; } + public void delete() { + TNT_SPAWNS.clear(); + } + public void start() { Map> first = new HashMap<>(); Map> second = new HashMap<>(); - AtomicInteger lastTick = new AtomicInteger(0); - TNT_SPAWNS.forEach(tntSpawn -> { + int lastTick = 0; + + for (TNTSpawn tntSpawn : TNT_SPAWNS) { Map> list = tntSpawn.isComparator() ? second : first; for (int i = 0; i < tntSpawn.getCount(); i++) { list.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList<>()).add(tntSpawn); } - if (lastTick.get() < tntSpawn.getTickOffset()) { - lastTick.set(tntSpawn.getTickOffset()); + if (lastTick < tntSpawn.getTickOffset()) { + lastTick = tntSpawn.getTickOffset(); } - }); + } + int finalLastTick = lastTick; + AtomicInteger currentTick = new AtomicInteger(0); Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), bukkitTask -> { int tick = currentTick.get(); spawnRandomList(first.getOrDefault(tick, EMPTY)); spawnRandomList(second.getOrDefault(tick, EMPTY)); - if (tick > lastTick.get()) bukkitTask.cancel(); + if (tick > finalLastTick) bukkitTask.cancel(); currentTick.incrementAndGet(); }, 1, 1); }