diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index 25205d00..f0e1b996 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -45,12 +45,13 @@ import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.function.BiFunction; @Linked public class TNTSimulatorListener implements Listener { - private Map currentSimulator = new HashMap<>(); + private Map> currentSimulator = new HashMap<>(); private boolean permissionCheck(Player player) { if (!Permission.hasPermission(player, Permission.WORLD)) { @@ -88,10 +89,10 @@ public class TNTSimulatorListener implements Listener { { BiFunction positionSetter = (player, o) -> { if (player.getGameMode() == GameMode.SPECTATOR) return o; - TNTSimulator tntSimulator = currentSimulator.get(player); + Pair tntSimulator = currentSimulator.get(player); if (tntSimulator == null) return o; - if (!tntSimulator.hasPreview(player)) return o; - if (!tntSimulator.getPreviewRecord().isAir(x.get(o), y.get(o), z.get(o))) return o; + if (!tntSimulator.getKey().hasPreview(player)) return o; + if (!tntSimulator.getKey().getPreviewRecord().isAir(x.get(o), y.get(o), z.get(o))) return o; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { PlayerMovementWrapper.impl.setPosition(player, o); }, 0L); @@ -103,15 +104,27 @@ public class TNTSimulatorListener implements Listener { } private void hideShow(Player player, Pair simulatorPair) { + Pair tntSimulatorPair = currentSimulator.get(player); + TNTSimulator tntSimulator = tntSimulatorPair == null ? null : tntSimulatorPair.getKey(); TNTSimulator simulator = simulatorPair.getKey(); - TNTSimulator tntSimulator = currentSimulator.remove(player); - if (tntSimulator == simulator) return; - if (tntSimulator != null) tntSimulator.hide(player); + + if (Objects.equals(simulatorPair, tntSimulatorPair)) { + if (simulatorPair.getKey() != null) { + SimulatorCursor.show(player, simulator, trace(player, player.getLocation(), simulator)); + } + return; + } + + if (tntSimulator != null) { + tntSimulator.hide(player); + currentSimulator.remove(player); + } if (simulator == null) { SimulatorCursor.hide(player); return; } - currentSimulator.put(player, simulator); + + currentSimulator.put(player, simulatorPair); simulator.show(player); SimulatorCursor.show(player, simulator, trace(player, player.getLocation(), simulator)); if (simulatorPair.getValue()) { @@ -196,7 +209,7 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { currentSimulator.values().forEach(simulator -> { - simulator.calcPreview(false, event.getBlock().getLocation().toVector()); + simulator.getKey().calcPreview(false, event.getBlock().getLocation().toVector()); }); } @@ -204,7 +217,7 @@ public class TNTSimulatorListener implements Listener { public void onBlockBreak(BlockBreakEvent event) { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { currentSimulator.values().forEach(simulator -> { - simulator.calcPreview(false, event.getBlock().getLocation().toVector()); + simulator.getKey().calcPreview(false, event.getBlock().getLocation().toVector()); }); }, 0); }