From c92d610ca9e0772d596d14fb670719a6a5a254ff Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 8 Sep 2023 20:46:00 +0200 Subject: [PATCH] Fix many inconveniences Signed-off-by: yoyosource --- .../bausystem/features/simulator/preview/Simulator19.java | 6 ++++-- .../bausystem/features/simulator/TNTSimulator.java | 2 ++ .../features/simulator/TNTSimulatorListener.java | 8 +++++++- .../features/simulator/preview/PreviewRecord.java | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java index 909fb324..3b5d5db1 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java @@ -53,7 +53,9 @@ public class Simulator19 implements Simulator { @Override public void run() { long time = System.currentTimeMillis(); - while (!simulatorData.tntList.isEmpty() || currentTick <= toCalculate.getKey() && System.currentTimeMillis() - time < 40) { + while (!simulatorData.tntList.isEmpty() || currentTick <= toCalculate.getKey()) { + if (System.currentTimeMillis() - time >= 40) break; + List>> toSpawnInTick = toCalculate.getValue().get(currentTick); if (toSpawnInTick != null) { int finalCurrentTick = currentTick; @@ -94,7 +96,7 @@ public class Simulator19 implements Simulator { } System.out.println("Time: " + (System.currentTimeMillis() - time) + "ms " + simulatorData.cacheMisses + "/" + simulatorData.accessed + "/" + simulatorData.aired); - if (simulatorData.tntList.isEmpty() && currentTick <= toCalculate.getKey()) { + if (simulatorData.tntList.isEmpty() && currentTick > toCalculate.getKey()) { simulatorData.airBlocks.forEach(pos -> previewRecord.addAir(new Vector(pos.x, pos.y, pos.z))); consumer.accept(previewRecord); cancel(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 8a0bc5cf..59914193 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -66,6 +66,8 @@ public class TNTSimulator { private List toShow = new ArrayList<>(); private BukkitTask currentlyCalculating = null; + + @Getter private PreviewRecord previewRecord = null; public TNTSimulator() { 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 995bf560..f18af23c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -36,6 +36,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; @@ -77,6 +78,10 @@ public class TNTSimulatorListener implements Listener { return RayTraceUtils.traceREntity(player, to, simulator.getEntities()); } + private static final Class base = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying"); + private static final Reflection.FieldAccessor x = Reflection.getField(base, double.class, 0); + private static final Reflection.FieldAccessor y = Reflection.getField(base, double.class, 1); + private static final Reflection.FieldAccessor z = Reflection.getField(base, double.class, 2); private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); @@ -86,6 +91,7 @@ public class TNTSimulatorListener implements Listener { TNTSimulator 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; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { PlayerMovementWrapper.impl.setPosition(player, o); }, 0L); @@ -139,7 +145,7 @@ public class TNTSimulatorListener implements Listener { hideShow(e.getPlayer(), simulatorPair); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerQuit(PlayerQuitEvent e) { hideShow(e.getPlayer(), new Pair<>(null, false)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java index 147a0119..6cdf169e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java @@ -84,4 +84,9 @@ public class PreviewRecord { public boolean has(Player player) { return showModeMap.containsKey(player); } + + public boolean isAir(double x, double y, double z) { + Vector vec = new Vector(x, y, z); + return destroyedBlocks.contains(new Vector(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ())); + } }