From 595c45bb54a10e8ffc3598cfc54dd71406c305e5 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Thu, 9 May 2024 11:44:50 +0200 Subject: [PATCH 1/3] Added advanced logging for trace read EOF --- .../bausystem/features/tracer/Trace.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java index 13e7114d..e3305def 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java @@ -29,11 +29,14 @@ import de.steamwar.entity.REntityServer; import lombok.Cleanup; import lombok.Getter; import lombok.SneakyThrows; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.io.*; import java.lang.ref.SoftReference; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.GZIPInputStream; @@ -308,16 +311,28 @@ public class Trace { /** * Loads the records of this trace from storage to memory */ - @SneakyThrows private void loadRecords() { List records = new ArrayList<>(); + long readBytes = 0; + try { + FileInputStream fileInputStream = new FileInputStream(recordsSaveFile); - FileInputStream fileInputStream = new FileInputStream(recordsSaveFile); + @Cleanup + ObjectInputStream inputStream = new ObjectInputStream(new GZIPInputStream(fileInputStream)); + long fileLenght = recordsSaveFile.length(); + while (fileInputStream.getChannel().position() < fileLenght) { + records.add((TNTPoint) inputStream.readObject()); + readBytes = fileInputStream.getChannel().position(); + } + } catch (EOFException e) { + Logger logger = Bukkit.getLogger(); + logger.log(Level.WARNING, "EOF in trace read detected in " + uuid); + logger.log(Level.WARNING, "Read " + readBytes + "/" + recordsSaveFile.length() + " Bytes"); + logger.log(Level.WARNING, "Read so far: " + records); - @Cleanup - ObjectInputStream inputStream = new ObjectInputStream(new GZIPInputStream(fileInputStream)); - while (fileInputStream.getChannel().position() < recordsSaveFile.length()) { - records.add((TNTPoint) inputStream.readObject()); + e.printStackTrace(); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); } Map> histories = new HashMap<>(); From 7d01ebf4edc82e188c007f64d1e6f34d3e0ebc1a Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Thu, 9 May 2024 12:18:27 +0200 Subject: [PATCH 2/3] Fixed build-destory-only not working --- .../de/steamwar/bausystem/features/tracer/TraceRecorder.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java index eeb6d941..0fba6df0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java @@ -113,7 +113,7 @@ public class TraceRecorder implements Listener { public void stopRecording(Region region) { TraceRecordingWrapper wrappedTrace = activeTraces.getOrDefault(region, null); if (wrappedTrace == null) return; - + wrappedTrace.finalizeRecording(); activeTraces.remove(region); for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) { @@ -247,10 +247,9 @@ public class TraceRecorder implements Listener { * * @param event */ - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onTNTExplode(EntityExplodeEvent event) { if (!(event.getEntity() instanceof TNTPrimed)) return; - Region region = tntSpawnRegion.getOrDefault((TNTPrimed) event.getEntity(), null); if (region == null) return; trackedTNT.get(region).remove((TNTPrimed) event.getEntity()); From f054710a958c4bd20e0c0cc07e151ce1d9d4d558 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Fri, 10 May 2024 18:34:50 +0200 Subject: [PATCH 3/3] Improved Advanced-Flag to backtrack instead of going forward --- .../features/tracer/rendering/ViewFlag.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/ViewFlag.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/ViewFlag.java index 83ad005d..8702a607 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/ViewFlag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/ViewFlag.java @@ -26,10 +26,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -120,26 +117,30 @@ public abstract class ViewFlag { @Override public void modify(REntityServer server, List entities) { for (TraceEntity entity : entities) { - TNTPoint current = entity.getRecords().get(0); - if (current.isExplosion()) continue; - TNTPoint next = current.getNext().orElse(null); - if (next == null) continue; + TNTPoint representative = entity.getRecords().get(0); + Optional prev = representative.getPrevious(); - Location pos = current.getLocation().clone(); - pos.setY(next.getLocation().getY()); + if (prev.isEmpty()) continue; - if (pos.distanceSquared(current.getLocation()) >= 1.0 / 256.0) { - RFallingBlockEntity y = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS); + TNTPoint previous = prev.get(); + + Location delta = representative.getLocation().clone().subtract(previous.getLocation()); + + Location yLocation = previous.getLocation().clone().add(0, delta.getY(), 0); + if (yLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && yLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) { + RFallingBlockEntity y = new RFallingBlockEntity(server, yLocation, Material.WHITE_STAINED_GLASS); y.setNoGravity(true); } - if (current.getVelocity().getX() >= current.getVelocity().getZ()) { - pos.setX(next.getLocation().getX()); + Location secoundLocation; + if (delta.getX() >= delta.getZ()) { + secoundLocation = previous.getLocation().clone().add(delta.getX(), delta.getY(), 0); } else { - pos.setZ(next.getLocation().getZ()); + secoundLocation = previous.getLocation().clone().add(0, delta.getY(), delta.getZ()); } - if (pos.distanceSquared(next.getLocation()) >= 1.0 / 256.0) { - RFallingBlockEntity second = new RFallingBlockEntity(server, pos, Material.WHITE_STAINED_GLASS); + + if (secoundLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && secoundLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) { + RFallingBlockEntity second = new RFallingBlockEntity(server, secoundLocation, Material.WHITE_STAINED_GLASS); second.setNoGravity(true); } }