From d800eb554475163d09f1b190418a8c952d41b92e Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 10:14:14 +0200 Subject: [PATCH 01/20] Fix help message 15 --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 22eb928..70bea5d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -31,7 +31,7 @@ public class CommandTrace implements CommandExecutor { player.sendMessage("§8/§etrace toggleshow §8<§7TNT-ID§8> §8- §7Zeigt/Versteckt ein TNT"); player.sendMessage("§8/§etrace delete §8<§7TNT-ID§8> §8- §7Löscht alle TNT-Positionen"); player.sendMessage("§8/§etrace interpolate §8[§eall§8|§eyaxis§8|§enone§8] §8- §7Interpolationsoptionen"); - player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8>§8- §7Listet alle TNT auf"); + player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf"); //player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an"); player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); } From df72a08f9922ff5319af95e2d75fa89541b58824 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 14:42:55 +0200 Subject: [PATCH 02/20] Fix NullPointerException in delete() --- .../src/de/steamwar/bausystem/tracer/trace/TNTFrame.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java index ca9364b..11301aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java @@ -50,7 +50,6 @@ public class TNTFrame { private void delete(TNTPrimed tntPrimed, boolean delete) { if (aliveTNT == null) return; TNTTrace tntTrace = aliveTNT.get(tntPrimed); - tntTrace.addLocation(tntPrimed.getLocation()); if (delete) { aliveTNT.remove(tntPrimed); } From 7e5d690c9d0e64159a76563e7399bf8cda59ba4f Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 14:51:40 +0200 Subject: [PATCH 03/20] Fix synchronization Deadlock --- .../de/steamwar/bausystem/tracer/PlayerTraceCache_15.java | 7 ++++++- .../src/de/steamwar/bausystem/tracer/TNTTracer12.java | 6 +++--- .../src/de/steamwar/bausystem/tracer/TNTTracer15.java | 1 + .../de/steamwar/bausystem/tracer/trace/ShowManager.java | 8 ++++++++ .../de/steamwar/bausystem/tracer/trace/ShowStatus.java | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java index 16fc7e9..f60583b 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java @@ -23,6 +23,8 @@ public class PlayerTraceCache_15 { private float[] pLocation; private float locationThreshold = square(10.0F); + private boolean hiding = false; + public PlayerTraceCache_15() { this.pLocation = new float[]{0.0F, 0.0F, 0.0F}; } @@ -49,7 +51,8 @@ public class PlayerTraceCache_15 { return false; } - public synchronized void show(Player player, TNTShowCallback_15.ShowMode showMode) { + public void show(Player player, TNTShowCallback_15.ShowMode showMode) { + if (hiding) return; if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { float x = positions[i + 0]; @@ -84,6 +87,7 @@ public class PlayerTraceCache_15 { } public synchronized void hide(Player player) { + hiding = true; if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { float x = positions[i + 0]; @@ -102,6 +106,7 @@ public class PlayerTraceCache_15 { hideBlock(player, x, y + 0.49F, z); } updatePoints = new float[0]; + hiding = false; } private static void showCorner(Player player, float x, float y, float z, Particle particle) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java index 37fc4fb..8d02563 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java @@ -29,7 +29,7 @@ public class TNTTracer12 { TNTTracer_12.remove(locations, tnt); } - public static void start(){ + public static void start() { if(status == Status.RECORD) return; stop(); @@ -39,7 +39,7 @@ public class TNTTracer12 { task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer12::run, 1, 1); } - public static int show(){ + public static int show() { if(status == Status.SHOW) return printedLocs.size(); stop(); @@ -48,7 +48,7 @@ public class TNTTracer12 { return TNTTracer_12.show(locations, printedLocs); } - public static void stop(){ + public static void stop() { status = Status.IDLE; if(task != null) task.cancel(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index 2d49dba..af13218 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -326,6 +326,7 @@ public class TNTTracer15 { Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt"))); status = Status.IDLE_AUTO; } + ShowManager.dirty(); if (task != null) task.cancel(); if (tntFrames.getLast().finish()) { tntFrames.removeLast(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java index 5506762..d87f465 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java @@ -15,6 +15,14 @@ public class ShowManager { TNTTracer15.worldInit(); } + public static void dirty() { + for (Map.Entry entry : showMap.entrySet()) { + if (entry.getValue().getShow() != ShowStatus.Show.NONE) { + entry.getValue().dirty = true; + } + } + } + public static void remove(Player player) { showMap.remove(player); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java index 0b65c54..a9949d3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java @@ -16,7 +16,7 @@ public class ShowStatus { private Player p; - private boolean dirty = false; + boolean dirty = false; public ShowStatus(Player p) { this.p = p; From 6f558b6b91a79ea018e5e528e9875d04a7140eb3 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 14:54:07 +0200 Subject: [PATCH 04/20] Fix dirty Flaging --- .../de/steamwar/bausystem/tracer/trace/ShowManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java index d87f465..74a438e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java @@ -1,6 +1,7 @@ package de.steamwar.bausystem.tracer.trace; import de.steamwar.bausystem.tracer.TNTTracer15; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.HashMap; @@ -16,9 +17,9 @@ public class ShowManager { } public static void dirty() { - for (Map.Entry entry : showMap.entrySet()) { - if (entry.getValue().getShow() != ShowStatus.Show.NONE) { - entry.getValue().dirty = true; + for (Player player : Bukkit.getOnlinePlayers()) { + if (showMap.get(player).getShow() != ShowStatus.Show.NONE) { + showMap.get(player).dirty = true; } } } From 29c3e954beea36832d137052750f39a33fbb139c Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 16:38:47 +0200 Subject: [PATCH 05/20] Fix ArrayIndexOutOfBoundsException --- .../src/de/steamwar/bausystem/tracer/trace/TNTTrace.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java index b20f6b5..212d6ec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java @@ -10,7 +10,7 @@ public class TNTTrace { private int uniqueID; private int index = 0; - private float[] positions = new float[243]; + private float[] positions = new float[240]; public TNTTrace(int uniqueID) { this.uniqueID = uniqueID; @@ -21,6 +21,9 @@ public class TNTTrace { } public void addLocation(double x, double y, double z) { + if (index >= positions.length) { + positions = Arrays.copyOf(positions, positions.length + 240); + } positions[index + 0] = (float)x; positions[index + 1] = (float)y; positions[index + 2] = (float)z; From 8d10a702b438bc03700d2cfde67b6e6d047e6768 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 17:21:33 +0200 Subject: [PATCH 06/20] Fix ConcurrentModificationException --- .../src/de/steamwar/bausystem/tracer/TNTTracer_15.java | 8 +++++++- .../tracer/showcallback/TracerCallbackTracing_15.java | 8 ++++++++ .../src/de/steamwar/bausystem/tracer/TNTTracer15.java | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 5c1cc63..7847323 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -21,6 +21,7 @@ class TNTTracer_15 { private static TracerCallback_15 tracerCallback; private static TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints; + private static TracerCallbackTracing_15 tracerCallbackTracing; private static TracerActionBarCallback_15 tracerActionBarCallback; private static TNTShowCallback_15 tntShowCallback; private static CacheUpdateCallback_15 cacheUpdateCallback; @@ -39,7 +40,7 @@ class TNTTracer_15 { return d * d; } - static void init(Plugin plugin, TracerCallback_15 tracerCallback, TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints, TracerActionBarCallback_15 tracerActionBarCallback, TNTShowCallback_15 tntShowCallback, CacheUpdateCallback_15 cacheUpdateCallback) { + static void init(Plugin plugin, TracerCallback_15 tracerCallback, TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints, TracerActionBarCallback_15 tracerActionBarCallback, TNTShowCallback_15 tntShowCallback, CacheUpdateCallback_15 cacheUpdateCallback, TracerCallbackTracing_15 tracerCallbackTracing) { Bukkit.getScheduler().runTaskTimer(plugin, () -> { synchronized (synchronizer) { synchronizer.notifyAll(); @@ -63,6 +64,7 @@ class TNTTracer_15 { TNTTracer_15.tracerActionBarCallback = tracerActionBarCallback; TNTTracer_15.tntShowCallback = tntShowCallback; TNTTracer_15.cacheUpdateCallback = cacheUpdateCallback; + TNTTracer_15.tracerCallbackTracing = tracerCallbackTracing; } static void initWorld() { @@ -100,6 +102,10 @@ class TNTTracer_15 { private static float[] noValue = new float[0]; private static void update(Player p, PlayerTraceCache_15 traceCache) { + if (tracerCallbackTracing.run()) { + return; + } + float[] floats = tracerCallback.run(p); if (floats.length == 0 || floats.length % 3 != 0) { traceCache.setPositions(noValue); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java new file mode 100644 index 0000000..b456011 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java @@ -0,0 +1,8 @@ +package de.steamwar.bausystem.tracer.showcallback; + +@FunctionalInterface +public interface TracerCallbackTracing_15 { + + boolean run(); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index af13218..d39dd86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -44,7 +44,7 @@ public class TNTTracer15 { private static final float[] noValue = new float[0]; public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty()); + TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), () -> status == Status.RECORD || status == Status.RECORD_AUTO); } private static float[] accumulate(LinkedList traces) { From f4378c58c24ba125a47bcc90a8e556a32f0aa66a Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 17:49:07 +0200 Subject: [PATCH 07/20] Fix ConcurrentModificationException - 2 --- .../src/de/steamwar/bausystem/tracer/TNTTracer15.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index d39dd86..f0ede25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -26,6 +26,7 @@ public class TNTTracer15 { private static long current = System.currentTimeMillis(); private static boolean removeInWater = true; + private static long lastExplosion = System.currentTimeMillis(); private static World world; public static void worldInit() { @@ -44,7 +45,7 @@ public class TNTTracer15 { private static final float[] noValue = new float[0]; public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), () -> status == Status.RECORD || status == Status.RECORD_AUTO); + TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), () -> System.currentTimeMillis() - lastExplosion > 4500); } private static float[] accumulate(LinkedList traces) { @@ -264,6 +265,7 @@ public class TNTTracer15 { static void explode(TNTPrimed tntPrimed) { if (tntFrames.isEmpty()) return; + lastExplosion = System.currentTimeMillis(); tntFrames.getLast().explode(tntPrimed); } From 8254fb6e5e1ebb52d40e4118b3423deaf26cefd2 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 19:18:28 +0200 Subject: [PATCH 08/20] Fix ConcurrentModificationException - 3 --- .../src/de/steamwar/bausystem/tracer/TNTTracer15.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index f0ede25..a01710d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -45,7 +45,7 @@ public class TNTTracer15 { private static final float[] noValue = new float[0]; public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), () -> System.currentTimeMillis() - lastExplosion > 4500); + TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), () -> System.currentTimeMillis() - lastExplosion < 4500); } private static float[] accumulate(LinkedList traces) { From 930e8dc7d0b30908e189c912d7044f3f94373d04 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 19:54:58 +0200 Subject: [PATCH 09/20] Fix Updating Issue while Tracing --- .../src/de/steamwar/bausystem/tracer/TNTTracer_15.java | 2 +- .../tracer/showcallback/TracerCallbackTracing_15.java | 4 +++- .../src/de/steamwar/bausystem/tracer/TNTTracer15.java | 7 ++++++- .../src/de/steamwar/bausystem/tracer/trace/ShowStatus.java | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 7847323..feea293 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -102,7 +102,7 @@ class TNTTracer_15 { private static float[] noValue = new float[0]; private static void update(Player p, PlayerTraceCache_15 traceCache) { - if (tracerCallbackTracing.run()) { + if (tracerCallbackTracing.run(p)) { return; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java index b456011..16ee5b7 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java @@ -1,8 +1,10 @@ package de.steamwar.bausystem.tracer.showcallback; +import org.bukkit.entity.Player; + @FunctionalInterface public interface TracerCallbackTracing_15 { - boolean run(); + boolean run(Player p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index a01710d..6a9731b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -45,7 +45,12 @@ public class TNTTracer15 { private static final float[] noValue = new float[0]; public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), () -> System.currentTimeMillis() - lastExplosion < 4500); + TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), p -> { + if (System.currentTimeMillis() - lastExplosion < 4500) { + ShowManager.get(p).dirty(); + } + return System.currentTimeMillis() - lastExplosion < 4500; + }); } private static float[] accumulate(LinkedList traces) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java index a9949d3..c28e118 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java @@ -147,6 +147,10 @@ public class ShowStatus { return false; } + public void dirty() { + dirty = true; + } + @Override public String toString() { return "ShowStatus{" + From 4eed29d7d611fae4b1a0fedf462972a673d46da6 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 20:36:33 +0200 Subject: [PATCH 10/20] Add Initial 1.12 Support --- .../bausystem/tracer/PlayerTraceCache_15.java | 8 ++-- .../bausystem/tracer/TNTTracerGUI_15.java | 24 ++++++------ .../bausystem/tracer/TNTTracer_15.java | 37 ++++++++++--------- .../TracerActionBarCallback_15.java | 8 ---- .../TracerCallbackTracing_15.java | 10 ----- .../TracerCallbackUpdatePoints_15.java | 10 ----- .../showcallback/TracerCallback_15.java | 10 ----- .../debugcallback/DebugCallbackActionBar.java | 8 ++++ .../guicallback/GuiCallbackRecording.java | 2 +- .../guicallback/GuiCallbackTNTFrame.java | 2 +- .../guicallback/GuiCallbackTNTTrace.java | 2 +- .../showcallback/TNTCallbackCacheUpdate.java | 2 +- .../tracer/showcallback/TNTCallbackShow.java | 2 +- .../TracerCallbackPositions.java | 10 +++++ .../updatecallback/TracerCallbackTracing.java | 10 +++++ .../TracerCallbackUpdatePoints.java | 10 +++++ .../bausystem/tracer/TNTTracer15.java | 10 ++--- 17 files changed, 84 insertions(+), 81 deletions(-) delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerActionBarCallback_15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackUpdatePoints_15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallback_15.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java rename BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/RecordingCallback_15.java => BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java (77%) rename BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTFrameCallback_15.java => BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java (82%) rename BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTTraceCallback_15.java => BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java (82%) rename BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/CacheUpdateCallback_15.java => BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java (76%) rename BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TNTShowCallback_15.java => BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java (84%) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java index f60583b..922cc31 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java @@ -1,6 +1,6 @@ package de.steamwar.bausystem.tracer; -import de.steamwar.bausystem.tracer.showcallback.TNTShowCallback_15; +import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -51,7 +51,7 @@ public class PlayerTraceCache_15 { return false; } - public void show(Player player, TNTShowCallback_15.ShowMode showMode) { + public void show(Player player, TNTCallbackShow.ShowMode showMode) { if (hiding) return; if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { @@ -59,7 +59,7 @@ public class PlayerTraceCache_15 { float y = positions[i + 1]; float z = positions[i + 2]; - if (showMode == TNTShowCallback_15.ShowMode.PARTICLE && positions.length / 3 < 1000) { + if (showMode == TNTCallbackShow.ShowMode.PARTICLE && positions.length / 3 < 1000) { showCorner(player, x - 0.49F, y, z - 0.49F, Particle.FLAME); } else { showBlock(player, x, y + 0.49F, z, Material.RED_STAINED_GLASS, (byte) 14); @@ -78,7 +78,7 @@ public class PlayerTraceCache_15 { if (hasBlock(positions, x, y, z)) continue; - if (showMode == TNTShowCallback_15.ShowMode.PARTICLE) { + if (showMode == TNTCallbackShow.ShowMode.PARTICLE) { showCorner(player, x - 0.49F, y, z - 0.49F, Particle.VILLAGER_HAPPY); } else { showBlock(player, x, y + 0.49F, z, Material.LIME_STAINED_GLASS, (byte) 5); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java index fa2664a..24f24b2 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java @@ -1,8 +1,8 @@ package de.steamwar.bausystem.tracer; -import de.steamwar.bausystem.tracer.guicallback.RecordingCallback_15; -import de.steamwar.bausystem.tracer.guicallback.TNTFrameCallback_15; -import de.steamwar.bausystem.tracer.guicallback.TNTTraceCallback_15; +import de.steamwar.bausystem.tracer.guicallback.GuiCallbackRecording; +import de.steamwar.bausystem.tracer.guicallback.GuiCallbackTNTFrame; +import de.steamwar.bausystem.tracer.guicallback.GuiCallbackTNTTrace; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -17,9 +17,9 @@ import java.util.List; public class TNTTracerGUI_15 { - private static TNTFrameCallback_15 tntFrameCallback_15; - private static TNTTraceCallback_15 tntTraceCallback_15; - private static RecordingCallback_15 recordingCallback_15; + private static GuiCallbackTNTFrame guiCallbackTNTFrame; + private static GuiCallbackTNTTrace guiCallbackTNTTrace; + private static GuiCallbackRecording guiCallbackRecording; private static Inventory getEmpty(String title) { Inventory inventory = Bukkit.createInventory(null, 54, title); @@ -60,12 +60,12 @@ public class TNTTracerGUI_15 { inventory.setItem(1, createItem(Material.HONEYCOMB, false, "§eShow§8/§eHide")); inventory.setItem(4, createItem(Material.BARRIER, false, "§eClear ausgewählte Positionen")); inventory.setItem(5, createItem(Material.OBSERVER, false, "§eToggle AUTO-Trace")); - inventory.setItem(6, recordingCallback_15.run()); + inventory.setItem(6, guiCallbackRecording.run()); inventory.setItem(8, createItem(Material.PAPER, false, "§7PAGE §e§l" + page + "§8/§e§l" + allPages)); } private static Inventory getFrameInventory(Player p, int page) { - ItemStack[] items = tntFrameCallback_15.run(p); + ItemStack[] items = guiCallbackTNTFrame.run(p); Inventory inventory = getEmpty("§7§lTRACE §8- §e§lAufnahmen"); if (items.length == 0) { @@ -76,10 +76,10 @@ public class TNTTracerGUI_15 { return inventory; } - public static void init(TNTFrameCallback_15 tntFrameCallback_15, TNTTraceCallback_15 tntTraceCallback_15, RecordingCallback_15 recordingCallback_15) { - TNTTracerGUI_15.tntFrameCallback_15 = tntFrameCallback_15; - TNTTracerGUI_15.tntTraceCallback_15 = tntTraceCallback_15; - TNTTracerGUI_15.recordingCallback_15 = recordingCallback_15; + public static void init(GuiCallbackTNTFrame guiCallbackTNTFrame, GuiCallbackTNTTrace guiCallbackTNTTrace, GuiCallbackRecording guiCallbackRecording) { + TNTTracerGUI_15.guiCallbackTNTFrame = guiCallbackTNTFrame; + TNTTracerGUI_15.guiCallbackTNTTrace = guiCallbackTNTTrace; + TNTTracerGUI_15.guiCallbackRecording = guiCallbackRecording; } public enum Menu { diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index feea293..7bf223f 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -1,6 +1,9 @@ package de.steamwar.bausystem.tracer; -import de.steamwar.bausystem.tracer.showcallback.*; +import de.steamwar.bausystem.tracer.debugcallback.DebugCallbackActionBar; +import de.steamwar.bausystem.tracer.showcallback.TNTCallbackCacheUpdate; +import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; +import de.steamwar.bausystem.tracer.updatecallback.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -19,12 +22,12 @@ class TNTTracer_15 { private TNTTracer_15(){} - private static TracerCallback_15 tracerCallback; - private static TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints; - private static TracerCallbackTracing_15 tracerCallbackTracing; - private static TracerActionBarCallback_15 tracerActionBarCallback; - private static TNTShowCallback_15 tntShowCallback; - private static CacheUpdateCallback_15 cacheUpdateCallback; + private static TracerCallbackPositions tracerCallbackPositions; + private static TracerCallbackUpdatePoints tracerCallbackUpdatePoints; + private static TracerCallbackTracing tracerCallbackTracing; + private static DebugCallbackActionBar debugCallbackActionBar; + private static TNTCallbackShow tntCallbackShow; + private static TNTCallbackCacheUpdate tntCallbackCacheUpdate; private static Map playerMap = new HashMap<>(); @@ -40,7 +43,7 @@ class TNTTracer_15 { return d * d; } - static void init(Plugin plugin, TracerCallback_15 tracerCallback, TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints, TracerActionBarCallback_15 tracerActionBarCallback, TNTShowCallback_15 tntShowCallback, CacheUpdateCallback_15 cacheUpdateCallback, TracerCallbackTracing_15 tracerCallbackTracing) { + static void init(Plugin plugin, TracerCallbackPositions tracerCallbackPositions, TracerCallbackUpdatePoints tracerCallbackUpdatePoints, TracerCallbackTracing tracerCallbackTracing, DebugCallbackActionBar debugCallbackActionBar, TNTCallbackShow tntCallbackShow, TNTCallbackCacheUpdate tntCallbackCacheUpdate) { Bukkit.getScheduler().runTaskTimer(plugin, () -> { synchronized (synchronizer) { synchronizer.notifyAll(); @@ -59,11 +62,11 @@ class TNTTracer_15 { } }); - TNTTracer_15.tracerCallback = tracerCallback; + TNTTracer_15.tracerCallbackPositions = tracerCallbackPositions; TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints; - TNTTracer_15.tracerActionBarCallback = tracerActionBarCallback; - TNTTracer_15.tntShowCallback = tntShowCallback; - TNTTracer_15.cacheUpdateCallback = cacheUpdateCallback; + TNTTracer_15.debugCallbackActionBar = debugCallbackActionBar; + TNTTracer_15.tntCallbackShow = tntCallbackShow; + TNTTracer_15.tntCallbackCacheUpdate = tntCallbackCacheUpdate; TNTTracer_15.tracerCallbackTracing = tracerCallbackTracing; } @@ -77,7 +80,7 @@ class TNTTracer_15 { private static void run() { if (actionBar) { - String actionBar = tracerActionBarCallback.run(); + String actionBar = debugCallbackActionBar.run(); Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar))); } for (Player p : Bukkit.getOnlinePlayers()) { @@ -89,13 +92,13 @@ class TNTTracer_15 { traceCache = playerMap.get(p); } - if (!traceCache.nearLastLocation(p) && !cacheUpdateCallback.run(p)) { - traceCache.show(p, tntShowCallback.run(p)); + if (!traceCache.nearLastLocation(p) && !tntCallbackCacheUpdate.run(p)) { + traceCache.show(p, tntCallbackShow.run(p)); continue; } update(p, traceCache); - traceCache.show(p, tntShowCallback.run(p)); + traceCache.show(p, tntCallbackShow.run(p)); } } @@ -106,7 +109,7 @@ class TNTTracer_15 { return; } - float[] floats = tracerCallback.run(p); + float[] floats = tracerCallbackPositions.run(p); if (floats.length == 0 || floats.length % 3 != 0) { traceCache.setPositions(noValue); traceCache.setUpdatePoints(noValue); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerActionBarCallback_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerActionBarCallback_15.java deleted file mode 100644 index adc5cef..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerActionBarCallback_15.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.steamwar.bausystem.tracer.showcallback; - -@FunctionalInterface -public interface TracerActionBarCallback_15 { - - String run(); - -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java deleted file mode 100644 index 16ee5b7..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackTracing_15.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.showcallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TracerCallbackTracing_15 { - - boolean run(Player p); - -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackUpdatePoints_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackUpdatePoints_15.java deleted file mode 100644 index 7d810c3..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallbackUpdatePoints_15.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.showcallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TracerCallbackUpdatePoints_15 { - - float[] run(Player p); - -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallback_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallback_15.java deleted file mode 100644 index 9f36e06..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TracerCallback_15.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.showcallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TracerCallback_15 { - - float[] run(Player p); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java new file mode 100644 index 0000000..b6988fb --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java @@ -0,0 +1,8 @@ +package de.steamwar.bausystem.tracer.debugcallback; + +@FunctionalInterface +public interface DebugCallbackActionBar { + + String run(); + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/RecordingCallback_15.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java similarity index 77% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/RecordingCallback_15.java rename to BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java index 91bb725..66b03d8 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/RecordingCallback_15.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java @@ -3,7 +3,7 @@ package de.steamwar.bausystem.tracer.guicallback; import org.bukkit.inventory.ItemStack; @FunctionalInterface -public interface RecordingCallback_15 { +public interface GuiCallbackRecording { ItemStack run(); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTFrameCallback_15.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java similarity index 82% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTFrameCallback_15.java rename to BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java index d06da2d..ee1b77e 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTFrameCallback_15.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java @@ -4,7 +4,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @FunctionalInterface -public interface TNTFrameCallback_15 { +public interface GuiCallbackTNTFrame { ItemStack[] run(Player p); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTTraceCallback_15.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java similarity index 82% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTTraceCallback_15.java rename to BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java index 46b5d93..cc57b60 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/guicallback/TNTTraceCallback_15.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java @@ -4,7 +4,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @FunctionalInterface -public interface TNTTraceCallback_15 { +public interface GuiCallbackTNTTrace { ItemStack[] run(Player p); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/CacheUpdateCallback_15.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java similarity index 76% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/CacheUpdateCallback_15.java rename to BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java index f05d2cb..d92369f 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/CacheUpdateCallback_15.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java @@ -3,7 +3,7 @@ package de.steamwar.bausystem.tracer.showcallback; import org.bukkit.entity.Player; @FunctionalInterface -public interface CacheUpdateCallback_15 { +public interface TNTCallbackCacheUpdate { boolean run(Player p); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TNTShowCallback_15.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java similarity index 84% rename from BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TNTShowCallback_15.java rename to BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java index 4a874c6..fc91355 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/showcallback/TNTShowCallback_15.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java @@ -3,7 +3,7 @@ package de.steamwar.bausystem.tracer.showcallback; import org.bukkit.entity.Player; @FunctionalInterface -public interface TNTShowCallback_15 { +public interface TNTCallbackShow { public static enum ShowMode { BLOCK, diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java new file mode 100644 index 0000000..ce1b4ec --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java @@ -0,0 +1,10 @@ +package de.steamwar.bausystem.tracer.updatecallback; + +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface TracerCallbackPositions { + + float[] run(Player p); + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java new file mode 100644 index 0000000..e88d073 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java @@ -0,0 +1,10 @@ +package de.steamwar.bausystem.tracer.updatecallback; + +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface TracerCallbackTracing { + + boolean run(Player p); + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java new file mode 100644 index 0000000..efe2a20 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java @@ -0,0 +1,10 @@ +package de.steamwar.bausystem.tracer.updatecallback; + +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface TracerCallbackUpdatePoints { + + float[] run(Player p); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index 6a9731b..5d09643 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -1,7 +1,7 @@ package de.steamwar.bausystem.tracer; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.showcallback.TNTShowCallback_15; +import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; import de.steamwar.bausystem.tracer.trace.ShowManager; import de.steamwar.bausystem.tracer.trace.ShowStatus; import de.steamwar.bausystem.tracer.trace.TNTFrame; @@ -45,7 +45,7 @@ public class TNTTracer15 { private static final float[] noValue = new float[0]; public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty(), p -> { + TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, p -> ShowManager.get(p).isDirty(), TNTTracer15::getActionBar, TNTTracer15::showMode, p -> { if (System.currentTimeMillis() - lastExplosion < 4500) { ShowManager.get(p).dirty(); } @@ -202,11 +202,11 @@ public class TNTTracer15 { return traces; } - private static TNTShowCallback_15.ShowMode showMode(Player player) { + private static TNTCallbackShow.ShowMode showMode(Player player) { if (ShowManager.get(player).getShowMode() == ShowStatus.ShowMode.BLOCK) { - return TNTShowCallback_15.ShowMode.BLOCK; + return TNTCallbackShow.ShowMode.BLOCK; } else { - return TNTShowCallback_15.ShowMode.PARTICLE; + return TNTCallbackShow.ShowMode.PARTICLE; } } From 6c625c51c0c2c9e91ba50b8159e29567be6ed09e Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 19 Jul 2020 20:42:10 +0200 Subject: [PATCH 11/20] Add dirtyFlag after explode --- .../src/de/steamwar/bausystem/tracer/TNTTracer15.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index 5d09643..8137898 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -270,6 +270,9 @@ public class TNTTracer15 { static void explode(TNTPrimed tntPrimed) { if (tntFrames.isEmpty()) return; + if (System.currentTimeMillis() - lastExplosion > 4500) { + ShowManager.dirty(); + } lastExplosion = System.currentTimeMillis(); tntFrames.getLast().explode(tntPrimed); } @@ -313,9 +316,7 @@ public class TNTTracer15 { tntFrames.addLast(new TNTFrame()); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer15::run, 1, 1); current = System.currentTimeMillis(); - if (status == Status.RECORD_AUTO) { - run(); - } + run(); } if (status == Status.RECORD_AUTO) { current = System.currentTimeMillis(); From 5967592ced388148eeb37f95244816df39f4baaa Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 25 Jul 2020 20:43:59 +0200 Subject: [PATCH 12/20] Fix "/trace show" Fix "/trace hide" Remove ShowRadius --- .../bausystem/tracer/TNTTracer_15.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 7bf223f..95911bf 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -92,16 +92,17 @@ class TNTTracer_15 { traceCache = playerMap.get(p); } - if (!traceCache.nearLastLocation(p) && !tntCallbackCacheUpdate.run(p)) { - traceCache.show(p, tntCallbackShow.run(p)); - continue; - } - - update(p, traceCache); - traceCache.show(p, tntCallbackShow.run(p)); + updateShowPlayer(p, traceCache); } } + private static void updateShowPlayer(Player p, PlayerTraceCache_15 traceCache) { + if (!tntCallbackCacheUpdate.run(p) && traceCache.nearLastLocation(p)) { + update(p, traceCache); + } + traceCache.show(p, tntCallbackShow.run(p)); + } + private static float[] noValue = new float[0]; private static void update(Player p, PlayerTraceCache_15 traceCache) { @@ -133,6 +134,10 @@ class TNTTracer_15 { } private static float[] accumulatePositions(float[] floats, float px, float py, float pz) { + if (true) { + return floats; + } + LinkedList linkedList = new LinkedList<>(); for (int i = 0; i < floats.length; i += 3) { From 423ec6999620885b2958b62dc1590e6015254785 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 25 Jul 2020 21:09:27 +0200 Subject: [PATCH 13/20] Fix Trace show/hide Bug --- .../src/de/steamwar/bausystem/tracer/TNTTracer_15.java | 4 ++-- .../tracer/updatecallback/TracerUpdateManager.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 95911bf..de72554 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -97,7 +97,7 @@ class TNTTracer_15 { } private static void updateShowPlayer(Player p, PlayerTraceCache_15 traceCache) { - if (!tntCallbackCacheUpdate.run(p) && traceCache.nearLastLocation(p)) { + if (!tntCallbackCacheUpdate.run(p)) { update(p, traceCache); } traceCache.show(p, tntCallbackShow.run(p)); @@ -106,7 +106,7 @@ class TNTTracer_15 { private static float[] noValue = new float[0]; private static void update(Player p, PlayerTraceCache_15 traceCache) { - if (tracerCallbackTracing.run(p)) { + if (!tracerCallbackTracing.run(p) && traceCache.nearLastLocation(p)) { return; } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java new file mode 100644 index 0000000..223249c --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java @@ -0,0 +1,9 @@ +package de.steamwar.bausystem.tracer.updatecallback; + +public class TracerUpdateManager { + + public TracerUpdateManager() { + + } + +} From bb8c6c259ec6924b9159f128465bda32356c862d Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 25 Jul 2020 21:16:58 +0200 Subject: [PATCH 14/20] Fix Trace show/hide Bug --- .../bausystem/tracer/TNTTracer_15.java | 16 +++++-------- .../bausystem/tracer/TracerUpdateManager.java | 23 +++++++++++++++++++ .../updatecallback/TracerUpdateManager.java | 9 -------- .../bausystem/tracer/TNTTracer15.java | 4 ++-- 4 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index de72554..fd1c2e8 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -24,10 +24,10 @@ class TNTTracer_15 { private static TracerCallbackPositions tracerCallbackPositions; private static TracerCallbackUpdatePoints tracerCallbackUpdatePoints; - private static TracerCallbackTracing tracerCallbackTracing; private static DebugCallbackActionBar debugCallbackActionBar; private static TNTCallbackShow tntCallbackShow; - private static TNTCallbackCacheUpdate tntCallbackCacheUpdate; + + private static TracerUpdateManager tracerUpdateManager; private static Map playerMap = new HashMap<>(); @@ -43,7 +43,7 @@ class TNTTracer_15 { return d * d; } - static void init(Plugin plugin, TracerCallbackPositions tracerCallbackPositions, TracerCallbackUpdatePoints tracerCallbackUpdatePoints, TracerCallbackTracing tracerCallbackTracing, DebugCallbackActionBar debugCallbackActionBar, TNTCallbackShow tntCallbackShow, TNTCallbackCacheUpdate tntCallbackCacheUpdate) { + static void init(Plugin plugin, TracerCallbackPositions tracerCallbackPositions, TracerCallbackUpdatePoints tracerCallbackUpdatePoints, DebugCallbackActionBar debugCallbackActionBar, TNTCallbackShow tntCallbackShow, TracerUpdateManager tracerUpdateManager) { Bukkit.getScheduler().runTaskTimer(plugin, () -> { synchronized (synchronizer) { synchronizer.notifyAll(); @@ -66,8 +66,8 @@ class TNTTracer_15 { TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints; TNTTracer_15.debugCallbackActionBar = debugCallbackActionBar; TNTTracer_15.tntCallbackShow = tntCallbackShow; - TNTTracer_15.tntCallbackCacheUpdate = tntCallbackCacheUpdate; - TNTTracer_15.tracerCallbackTracing = tracerCallbackTracing; + + TNTTracer_15.tracerUpdateManager = tracerUpdateManager; } static void initWorld() { @@ -97,7 +97,7 @@ class TNTTracer_15 { } private static void updateShowPlayer(Player p, PlayerTraceCache_15 traceCache) { - if (!tntCallbackCacheUpdate.run(p)) { + if (tracerUpdateManager.run(p, traceCache.nearLastLocation(p))) { update(p, traceCache); } traceCache.show(p, tntCallbackShow.run(p)); @@ -106,10 +106,6 @@ class TNTTracer_15 { private static float[] noValue = new float[0]; private static void update(Player p, PlayerTraceCache_15 traceCache) { - if (!tracerCallbackTracing.run(p) && traceCache.nearLastLocation(p)) { - return; - } - float[] floats = tracerCallbackPositions.run(p); if (floats.length == 0 || floats.length % 3 != 0) { traceCache.setPositions(noValue); diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java new file mode 100644 index 0000000..8000f2f --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java @@ -0,0 +1,23 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.bausystem.tracer.showcallback.TNTCallbackCacheUpdate; +import de.steamwar.bausystem.tracer.updatecallback.TracerCallbackTracing; +import org.bukkit.entity.Player; + +public class TracerUpdateManager { + + private TracerCallbackTracing tracerCallbackTracing; + private TNTCallbackCacheUpdate tntCallbackCacheUpdate; + + public TracerUpdateManager(TracerCallbackTracing tracerCallbackTracing, TNTCallbackCacheUpdate tntCallbackCacheUpdate) { + this.tracerCallbackTracing = tracerCallbackTracing; + this.tntCallbackCacheUpdate = tntCallbackCacheUpdate; + } + + boolean run(Player p, boolean nearLastLocation) { + if (tntCallbackCacheUpdate.run(p)) return false; + if (!tracerCallbackTracing.run(p) && nearLastLocation) return false; + return true; + } + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java deleted file mode 100644 index 223249c..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerUpdateManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.steamwar.bausystem.tracer.updatecallback; - -public class TracerUpdateManager { - - public TracerUpdateManager() { - - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index 8137898..4391181 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -45,12 +45,12 @@ public class TNTTracer15 { private static final float[] noValue = new float[0]; public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, p -> ShowManager.get(p).isDirty(), TNTTracer15::getActionBar, TNTTracer15::showMode, p -> { + TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, new TracerUpdateManager(p -> ShowManager.get(p).isDirty(), p -> { if (System.currentTimeMillis() - lastExplosion < 4500) { ShowManager.get(p).dirty(); } return System.currentTimeMillis() - lastExplosion < 4500; - }); + })); } private static float[] accumulate(LinkedList traces) { From c1ec555838d0dd18a8f78fb066ad7f87ba29a363 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 25 Jul 2020 21:36:42 +0200 Subject: [PATCH 15/20] Fix Trace show/hide Bug --- .../src/de/steamwar/bausystem/commands/CommandTrace.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 70bea5d..2f6ae1f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -133,6 +133,7 @@ public class CommandTrace implements CommandExecutor { case "particle": case "particles": TNTTracer15.hideBlockTraces(player); + ShowManager.get(player).show(); ShowManager.get(player).setShowMode(ShowStatus.ShowMode.PARTICLE); break; default: From e0b885ad320ac1a3e50c5526aefea66b276e9ada Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 25 Jul 2020 21:44:41 +0200 Subject: [PATCH 16/20] Fix Trace show/hide Bug --- .../bausystem/tracer/PlayerTraceCache_15.java | 17 +++++++++++++++-- .../bausystem/commands/CommandTrace.java | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java index 922cc31..1af3c95 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java @@ -25,6 +25,11 @@ public class PlayerTraceCache_15 { private boolean hiding = false; + private PlayerTraceCache_15 instance; + { + instance = this; + } + public PlayerTraceCache_15() { this.pLocation = new float[]{0.0F, 0.0F, 0.0F}; } @@ -52,7 +57,14 @@ public class PlayerTraceCache_15 { } public void show(Player player, TNTCallbackShow.ShowMode showMode) { - if (hiding) return; + if (hiding) { + try { + instance.wait(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + if (hiding) return; + } if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { float x = positions[i + 0]; @@ -86,7 +98,7 @@ public class PlayerTraceCache_15 { } } - public synchronized void hide(Player player) { + public void hide(Player player) { hiding = true; if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { @@ -107,6 +119,7 @@ public class PlayerTraceCache_15 { } updatePoints = new float[0]; hiding = false; + instance.notifyAll(); } private static void showCorner(Player player, float x, float y, float z, Particle particle) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 2f6ae1f..70bea5d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -133,7 +133,6 @@ public class CommandTrace implements CommandExecutor { case "particle": case "particles": TNTTracer15.hideBlockTraces(player); - ShowManager.get(player).show(); ShowManager.get(player).setShowMode(ShowStatus.ShowMode.PARTICLE); break; default: From 03683fc0b67d3f2264b58c2884ba3bed2121c15e Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 25 Jul 2020 21:55:23 +0200 Subject: [PATCH 17/20] Rename hide() -> hideBlockTraces() --- .../bausystem/tracer/PlayerTraceCache_15.java | 17 ++--------------- .../steamwar/bausystem/tracer/TNTTracer_15.java | 5 ++--- .../bausystem/commands/CommandTrace.java | 4 ++-- .../steamwar/bausystem/tracer/TNTTracer15.java | 2 +- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java index 1af3c95..15d6689 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java @@ -25,11 +25,6 @@ public class PlayerTraceCache_15 { private boolean hiding = false; - private PlayerTraceCache_15 instance; - { - instance = this; - } - public PlayerTraceCache_15() { this.pLocation = new float[]{0.0F, 0.0F, 0.0F}; } @@ -57,14 +52,7 @@ public class PlayerTraceCache_15 { } public void show(Player player, TNTCallbackShow.ShowMode showMode) { - if (hiding) { - try { - instance.wait(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - if (hiding) return; - } + if (hiding) return; if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { float x = positions[i + 0]; @@ -98,7 +86,7 @@ public class PlayerTraceCache_15 { } } - public void hide(Player player) { + public void hideBlockTraces(Player player) { hiding = true; if (positions.length == 0 || positions.length % 3 != 0) return; for (int i = 0; i < positions.length; i += 3) { @@ -119,7 +107,6 @@ public class PlayerTraceCache_15 { } updatePoints = new float[0]; hiding = false; - instance.notifyAll(); } private static void showCorner(Player player, float x, float y, float z, Particle particle) { diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index fd1c2e8..527822c 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -1,7 +1,6 @@ package de.steamwar.bausystem.tracer; import de.steamwar.bausystem.tracer.debugcallback.DebugCallbackActionBar; -import de.steamwar.bausystem.tracer.showcallback.TNTCallbackCacheUpdate; import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; import de.steamwar.bausystem.tracer.updatecallback.*; import net.md_5.bungee.api.ChatMessageType; @@ -158,10 +157,10 @@ class TNTTracer_15 { return result; } - static void hide(Player p) { + static void hideBlockTraces(Player p) { PlayerTraceCache_15 tracerCache15 = playerMap.get(p); if (tracerCache15 == null) return; - tracerCache15.hide(p); + tracerCache15.hideBlockTraces(p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 70bea5d..fdaa94e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -141,7 +141,7 @@ public class CommandTrace implements CommandExecutor { ShowManager.get(player).addSelection(tntID); player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " angezeigt"); player.sendMessage(BauSystem.PREFIX + "§eBei zu vielen zu zeigenden Positionen wird der Block Tracer aktiviert"); - player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen"); + // player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen"); } catch (NumberFormatException e) { help15(player); } @@ -151,7 +151,7 @@ public class CommandTrace implements CommandExecutor { ShowManager.get(player).show(); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); player.sendMessage(BauSystem.PREFIX + "§eBei zu vielen zu zeigenden Positionen wird der Block Tracer aktiviert"); - player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen"); + // player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen"); break; case "hide": if (args.length == 2) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java index 4391181..3b7ca60 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java @@ -302,7 +302,7 @@ public class TNTTracer15 { } public static void hideBlockTraces(Player p) { - TNTTracer_15.hide(p); + TNTTracer_15.hideBlockTraces(p); } public static void start() { From 8aee883a8ee63132fbfbf1b91f0ebb688a246736 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 26 Jul 2020 16:29:16 +0200 Subject: [PATCH 18/20] Remove Logger --- .../src/de/steamwar/bausystem/BauSystem.java | 32 ++++++++++--------- .../bausystem/tracer/trace/ShowStatus.java | 13 -------- .../bausystem/tracer/trace/TNTFrame.java | 2 -- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 16a81d8..e2610d2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -265,51 +265,53 @@ public class BauSystem extends JavaPlugin implements Listener { attachment.setPermission("worldedit.calc", true); attachment.setPermission("worldedit.fill", true);*/ - if (Core.getVersion() == 15) ShowManager.add(p); + if (Core.getVersion() == 15) { + ShowManager.add(p); + } } @EventHandler public void onLeave(PlayerQuitEvent e) { - Player player = e.getPlayer(); - SWScoreboard.removeScoreboard(player); - if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player))) { + Player p = e.getPlayer(); + SWScoreboard.removeScoreboard(p); + if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) { Bukkit.shutdown(); return; } - if (Core.getVersion() == 15) ShowManager.remove(e.getPlayer()); + if (Core.getVersion() == 15) { + ShowManager.remove(p); + } } @EventHandler public void onInventoryClick(InventoryClickEvent e) { ItemStack stack = e.getCursor(); - if (stack == null) - return; - if (!stack.hasItemMeta()) - return; + if (stack == null) return; + if (!stack.hasItemMeta()) return; if (stack.getItemMeta().hasEnchants()) { for (Enchantment en : Enchantment.values()) { if (stack.getEnchantmentLevel(en) > en.getMaxLevel()) stack.removeEnchantment(en); } } - Player p = (Player) e.getWhoClicked(); Material material = stack.getType(); - if (material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION) + if (material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION) { stack.setType(Material.MILK_BUCKET); + } - if(Core.getVersion() < 14){ + if (Core.getVersion() < 14) { e.setCurrentItem(stack); return; } if (stack.getItemMeta().hasAttributeModifiers()) { ItemMeta meta = stack.getItemMeta(); - for (Attribute a : Attribute.values()) - meta.removeAttributeModifier(a); + for (Attribute a : Attribute.values()) { + meta.removeAttributeModifier(a); + } stack.setItemMeta(meta); - Bukkit.getLogger().log(Level.SEVERE, "Spieler " + p.getName() + " (" + p.getUniqueId().toString() + ") hat versucht ein Item mit einem Attribute-Modifier zu bekommen."); } e.setCurrentItem(stack); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java index c28e118..72fdd96 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java @@ -39,21 +39,8 @@ public class ShowStatus { PARTICLE } - public boolean toggleShow() { - dirty = true; - if (show == Show.NONE) { - show = Show.ALL; - return true; - } else { - selected.clear(); - show = Show.NONE; - return false; - } - } - public boolean toggleShow(int tntID) { dirty = true; - if (show == Show.ALL) { removeSelection(tntID); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java index 11301aa..667e8c8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java @@ -15,7 +15,6 @@ public class TNTFrame { private static int uniqueIdentifier = 0; private long startTime = System.currentTimeMillis(); - private long endTime = System.currentTimeMillis(); private Map positions = new HashMap<>(); private Map aliveTNT = new HashMap<>(); @@ -87,7 +86,6 @@ public class TNTFrame { entry.getValue().cleanUp(); delete(entry.getKey(), false); } - endTime = System.currentTimeMillis(); aliveTNT.clear(); aliveTNT = null; return positions.isEmpty(); From b13dcc57a10932380406fb06b2fceb633747b0b7 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 30 Aug 2020 02:23:23 +0200 Subject: [PATCH 19/20] Update Tracer --- .../bausystem/tracer/TNTTracer_12.java | 235 +++------ .../bausystem/tracer/PlayerTraceCache_15.java | 152 ------ .../bausystem/tracer/TNTTracer_15.java | 147 ++---- .../steamwar/bausystem/tracer/TraceCache.java | 126 +++++ .../steamwar/bausystem/tracer/TraceUtils.java | 48 ++ .../bausystem/tracer/TracerUpdateManager.java | 23 - .../bausystem/tracer/TracerUpdater.java | 21 + .../debugcallback/DebugCallbackActionBar.java | 8 - .../showcallback/TNTCallbackCacheUpdate.java | 10 - .../tracer/showcallback/TNTCallbackShow.java | 15 - .../TracerCallbackPositions.java | 10 - .../updatecallback/TracerCallbackTracing.java | 10 - .../TracerCallbackUpdatePoints.java | 10 - .../src/de/steamwar/bausystem/BauSystem.java | 30 +- .../bausystem/commands/CommandTrace.java | 208 +------- .../commands/CommandTraceTabCompleter.java | 34 +- .../steamwar/bausystem/tracer/MoveEvent.java | 17 + .../bausystem/tracer/TNTListener.java | 28 +- .../steamwar/bausystem/tracer/TNTTracer.java | 83 +++ .../bausystem/tracer/TNTTracer12.java | 82 --- .../bausystem/tracer/TNTTracer15.java | 486 ------------------ .../bausystem/tracer/TraceActionbar.java | 52 ++ .../bausystem/tracer/TraceSidebar.java | 22 + .../tracer/manager/FrameManager.java | 51 ++ .../bausystem/tracer/manager/IDManager.java | 11 + .../bausystem/tracer/manager/ShowManager.java | 336 ++++++++++++ .../bausystem/tracer/manager/TNTManager.java | 33 ++ .../tracer/manager/TraceManager.java | 59 +++ .../tracer/recorder/RecordManager.java | 141 +++++ .../tracer/recorder/TNTRecorder.java | 51 ++ .../bausystem/tracer/trace/ShowManager.java | 49 -- .../bausystem/tracer/trace/ShowStatus.java | 149 ------ .../bausystem/tracer/trace/TNTFrame.java | 98 ---- .../bausystem/tracer/trace/TNTTrace.java | 82 ++- .../bausystem/world/BauScoreboard.java | 53 +- 35 files changed, 1307 insertions(+), 1663 deletions(-) delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/TraceCache.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/TraceUtils.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdater.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/MoveEvent.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceActionbar.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceSidebar.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/FrameManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/IDManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/ShowManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TNTManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TraceManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 9b28cdc..83c77b7 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -1,196 +1,95 @@ package de.steamwar.bausystem.tracer; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.material.Step; +import org.bukkit.plugin.Plugin; import java.util.*; @SuppressWarnings("deprecation") class TNTTracer_12 { + private TNTTracer_12(){} - private static final byte BRICK_STEP = new Step(Material.BRICK).getData(); - private static final byte INVERTED_BRICK_STEP = (byte)(BRICK_STEP + 8); - private static final World world = Bukkit.getWorlds().get(0); + private static TracerUpdater tracerUpdater; + private static TraceCache traceCache = new TraceCache(); - static void remove(Map> locations, TNTPrimed tnt){ - Material material = tnt.getLocation().getBlock().getType(); - if(material == Material.WATER || material == Material.STATIONARY_WATER) - locations.remove(tnt); + private static boolean actionBar = true; + + private static class Synchronizer {} + private static final Synchronizer synchronizer = new Synchronizer(); + + private static World world; + static void worldInit() { + if (world != null) return; + world = Bukkit.getWorlds().get(0); } - static int show(Map> locations, Set printedLocs){ - - for(LinkedList tntTrace : locations.values()){ - if(tntTrace.size() == 1) - printLocation(tntTrace.getFirst(), printedLocs); - else if(tntTrace.size() > 1) - interpolate(tntTrace, printedLocs); - } - locations.clear(); - return printedLocs.size(); - } - - static boolean airOrBrick(Block block){ - Material material = block.getType(); - if(material == Material.AIR || material == Material.BRICK) - return true; - if(material != Material.STEP) - return false; - - byte data = block.getData(); - return data == BRICK_STEP || data == INVERTED_BRICK_STEP; - } - - private static void interpolate(LinkedList trace, Set printedLocs){ - ListIterator it = trace.listIterator(); - Location previous = it.next(); - printLocation(previous, printedLocs); - while(it.hasNext()){ - Location actual = it.next(); - Set xSteps = getSteps(previous.getX(), actual.getX()); - Set ySteps = getSteps(previous.getY(), actual.getY()); - Set zSteps = getSteps(previous.getZ(), actual.getZ()); - for(double y : ySteps) - printLocation(new Location(world, previous.getX(), y, previous.getZ()), printedLocs); - for(double x : xSteps) - printLocation(new Location(world, x, actual.getY(), previous.getZ()), printedLocs); - for(double z : zSteps) - printLocation(new Location(world, actual.getX(), actual.getY(), z), printedLocs); - previous = actual; - } - } - - private static Set getSteps(double previous, double actual){ - Set steps = new HashSet<>(); - if(actual < previous){ - double temp = previous; - previous = actual; - actual = temp; - } - - steps.add(actual); - steps.add(previous); - double iterator = previous; - while(actual - iterator > 1){ - iterator++; - steps.add(iterator); - } - return steps; - } - private static void printLocation(Location l, Set printedLocs){ - Block block = l.getBlock(); - double rx = l.getX() - Math.floor(l.getX()); - double ry = l.getY() - Math.floor(l.getY()); - double rz = l.getZ() - Math.floor(l.getZ()); - BlockStatus main; - BlockStatus upper; - if(ry <= 0.02){ - main = BlockStatus.BLOCK; - upper = BlockStatus.NONE; - }else if(ry <= 0.5){ - main = BlockStatus.BLOCK; - upper = BlockStatus.SLAB; - }else if(ry <= 0.52){ - main = BlockStatus.INVERTED_SLAB; - upper = BlockStatus.SLAB; - }else{ - main = BlockStatus.INVERTED_SLAB; - upper = BlockStatus.BLOCK; - } - - Block nearX = null; - Block nearZ = null; - Block nearCross = null; - if(rx < 0.48){ - nearX = block.getRelative(BlockFace.WEST); - if(rz < 0.48){ - nearZ = block.getRelative(BlockFace.NORTH); - nearCross = block.getRelative(BlockFace.NORTH_WEST); - }else if(rz > 0.52){ - nearZ = block.getRelative(BlockFace.SOUTH); - nearCross = block.getRelative(BlockFace.SOUTH_WEST); + static void init(Plugin plugin, TracerUpdater tracerUpdater) { + Bukkit.getScheduler().runTaskTimer(plugin, () -> { + synchronized (synchronizer) { + synchronizer.notifyAll(); } - }else if(rx > 0.52){ - nearX = block.getRelative(BlockFace.EAST); - if(rz < 0.48){ - nearZ = block.getRelative(BlockFace.NORTH); - nearCross = block.getRelative(BlockFace.NORTH_EAST); - }else if(rz > 0.52){ - nearZ = block.getRelative(BlockFace.SOUTH); - nearCross = block.getRelative(BlockFace.SOUTH_EAST); + }, 1, 20); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + while (true) { + synchronized (synchronizer) { + try { + synchronizer.wait(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + run(); } - }else{ - if(rz < 0.48){ - nearZ = block.getRelative(BlockFace.NORTH); - }else if(rz > 0.52){ - nearZ = block.getRelative(BlockFace.SOUTH); - } - } + }); - setBlock(block, main, printedLocs); - setBlock(block.getRelative(BlockFace.UP), upper, printedLocs); - if(nearX != null){ - setBlock(nearX, main, printedLocs); - setBlock(nearX.getRelative(BlockFace.UP), upper, printedLocs); - } - if(nearZ != null){ - setBlock(nearZ, main, printedLocs); - setBlock(nearZ.getRelative(BlockFace.UP), upper, printedLocs); - } - if(nearCross != null){ - setBlock(nearCross, main, printedLocs); - setBlock(nearCross.getRelative(BlockFace.UP), upper, printedLocs); + TNTTracer_12.tracerUpdater = tracerUpdater; + } + + private static void run() { + for (Player p : Bukkit.getOnlinePlayers()) { + if (actionBar) { + String actionBar = tracerUpdater.actionBar(p); + p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar)); + } + + boolean dirty = tracerUpdater.needsUpdate(p); + if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) { + continue; + } + Set toHide = traceCache.update(p, tracerUpdater, dirty); + Set toShow = traceCache.get(p); + + hideBlockTraces(toHide, p); + showTraces(toShow, tracerUpdater.getDisplayType(p), p); } } - private static void setBlock(Block block, BlockStatus status, Set printedLocs){ - if(status == BlockStatus.NONE) - return; + private static void hideBlockTraces(Set locs, Player player) { + if (locs.isEmpty()) return; - Material material = block.getType(); - if(material == Material.AIR){ - status.setBlock(block); - printedLocs.add(block.getLocation()); - }else if(material == Material.STEP){ - byte data = block.getData(); - if(data == BRICK_STEP){ - if(status == BlockStatus.BLOCK) - status.setBlock(block); - else if(status == BlockStatus.INVERTED_SLAB) - BlockStatus.BLOCK.setBlock(block); - }else if(data == INVERTED_BRICK_STEP){ - if(status == BlockStatus.BLOCK) - status.setBlock(block); - else if(status == BlockStatus.SLAB) - BlockStatus.BLOCK.setBlock(block); + for (TraceCache.Loc l : locs) { + TraceUtils.hideBlock(player, l.x, l.y - 0.49F, l.z); + } + } + + private static void showTraces(Set locs, TracerUpdater.DisplayMode displayMode, Player player) { + if (locs.isEmpty()) return; + + for (TraceCache.Loc l : locs) { + if (displayMode == TracerUpdater.DisplayMode.Block) { + TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, Material.STAINED_GLASS, (l.updatePoint ? (byte) 5 : (byte) 14)); + } else { + TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY)); } } } - enum BlockStatus{ - NONE(Material.AIR, 0), - BLOCK(Material.BRICK, 0), - SLAB(Material.STEP, BRICK_STEP), - INVERTED_SLAB(Material.STEP, INVERTED_BRICK_STEP); - - - private final Material material; - private final byte data; - - BlockStatus(Material material, int data){ - this.material = material; - this.data = (byte)data; - } - - void setBlock(Block b){ - b.setTypeIdAndData(material.getId(), data, true); - } - } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java deleted file mode 100644 index 15d6689..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java +++ /dev/null @@ -1,152 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.entity.Player; - -import static de.steamwar.bausystem.tracer.TNTTracer_15.square; - -public class PlayerTraceCache_15 { - - private static Location location; - - public static void init() { - location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); - } - - private float[] positions = new float[0]; - private float[] updatePoints = new float[0]; - - private float[] pLocation; - private float locationThreshold = square(10.0F); - - private boolean hiding = false; - - public PlayerTraceCache_15() { - this.pLocation = new float[]{0.0F, 0.0F, 0.0F}; - } - - public void setPositions(float[] positions) { - this.positions = positions; - } - - public void setUpdatePoints(float[] updatePoints) { - this.updatePoints = updatePoints; - } - - public synchronized boolean nearLastLocation(Player player) { - float x = (float)player.getLocation().getX(); - float y = (float)player.getLocation().getY(); - float z = (float)player.getLocation().getZ(); - - if (square(pLocation[0] - x) + square(pLocation[1] - y) + square(pLocation[2] - z) > locationThreshold) { - pLocation[0] = x; - pLocation[1] = y; - pLocation[2] = z; - return true; - } - return false; - } - - public void show(Player player, TNTCallbackShow.ShowMode showMode) { - if (hiding) return; - if (positions.length == 0 || positions.length % 3 != 0) return; - for (int i = 0; i < positions.length; i += 3) { - float x = positions[i + 0]; - float y = positions[i + 1]; - float z = positions[i + 2]; - - if (showMode == TNTCallbackShow.ShowMode.PARTICLE && positions.length / 3 < 1000) { - showCorner(player, x - 0.49F, y, z - 0.49F, Particle.FLAME); - } else { - showBlock(player, x, y + 0.49F, z, Material.RED_STAINED_GLASS, (byte) 14); - } - } - - if (positions.length / 3 >= 1000) { - return; - } - - if (updatePoints.length == 0 || updatePoints.length % 3 != 0) return; - for (int i = 0; i < updatePoints.length; i += 3) { - float x = updatePoints[i + 0]; - float y = updatePoints[i + 1]; - float z = updatePoints[i + 2]; - - if (hasBlock(positions, x, y, z)) continue; - - if (showMode == TNTCallbackShow.ShowMode.PARTICLE) { - showCorner(player, x - 0.49F, y, z - 0.49F, Particle.VILLAGER_HAPPY); - } else { - showBlock(player, x, y + 0.49F, z, Material.LIME_STAINED_GLASS, (byte) 5); - } - } - } - - public void hideBlockTraces(Player player) { - hiding = true; - if (positions.length == 0 || positions.length % 3 != 0) return; - for (int i = 0; i < positions.length; i += 3) { - float x = positions[i + 0]; - float y = positions[i + 1]; - float z = positions[i + 2]; - - hideBlock(player, x, y + 0.49F, z); - } - - if (updatePoints.length == 0 || updatePoints.length % 3 != 0) return; - for (int i = 0; i < updatePoints.length; i += 3) { - float x = updatePoints[i + 0]; - float y = updatePoints[i + 1]; - float z = updatePoints[i + 2]; - - hideBlock(player, x, y + 0.49F, z); - } - updatePoints = new float[0]; - hiding = false; - } - - private static void showCorner(Player player, float x, float y, float z, Particle particle) { - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); - } - - private static void showBlock(Player p, float x, float y, float z, Material block, byte b) { - if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) { - p.sendBlockChange(makeLocation(x, y, z), block, b); - } - } - - private static void hideBlock(Player p, float x, float y, float z) { - if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) { - p.sendBlockChange(makeLocation(x, y, z), Material.AIR, (byte) 0); - } - } - - private static boolean hasBlock(float[] floats, float x, float y, float z) { - for (int i = 0; i < floats.length; i += 3) { - if (square(floats[i + 0] - x) + square(floats[i + 1] - y) + square(floats[i + 2] - z) < 1) { - return true; - } - } - return false; - } - - private static Location makeLocation(float x, float y, float z) { - location.setX(x); - location.setY(y); - location.setZ(z); - return location; - } - -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 527822c..daabfa8 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -1,48 +1,33 @@ package de.steamwar.bausystem.tracer; -import de.steamwar.bausystem.tracer.debugcallback.DebugCallbackActionBar; -import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; -import de.steamwar.bausystem.tracer.updatecallback.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; import org.bukkit.plugin.Plugin; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; +import java.util.Set; +@SuppressWarnings("deprecation") class TNTTracer_15 { private TNTTracer_15(){} - private static TracerCallbackPositions tracerCallbackPositions; - private static TracerCallbackUpdatePoints tracerCallbackUpdatePoints; - private static DebugCallbackActionBar debugCallbackActionBar; - private static TNTCallbackShow tntCallbackShow; - - private static TracerUpdateManager tracerUpdateManager; - - private static Map playerMap = new HashMap<>(); + private static TracerUpdater tracerUpdater; + private static TraceCache traceCache = new TraceCache(); private static boolean actionBar = false; - private static final float showRadius = square(50.0F); - private static class Synchronizer {} - private static final Synchronizer synchronizer = new Synchronizer(); - public static float square(float d) { - return d * d; + private static World world; + static void worldInit() { + if (world != null) return; + world = Bukkit.getWorlds().get(0); } - static void init(Plugin plugin, TracerCallbackPositions tracerCallbackPositions, TracerCallbackUpdatePoints tracerCallbackUpdatePoints, DebugCallbackActionBar debugCallbackActionBar, TNTCallbackShow tntCallbackShow, TracerUpdateManager tracerUpdateManager) { + static void init(Plugin plugin, TracerUpdater tracerUpdater) { Bukkit.getScheduler().runTaskTimer(plugin, () -> { synchronized (synchronizer) { synchronizer.notifyAll(); @@ -61,106 +46,46 @@ class TNTTracer_15 { } }); - TNTTracer_15.tracerCallbackPositions = tracerCallbackPositions; - TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints; - TNTTracer_15.debugCallbackActionBar = debugCallbackActionBar; - TNTTracer_15.tntCallbackShow = tntCallbackShow; - - TNTTracer_15.tracerUpdateManager = tracerUpdateManager; - } - - static void initWorld() { - PlayerTraceCache_15.init(); - } - - static boolean isInWater(TNTPrimed tnt) { - return tnt.getLocation().getBlock().getType() == Material.WATER; + TNTTracer_15.tracerUpdater = tracerUpdater; } private static void run() { - if (actionBar) { - String actionBar = debugCallbackActionBar.run(); - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar))); - } for (Player p : Bukkit.getOnlinePlayers()) { - PlayerTraceCache_15 traceCache; - if (!playerMap.containsKey(p)) { - traceCache = new PlayerTraceCache_15(); - playerMap.put(p, traceCache); - } else { - traceCache = playerMap.get(p); + if (actionBar) { + String actionBar = tracerUpdater.actionBar(p); + p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar)); } - updateShowPlayer(p, traceCache); + boolean dirty = tracerUpdater.needsUpdate(p); + if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) { + continue; + } + Set toHide = traceCache.update(p, tracerUpdater, dirty); + Set toShow = traceCache.get(p); + + hideBlockTraces(toHide, p); + showTraces(toShow, tracerUpdater.getDisplayType(p), p); } } - private static void updateShowPlayer(Player p, PlayerTraceCache_15 traceCache) { - if (tracerUpdateManager.run(p, traceCache.nearLastLocation(p))) { - update(p, traceCache); + private static void hideBlockTraces(Set locs, Player player) { + if (locs.isEmpty()) return; + + for (TraceCache.Loc l : locs) { + TraceUtils.hideBlock(player, l.x, l.y - 0.49F, l.z); } - traceCache.show(p, tntCallbackShow.run(p)); } - private static float[] noValue = new float[0]; + private static void showTraces(Set locs, TracerUpdater.DisplayMode displayMode, Player player) { + if (locs.isEmpty()) return; - private static void update(Player p, PlayerTraceCache_15 traceCache) { - float[] floats = tracerCallbackPositions.run(p); - if (floats.length == 0 || floats.length % 3 != 0) { - traceCache.setPositions(noValue); - traceCache.setUpdatePoints(noValue); - return; + for (TraceCache.Loc l : locs) { + if (displayMode == TracerUpdater.DisplayMode.Block) { + TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, (l.updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS), (l.updatePoint ? (byte) 5 : (byte) 14)); + } else { + TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY)); + } } - - Location location = p.getLocation(); - float px = (float)location.getX(); - float py = (float)location.getY(); - float pz = (float)location.getZ(); - - traceCache.setPositions(accumulatePositions(floats, px, py, pz)); - - floats = tracerCallbackUpdatePoints.run(p); - if (floats.length == 0 || floats.length % 3 != 0) { - traceCache.setUpdatePoints(noValue); - return; - } - - traceCache.setUpdatePoints(accumulatePositions(floats, px, py, pz)); - } - - private static float[] accumulatePositions(float[] floats, float px, float py, float pz) { - if (true) { - return floats; - } - - LinkedList linkedList = new LinkedList<>(); - - for (int i = 0; i < floats.length; i += 3) { - float x = floats[i + 0]; - float y = floats[i + 1]; - float z = floats[i + 2]; - - if (square(x - px) + square(y + 0.49F - py) + square(z - pz) > showRadius) continue; - - linkedList.add(x); - linkedList.add(y); - linkedList.add(z); - } - - float[] result = new float[linkedList.size()]; - Iterator floatIterator = linkedList.iterator(); - int index = 0; - while (floatIterator.hasNext()) { - result[index] = floatIterator.next(); - index++; - } - return result; - } - - static void hideBlockTraces(Player p) { - PlayerTraceCache_15 tracerCache15 = playerMap.get(p); - if (tracerCache15 == null) return; - tracerCache15.hideBlockTraces(p); } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TraceCache.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TraceCache.java new file mode 100644 index 0000000..7634d37 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TraceCache.java @@ -0,0 +1,126 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.Player; + +import java.util.*; + +public class TraceCache { + + private static final Set empty = new HashSet(); + private Map> playerMap = new HashMap<>(); + private Map playerDisplayMap = new HashMap<>(); + + public Set get(Player player) { + return playerMap.getOrDefault(player.getUniqueId().toString(), empty); + } + + public Set update(Player player, TracerUpdater tracerUpdater, boolean dirty) { + if (!dirty) return empty; + String key = player.getUniqueId().toString(); + Set locOld; + TracerUpdater.DisplayMode displayMode; + if (!playerMap.containsKey(key)) { + locOld = new HashSet<>(); + displayMode = tracerUpdater.getDisplayType(player); + } else { + locOld = playerMap.get(key); + displayMode = playerDisplayMap.get(key); + } + + Set locSet = new HashSet<>(); + tracerUpdater.updatePoints(player).forEach(loc -> { + loc.updatePoint = true; + locSet.add(loc); + }); + tracerUpdater.updateLocations(player).forEach(loc -> { + loc.updatePoint = false; + locSet.add(loc); + }); + + playerMap.put(key, locSet); + TracerUpdater.DisplayMode currentMode = tracerUpdater.getDisplayType(player); + playerDisplayMap.put(key, currentMode); + + if (currentMode == TracerUpdater.DisplayMode.Particle && displayMode == TracerUpdater.DisplayMode.Block) return locOld; + if (currentMode == TracerUpdater.DisplayMode.Block) return diff(locOld, locSet); + return empty; + } + + public static class Loc { + public final float x; + public final float y; + public final float z; + + private final float dx; + private final float dy; + private final float dz; + + public boolean updatePoint = false; + + public Loc(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + this.dx = round(x); + this.dy = round(y); + this.dz = round(z); + } + + private static int roundNumber = 10; + private static float round(float toRound) { + float r = (toRound * roundNumber); + float t = r - (int) r; + if (t >= 0.5) { + return (((float)(int)r) + 1) / roundNumber; + } else { + return (((float)(int)r) + 0) / roundNumber; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Loc)) return false; + Loc loc = (Loc) o; + return Float.compare(loc.dx, dx) == 0 && + Float.compare(loc.dy, dy) == 0 && + Float.compare(loc.dz, dz) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(dx, dy, dz); + } + + @Override + public String toString() { + return "Loc{" + + "x=" + x + + ", y=" + y + + ", z=" + z + + '}'; + } + + public boolean remove(Player player, double radius) { + double x = player.getLocation().getX(); + double y = player.getLocation().getY(); + double z = player.getLocation().getZ(); + + double dx = (this.x - x) * (this.x - x); + double dy = (this.y - y) * (this.y - y); + double dz = (this.z - z) * (this.z - z); + + return (dx + dy + dz) > radius * radius; + } + } + + private Set diff(Set locOld, Set locNew) { + if (locOld.isEmpty()) return empty; + if (locNew.isEmpty()) return locOld; + for (Loc l : locNew) { + locOld.remove(l); + } + return locOld; + } + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TraceUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TraceUtils.java new file mode 100644 index 0000000..f867071 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TraceUtils.java @@ -0,0 +1,48 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.entity.Player; + +public class TraceUtils { + + private static Location location; + + public static void locationInit() { + location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); + } + + public static void showCorner(Player player, float x, float y, float z, Particle particle) { + player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); + player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); + player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); + player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); + + player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); + player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001); + player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); + player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001); + } + + public static void showBlock(Player p, float x, float y, float z, Material block, byte b) { + if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) { + p.sendBlockChange(makeLocation(x, y, z), block, b); + } + } + + public static void hideBlock(Player p, float x, float y, float z) { + if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) { + p.sendBlockChange(makeLocation(x, y, z), Material.AIR, (byte) 0); + } + } + + public static Location makeLocation(float x, float y, float z) { + location.setX(x); + location.setY(y); + location.setZ(z); + return location; + } + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java deleted file mode 100644 index 8000f2f..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdateManager.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.tracer.showcallback.TNTCallbackCacheUpdate; -import de.steamwar.bausystem.tracer.updatecallback.TracerCallbackTracing; -import org.bukkit.entity.Player; - -public class TracerUpdateManager { - - private TracerCallbackTracing tracerCallbackTracing; - private TNTCallbackCacheUpdate tntCallbackCacheUpdate; - - public TracerUpdateManager(TracerCallbackTracing tracerCallbackTracing, TNTCallbackCacheUpdate tntCallbackCacheUpdate) { - this.tracerCallbackTracing = tracerCallbackTracing; - this.tntCallbackCacheUpdate = tntCallbackCacheUpdate; - } - - boolean run(Player p, boolean nearLastLocation) { - if (tntCallbackCacheUpdate.run(p)) return false; - if (!tracerCallbackTracing.run(p) && nearLastLocation) return false; - return true; - } - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdater.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdater.java new file mode 100644 index 0000000..efa73aa --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TracerUpdater.java @@ -0,0 +1,21 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.Player; + +import java.util.Set; + +public interface TracerUpdater { + + enum DisplayMode { + Block, + Particle, + } + + Set updateLocations(Player player); + Set updatePoints(Player player); + boolean needsUpdate(Player player); + DisplayMode getDisplayType(Player player); + + String actionBar(Player player); + +} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java deleted file mode 100644 index b6988fb..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/debugcallback/DebugCallbackActionBar.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.steamwar.bausystem.tracer.debugcallback; - -@FunctionalInterface -public interface DebugCallbackActionBar { - - String run(); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java deleted file mode 100644 index d92369f..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackCacheUpdate.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.showcallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TNTCallbackCacheUpdate { - - boolean run(Player p); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java deleted file mode 100644 index fc91355..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/showcallback/TNTCallbackShow.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.steamwar.bausystem.tracer.showcallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TNTCallbackShow { - - public static enum ShowMode { - BLOCK, - PARTICLE - } - - ShowMode run(Player p); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java deleted file mode 100644 index ce1b4ec..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackPositions.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.updatecallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TracerCallbackPositions { - - float[] run(Player p); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java deleted file mode 100644 index e88d073..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackTracing.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.updatecallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TracerCallbackTracing { - - boolean run(Player p); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java deleted file mode 100644 index efe2a20..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/updatecallback/TracerCallbackUpdatePoints.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.updatecallback; - -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface TracerCallbackUpdatePoints { - - float[] run(Player p); - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index e2610d2..dd43f38 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -1,10 +1,16 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; +import de.steamwar.bausystem.tracer.MoveEvent; import de.steamwar.bausystem.tracer.TNTListener; -import de.steamwar.bausystem.tracer.TNTTracer15; -import de.steamwar.bausystem.tracer.trace.ShowManager; -import de.steamwar.bausystem.world.*; +import de.steamwar.bausystem.tracer.TNTTracer; +import de.steamwar.bausystem.tracer.TraceUtils; +import de.steamwar.bausystem.tracer.manager.ShowManager; +import de.steamwar.bausystem.tracer.recorder.RecordManager; +import de.steamwar.bausystem.world.AFKStopper; +import de.steamwar.bausystem.world.ArenaSection; +import de.steamwar.bausystem.world.BauScoreboard; +import de.steamwar.bausystem.world.RegionListener; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; import de.steamwar.scoreboard.SWScoreboard; @@ -97,9 +103,12 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new TNTListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); + Bukkit.getPluginManager().registerEvents(new MoveEvent(), this); new AFKStopper(); if (Core.getVersion() == 15) { - TNTTracer15.initTNTTracer_15(); + TNTTracer.init15(); + } else { + TNTTracer.init12(); } autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); @@ -265,9 +274,11 @@ public class BauSystem extends JavaPlugin implements Listener { attachment.setPermission("worldedit.calc", true); attachment.setPermission("worldedit.fill", true);*/ - if (Core.getVersion() == 15) { - ShowManager.add(p); - } + RecordManager.worldInit(); + TNTTracer.worldInit(); + TraceUtils.locationInit(); + + ShowManager.add(p); } @EventHandler @@ -276,11 +287,6 @@ public class BauSystem extends JavaPlugin implements Listener { SWScoreboard.removeScoreboard(p); if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) { Bukkit.shutdown(); - return; - } - - if (Core.getVersion() == 15) { - ShowManager.remove(p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index fdaa94e..95ac43d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -2,12 +2,10 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.tracer.TNTTracer12; -import de.steamwar.bausystem.tracer.TNTTracer15; -import de.steamwar.bausystem.tracer.trace.ShowManager; -import de.steamwar.bausystem.tracer.trace.ShowStatus; +import de.steamwar.bausystem.tracer.manager.ShowManager; +import de.steamwar.bausystem.tracer.manager.TraceManager; +import de.steamwar.bausystem.tracer.recorder.RecordManager; import de.steamwar.bausystem.world.Welt; -import de.steamwar.core.Core; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -15,38 +13,24 @@ import org.bukkit.entity.Player; public class CommandTrace implements CommandExecutor { - private void help12(Player player) { - player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); - player.sendMessage("§8/§etrace show §8- §7Zeigt alle TNT-Positionen"); - player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); - } - - private void help15(Player player) { + private void help(Player player) { player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen"); player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer"); player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart"); - player.sendMessage("§8/§etrace togglewater §8- §7Tracet auch TNT im Wasser"); player.sendMessage("§8/§etrace show §8<§eblock§8|§eparticle§8|§7TNT-ID§8> §8- §7Zeigt alle TNT-Positionen"); player.sendMessage("§8/§etrace hide §8<§7TNT-ID§8> §8- §7Versteckt alle TNT-Positionen"); player.sendMessage("§8/§etrace toggleshow §8<§7TNT-ID§8> §8- §7Zeigt/Versteckt ein TNT"); player.sendMessage("§8/§etrace delete §8<§7TNT-ID§8> §8- §7Löscht alle TNT-Positionen"); player.sendMessage("§8/§etrace interpolate §8[§eall§8|§eyaxis§8|§enone§8] §8- §7Interpolationsoptionen"); player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf"); - //player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an"); + player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an"); player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return false; - Player player = (Player) sender; - - switch (Core.getVersion()) { - case 15: - return tracer15(player, args); - default: - return tracer12(player, args); - } + return tracer((Player) sender, args); } private boolean permissionCheck(Player player) { @@ -57,189 +41,41 @@ public class CommandTrace implements CommandExecutor { return true; } - private boolean tracer12(Player player, String[] args) { + private boolean tracer(Player player, String[] args) { if(args.length == 0){ - help12(player); + help(player); return false; } if (!permissionCheck(player)) return false; - switch(args[0].toLowerCase()){ + switch (args[0].toLowerCase()) { case "start": - TNTTracer12.start(); - player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); - break; - case "show": - int blocks = TNTTracer12.show(); - player.sendMessage(BauSystem.PREFIX + "§a" + blocks + " TNT-Positionen angezeigt"); - break; case "stop": - TNTTracer12.stop(); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); - break; - default: - help12(player); - } - return false; - } - - private boolean tracer15(Player player, String[] args) { - if(args.length == 0){ - help15(player); - return false; - } - - if (!permissionCheck(player)) return false; - - switch(args[0].toLowerCase()){ - case "start": - if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) { - TNTTracer15.toggleAuto(); - } - TNTTracer15.start(); - player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); - break; - case "stop": - if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) { - TNTTracer15.toggleAuto(); - } - TNTTracer15.stop(); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); - break; case "toggleauto": - boolean mode = TNTTracer15.toggleAuto(); - if (mode) { - player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert"); - } else { - player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert"); - } - break; - case "togglewater": - mode = TNTTracer15.toggleRemoveInWater(); - if (mode) { - player.sendMessage(BauSystem.PREFIX + "§aTraces im Wasser werden gelöscht"); - } else { - player.sendMessage(BauSystem.PREFIX + "§cTraces im Wasser werden behalten"); - } + case "auto": + RecordManager.tracer(player, args); break; case "show": - if (args.length == 2) { - switch (args[1].toLowerCase()) { - case "block": - case "blocks": - ShowManager.get(player).setShowMode(ShowStatus.ShowMode.BLOCK); - break; - case "particle": - case "particles": - TNTTracer15.hideBlockTraces(player); - ShowManager.get(player).setShowMode(ShowStatus.ShowMode.PARTICLE); - break; - default: - try { - int tntID = Integer.parseInt(args[1]); - ShowManager.get(player).addSelection(tntID); - player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " angezeigt"); - player.sendMessage(BauSystem.PREFIX + "§eBei zu vielen zu zeigenden Positionen wird der Block Tracer aktiviert"); - // player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen"); - } catch (NumberFormatException e) { - help15(player); - } - return false; - } - } - ShowManager.get(player).show(); - player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); - player.sendMessage(BauSystem.PREFIX + "§eBei zu vielen zu zeigenden Positionen wird der Block Tracer aktiviert"); - // player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen"); - break; case "hide": - if (args.length == 2) { - try { - int tntID = Integer.parseInt(args[1]); - ShowManager.get(player).removeSelection(tntID); - player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " versteckt"); - } catch (NumberFormatException e) { - help15(player); - } - return false; - } - ShowManager.get(player).hide(); - player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt"); - break; case "toggleshow": - if (args.length == 2) { - try { - int tntID = Integer.parseInt(args[1]); - mode = ShowManager.get(player).toggleShow(tntID); - if (mode) { - player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " angezeigt"); - } else { - player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " versteckt"); - } - } catch (NumberFormatException e) { - help15(player); - } - } else { - help15(player); - } - break; - case "delete": - if (args.length == 2) { - try { - int tntID = Integer.parseInt(args[1]); - ShowManager.removeTrace(tntID); - TNTTracer15.remove(tntID); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + tntID + " gelöscht"); - } catch (NumberFormatException e) { - help15(player); - } - return false; - } - TNTTracer15.clear(); - player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); - break; case "interpolate": - if (args.length != 2) { - help15(player); - return false; - } - switch (args[1].toLowerCase()) { - case "none": - TNTTracer15.hideBlockTraces(player); - ShowManager.get(player).setUpdatePoints(ShowStatus.UpdatePoints.NONE); - player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt"); - break; - case "yaxis": - TNTTracer15.hideBlockTraces(player); - ShowManager.get(player).setUpdatePoints(ShowStatus.UpdatePoints.Y_AXIS); - player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt"); - break; - case "all": - ShowManager.get(player).setUpdatePoints(ShowStatus.UpdatePoints.ALL); - player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt"); - break; - default: - help15(player); - break; + case "distance": + if (ShowManager.tracer(player, args)) { + help(player); } break; case "list": - if (args.length == 2) { - try { - TNTTracer15.printFrames(player, Integer.parseInt(args[1])); - } catch (NumberFormatException e) { - help15(player); - } - return false; - } - TNTTracer15.printList(player); - break; case "gui": - //player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau"); - //break; + // player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau"); + break; + case "delete": + if (TraceManager.delete(player, args)) { + help(player); + } + break; default: - help15(player); + help(player); } return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index cebbd09..14e1c73 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -1,6 +1,6 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.tracer.TNTTracer15; +import de.steamwar.bausystem.tracer.recorder.RecordManager; import de.steamwar.core.Core; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -16,34 +16,18 @@ public class CommandTraceTabCompleter implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - Player player = (Player) sender; - - switch (Core.getVersion()) { - case 15: - return tracer15TabComplete(player, args); - default: - return tracer12TabComplete(player, args); - } + return tracerTabComplete((Player) sender, args); } - private List tracer12TabComplete(Player player, String[] args) { + private List tracerTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); - tabComplete.add("start"); - tabComplete.add("show"); - tabComplete.add("stop"); - - return manageList(tabComplete, args, 0); - } - - private List tracer15TabComplete(Player player, String[] args) { - List tabComplete = new ArrayList<>(); - if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE || TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO) { + if (RecordManager.getStatus() == RecordManager.Status.IDLE || RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) { tabComplete.add("start"); } else { tabComplete.add("stop"); } tabComplete.add("toggleauto"); - tabComplete.add("togglewater"); + tabComplete.add("auto"); tabComplete.add("toggleshow"); tabComplete.add("show"); if (args[0].equalsIgnoreCase("show") && args.length == 2) { @@ -55,10 +39,14 @@ public class CommandTraceTabCompleter implements TabCompleter { if (args[0].equalsIgnoreCase("interpolate") && args.length == 2) { return manageList(new ArrayList<>(Arrays.asList("all", "yaxis", "none")), args, 1); } + tabComplete.add("distance"); + if (args[0].equalsIgnoreCase("distance") && args.length == 2) { + return manageList(new ArrayList<>(Arrays.asList("3", "4", "5", "6", "7", "8", "9", "10", "11", "default")), args, 1); + } //tabComplete.add("gui"); - tabComplete.add("list"); + //tabComplete.add("list"); - if (args.length == 2) { + if (args.length >= 2) { return new ArrayList<>(); } return manageList(tabComplete, args, 0); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/MoveEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/MoveEvent.java new file mode 100644 index 0000000..3cfb0dc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/MoveEvent.java @@ -0,0 +1,17 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.bausystem.tracer.manager.ShowManager; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class MoveEvent implements Listener { + + @EventHandler + public void playerMove(PlayerMoveEvent event) { + Player p = event.getPlayer(); + ShowManager.get(p).move(p); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTListener.java index 04fa1bb..8499435 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTListener.java @@ -1,5 +1,8 @@ package de.steamwar.bausystem.tracer; +import de.steamwar.bausystem.tracer.manager.TNTManager; +import de.steamwar.bausystem.tracer.recorder.RecordManager; +import de.steamwar.bausystem.tracer.recorder.TNTRecorder; import de.steamwar.core.Core; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; @@ -10,16 +13,19 @@ public class TNTListener implements Listener { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { - switch (Core.getVersion()) { - case 15: - onEntityExplode15(event); - break; - default: - onEntityExplode12(event); + if (!(event.getEntity() instanceof TNTPrimed)) return; + + if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) { + RecordManager.startAuto(); } + if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO) { + RecordManager.updateAuto(); + } + + TNTManager.explode((TNTPrimed) event.getEntity()); } - private void onEntityExplode12(EntityExplodeEvent event) { + /*private void onEntityExplode12(EntityExplodeEvent event) { if(TNTTracer12.getStatus() != TNTTracer12.Status.RECORD) return; if(!(event.getEntity() instanceof TNTPrimed)) return; TNTPrimed entity = (TNTPrimed) event.getEntity(); @@ -28,9 +34,9 @@ public class TNTListener implements Listener { private void onEntityExplode15(EntityExplodeEvent event) { if(!(event.getEntity() instanceof TNTPrimed)) return; - if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) { - TNTTracer15.start(); + if (TraceRecorder.getStatus() == TraceRecorder.Status.IDLE_AUTO || TraceRecorder.getStatus() == TraceRecorder.Status.RECORD_AUTO) { + TraceRecorder.start(); } - TNTTracer15.explode((TNTPrimed) event.getEntity()); - } + TraceRecorder.explode((TNTPrimed) event.getEntity()); + }*/ } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java new file mode 100644 index 0000000..3d77d5e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java @@ -0,0 +1,83 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.manager.ShowManager; +import de.steamwar.bausystem.tracer.trace.TNTTrace; +import de.steamwar.core.Core; +import org.bukkit.entity.Player; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class TNTTracer { + + private static TracerUpdater tracerUpdater = new TracerUpdater() { + @Override + public Set updateLocations(Player player) { + Iterator traces = ShowManager.get(player).getTraces().descendingIterator(); + Set locSet = new HashSet<>(); + while (traces.hasNext()) { + locSet.addAll(traces.next().locs()); + } + double radius = ShowManager.get(player).getShowRadius(); + locSet.removeIf(loc -> loc.remove(player, radius)); + return locSet; + } + + @Override + public Set updatePoints(Player player) { + Iterator traces = ShowManager.get(player).getTraces().descendingIterator(); + Set locSet = new HashSet<>(); + while (traces.hasNext()) { + locSet.addAll(traces.next().locsUpdate(ShowManager.get(player).getDisplayMode())); + } + double radius = ShowManager.get(player).getShowRadius(); + locSet.removeIf(loc -> loc.remove(player, radius)); + return locSet; + } + + @Override + public boolean needsUpdate(Player player) { + return ShowManager.get(player).isDirty(); + } + + @Override + public DisplayMode getDisplayType(Player player) { + switch (ShowManager.get(player).getDisplayType()) { + case Block: + return DisplayMode.Block; + case Particle: + return DisplayMode.Particle; + default: + break; + } + return DisplayMode.Particle; + } + + @Override + public String actionBar(Player player) { + return TraceActionbar.traceMemory() + " " + TraceActionbar.traceSize() + " " + TraceActionbar.showRadius(player); + } + }; + + public static void init15() { + TNTTracer_15.init(BauSystem.getPlugin(), tracerUpdater); + } + + public static void init12() { + TNTTracer_12.init(BauSystem.getPlugin(), tracerUpdater); + } + + public static void worldInit() { + switch (Core.getVersion()) { + case 15: + TNTTracer_15.worldInit(); + break; + default: + TNTTracer_12.worldInit(); + break; + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java deleted file mode 100644 index 8d02563..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer12.java +++ /dev/null @@ -1,82 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.core.Core; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.scheduler.BukkitTask; - -import java.util.*; - -public class TNTTracer12 { - - private static BukkitTask task; - private static final Set printedLocs = new HashSet<>(); - private static final Map> locations = new HashMap<>(); - private static final World world = Bukkit.getWorlds().get(0); - - static Status getStatus() { - return status; - } - - private static Status status = Status.IDLE; - - static void remove(TNTPrimed tnt){ - TNTTracer_12.remove(locations, tnt); - } - - public static void start() { - if(status == Status.RECORD) - return; - stop(); - locations.clear(); - - status = Status.RECORD; - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer12::run, 1, 1); - } - - public static int show() { - if(status == Status.SHOW) - return printedLocs.size(); - stop(); - status = Status.SHOW; - - return TNTTracer_12.show(locations, printedLocs); - } - - public static void stop() { - status = Status.IDLE; - if(task != null) - task.cancel(); - - for(Location l : printedLocs){ - Block b = world.getBlockAt(l); - if(airOrBrick(b)) - b.setType(Material.AIR); - } - printedLocs.clear(); - } - - private static boolean airOrBrick(Block block){ - return TNTTracer_12.airOrBrick(block); - } - - private static void run() { - world.getEntities() - .stream() - .filter(e -> e instanceof TNTPrimed) - .map(e -> (TNTPrimed)e) - .forEach(tnt -> locations.computeIfAbsent(tnt, k -> new LinkedList<>()).add(tnt.getLocation())); - } - - enum Status{ - RECORD, - SHOW, - IDLE - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java deleted file mode 100644 index 3b7ca60..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer15.java +++ /dev/null @@ -1,486 +0,0 @@ -package de.steamwar.bausystem.tracer; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow; -import de.steamwar.bausystem.tracer.trace.ShowManager; -import de.steamwar.bausystem.tracer.trace.ShowStatus; -import de.steamwar.bausystem.tracer.trace.TNTFrame; -import de.steamwar.bausystem.tracer.trace.TNTTrace; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.scheduler.BukkitTask; - -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - -public class TNTTracer15 { - - private static BukkitTask task; - private static long current = System.currentTimeMillis(); - - private static boolean removeInWater = true; - private static long lastExplosion = System.currentTimeMillis(); - - private static World world; - public static void worldInit() { - if (world != null) return; - world = Bukkit.getWorlds().get(0); - TNTTracer_15.initWorld(); - } - - private static LinkedList tntFrames = new LinkedList<>(); - - public static TNTTracer15.Status getStatus() { - return status; - } - - private static TNTTracer15.Status status = Status.IDLE; - private static final float[] noValue = new float[0]; - - public static void initTNTTracer_15() { - TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, new TracerUpdateManager(p -> ShowManager.get(p).isDirty(), p -> { - if (System.currentTimeMillis() - lastExplosion < 4500) { - ShowManager.get(p).dirty(); - } - return System.currentTimeMillis() - lastExplosion < 4500; - })); - } - - private static float[] accumulate(LinkedList traces) { - Map locations = new HashMap<>(); - Iterator traceIterator = traces.iterator(); - while (traceIterator.hasNext()) { - float[] positions = traceIterator.next().getPositions(); - for (int i = 0; i < positions.length; i += 3) { - float x = positions[i + 0]; - float y = positions[i + 1]; - float z = positions[i + 2]; - locations.computeIfAbsent(round(x) + ":" + round(y) + ":" + round(z), t -> new float[]{x, y, z}); - } - } - - float[] floats = new float[locations.size() * 3]; - int index = 0; - for (Map.Entry entry : locations.entrySet()) { - floats[index + 0] = entry.getValue()[0]; - floats[index + 1] = entry.getValue()[1]; - floats[index + 2] = entry.getValue()[2]; - index += 3; - } - return floats; - } - - private static float[] accumulateInterpolate(LinkedList traces, ShowStatus.UpdatePoints updatePoints) { - Map locations = new HashMap<>(); - Iterator traceIterator = traces.iterator(); - while (traceIterator.hasNext()) { - float[] positions = interpolate(traceIterator.next().getPositions(), updatePoints); - for (int i = 0; i < positions.length; i += 3) { - float x = positions[i + 0]; - float y = positions[i + 1]; - float z = positions[i + 2]; - locations.computeIfAbsent(round(x) + ":" + round(y) + ":" + round(z), t -> new float[]{x, y, z}); - } - } - - float[] floats = new float[locations.size() * 3]; - int index = 0; - for (Map.Entry entry : locations.entrySet()) { - floats[index + 0] = entry.getValue()[0]; - floats[index + 1] = entry.getValue()[1]; - floats[index + 2] = entry.getValue()[2]; - index += 3; - } - return floats; - } - - private static float[] getTracePoints(Player p) { - ShowStatus showStatus = ShowManager.get(p); - if (showStatus.getShow() == ShowStatus.Show.NONE) return noValue; - if (showStatus.getShow() == ShowStatus.Show.ALL) { - return getAllTraces(); - } - LinkedList selection = showStatus.getSelection(); - - Iterator frameIterator = tntFrames.iterator(); - LinkedList traces = new LinkedList<>(); - while (frameIterator.hasNext()) { - traces.addAll(frameIterator.next().getTraces(selection)); - } - - return accumulate(traces); - } - - private static float[] getAllTraces() { - Iterator frameIterator = tntFrames.iterator(); - LinkedList traces = new LinkedList<>(); - while (frameIterator.hasNext()) { - traces.addAll(frameIterator.next().getTraces()); - } - - return accumulate(traces); - } - - private static float[] getTraceUpdatePoints(Player p) { - ShowStatus showStatus = ShowManager.get(p); - if (showStatus.getShow() == ShowStatus.Show.NONE) return noValue; - if (showStatus.getShow() == ShowStatus.Show.ALL) { - return getTraceUpdatePointsAll(showStatus); - } - if (showStatus.getUpdatePoints() == ShowStatus.UpdatePoints.NONE) return noValue; - LinkedList selection = showStatus.getSelection(); - - Iterator frameIterator = tntFrames.iterator(); - LinkedList traces = new LinkedList<>(); - while (frameIterator.hasNext()) { - traces.addAll(frameIterator.next().getTraces(selection)); - } - - return accumulateInterpolate(traces, showStatus.getUpdatePoints()); - } - - private static float[] getTraceUpdatePointsAll(ShowStatus showStatus) { - if (showStatus.getUpdatePoints() == ShowStatus.UpdatePoints.NONE) return noValue; - Iterator frameIterator = tntFrames.iterator(); - LinkedList traces = new LinkedList<>(); - while (frameIterator.hasNext()) { - traces.addAll(frameIterator.next().getTraces()); - } - - return accumulateInterpolate(traces, showStatus.getUpdatePoints()); - } - - private static int roundValue = 100; - - private static float round(float toRound) { - float r = (toRound * roundValue); - if (r - (int)r >= 0.5) { - return (((float)(int)r) + 1) / roundValue; - } else { - return (((float)(int)r) + 0) / roundValue; - } - } - - private static double round(double toRound, int digits) { - int x = (int)Math.pow(10, digits); - - double r = (toRound * x); - double t = r - (int) r; - - if (t >= 0.5) { - return (((double)(int)r) + 1) / x; - } else { - return (((double)(int)r) + 0) / x; - } - } - - private static String getActionBar() { - StringBuilder st = new StringBuilder(); - st.append("§7Frames: §e").append(tntFrames.size()).append(" "); - int traces = calcTraces(); - st.append("§7Traces: §e").append(traces).append(" "); - st.append("§7RAM: §c").append(round(traces * 32 / 8.0 / 1024 / 1024, 8)).append("MB"); - return st.toString(); - } - - private static int calcTraces() { - int traces = 0; - Iterator frameIterator = tntFrames.iterator(); - while (frameIterator.hasNext()) { - Iterator traceIterator = frameIterator.next().getTraces().iterator(); - while (traceIterator.hasNext()) { - traces += traceIterator.next().realLength(); - } - } - return traces; - } - - private static TNTCallbackShow.ShowMode showMode(Player player) { - if (ShowManager.get(player).getShowMode() == ShowStatus.ShowMode.BLOCK) { - return TNTCallbackShow.ShowMode.BLOCK; - } else { - return TNTCallbackShow.ShowMode.PARTICLE; - } - } - - private static float[] interpolate(float[] floats, ShowStatus.UpdatePoints updatePoints) { - LinkedList linkedList = new LinkedList<>(); - if (floats.length < 6) { - return noValue; - } - for (int i = 0; i < floats.length - 3; i += 3) { - float x1 = floats[i + 0]; - float y1 = floats[i + 1]; - float z1 = floats[i + 2]; - - float x2 = floats[i + 3]; - float y2 = floats[i + 4]; - float z2 = floats[i + 5]; - - if (!isEqual(y2, y1)) { - linkedList.add(x1); - linkedList.add(y2); - linkedList.add(z1); - } - if (updatePoints != ShowStatus.UpdatePoints.ALL) { - continue; - } - if (abs(x2 - x1) > abs(z2 - z1)) { - if (!isEqual(x2, x1)) { - linkedList.add(x2); - linkedList.add(y2); - linkedList.add(z1); - } - } else { - if (!isEqual(z2, z1)) { - linkedList.add(x1); - linkedList.add(y2); - linkedList.add(z2); - } - } - } - return toFloat(linkedList); - } - - private static boolean isEqual(float d1, float d2) { - return TNTTracer_15.square(d2 - d1) < 0.01; - } - - private static float[] toFloat(LinkedList floats) { - float[] value = new float[floats.size()]; - Iterator linkedListIterator = floats.listIterator(); - int index = 0; - while (linkedListIterator.hasNext()) { - value[index] = linkedListIterator.next(); - index++; - } - return value; - } - - private static float abs(float x) { - return x < 0 ? -x : x; - } - - static void explode(TNTPrimed tntPrimed) { - if (tntFrames.isEmpty()) return; - if (System.currentTimeMillis() - lastExplosion > 4500) { - ShowManager.dirty(); - } - lastExplosion = System.currentTimeMillis(); - tntFrames.getLast().explode(tntPrimed); - } - - public static boolean isInWater(TNTPrimed tntPrimed) { - return TNTTracer_15.isInWater(tntPrimed) && removeInWater; - } - - public static boolean toggleRemoveInWater() { - removeInWater = !removeInWater; - return removeInWater; - } - - public static void clear() { - if (status == Status.RECORD || status == Status.RECORD_AUTO) { - stop(); - } - tntFrames.clear(); - ShowManager.removeAllTraces(); - } - - public static void remove(int tntID) { - Iterator frameIterator = tntFrames.iterator(); - while (frameIterator.hasNext()) { - frameIterator.next().remove(tntID); - } - } - - public static void hideBlockTraces(Player p) { - TNTTracer_15.hideBlockTraces(p); - } - - public static void start() { - if (status == Status.IDLE || status == Status.IDLE_AUTO) { - if (status == Status.IDLE) { - status = Status.RECORD; - } else { - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet"))); - status = Status.RECORD_AUTO; - } - tntFrames.addLast(new TNTFrame()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer15::run, 1, 1); - current = System.currentTimeMillis(); - run(); - } - if (status == Status.RECORD_AUTO) { - current = System.currentTimeMillis(); - } - } - - public static void stop() { - if (status == Status.IDLE || status == Status.IDLE_AUTO) { - return; - } - if (status == Status.RECORD) { - status = Status.IDLE; - } - if (status == Status.RECORD_AUTO) { - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt"))); - status = Status.IDLE_AUTO; - } - ShowManager.dirty(); - if (task != null) task.cancel(); - if (tntFrames.getLast().finish()) { - tntFrames.removeLast(); - } - } - - public static boolean toggleAuto() { - if (status == Status.IDLE) { - status = Status.IDLE_AUTO; - return true; - } - if (status == Status.RECORD) { - status = Status.RECORD_AUTO; - current = System.currentTimeMillis(); - return true; - } - if (status == Status.IDLE_AUTO) { - status = Status.IDLE; - return false; - } - if (status == Status.RECORD_AUTO) { - status = Status.RECORD; - return false; - } - return false; - } - - private static void run() { - if (status == Status.RECORD_AUTO && System.currentTimeMillis() - current > 4500) { - stop(); - } - tntFrames.getLast().add(world.getEntities() - .stream() - .filter(e -> e instanceof TNTPrimed) - .map(e -> (TNTPrimed)e) - ); - } - - private static String format(long time) { - return new SimpleDateFormat("HH:mm:ss").format(new Date(time)); - } - - private static long calcTick(long startTime, long time) { - return (time - startTime) / 50; - } - - private static String format(long startTime, long time, int length) { - return calcTick(startTime, time) + "-" + (calcTick(startTime, time) + length); - } - - private static String format(int length, int uniqueID) { - if (length == 0) { - return uniqueID + ""; - } - return repeat(length - (int)Math.log10(uniqueID) - 1) + uniqueID; - } - - private static String repeat(int length) { - StringBuilder st = new StringBuilder(); - for (int i = 0; i < length; i++) st.append('0'); - return st.toString(); - } - - public static void printFrames(Player player, int uniqueID) { - Iterator frameIterator = tntFrames.iterator(); - LinkedList integerList = ShowManager.get(player).getSelection(); - TNTFrame tntFrame = null; - while (frameIterator.hasNext()) { - TNTFrame frame = frameIterator.next(); - if (frame.getUniqueID() == uniqueID) { - tntFrame = frame; - break; - } - } - if (tntFrame == null) { - player.sendMessage("§cUnbekannte Aufnahme"); - return; - } - - player.sendMessage(""); - player.sendMessage("§eAufnahme §7aufgenommen um §e" + format(tntFrame.getStartTime()) + " §7mit §a" + tntFrame.getTraces().size() + " TNT"); - int length = (int)Math.log10(tntFrame.getTraces().getLast().getUniqueID()) + 1; - Iterator traceIterator = tntFrame.getTraces().iterator(); - while (traceIterator.hasNext()) { - TNTTrace tntTrace = traceIterator.next(); - - StringBuilder st = new StringBuilder(); - st.append("§8 "); - if (integerList.contains(tntTrace.getUniqueID()) || ShowManager.get(player).getShow() == ShowStatus.Show.ALL) st.append("§a"); - else st.append("§c"); - st.append(format(length, tntTrace.getUniqueID())).append(" §eTick: ").append(format(tntFrame.getStartTime(), tntTrace.getStartTime(), tntTrace.length())); - - TextComponent textComponent = new TextComponent(); - textComponent.setText(st.toString()); - textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Zeigt die Positionen dieses TNT's an"))); - textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace toggleshow " + tntTrace.getUniqueID())); - player.spigot().sendMessage(textComponent); - } - } - - public static void printList(Player player) { - if (tntFrames.isEmpty()) { - player.sendMessage("§cKeine Aufnahme vorhanden"); - return; - } - Iterator frameIterator = tntFrames.iterator(); - while (frameIterator.hasNext()) { - TNTFrame tntFrame = frameIterator.next(); - - TextComponent textComponent = new TextComponent(); - textComponent.setText("§eAufnahme §7aufgenommen um §e" + format(tntFrame.getStartTime()) + " §7mit §a" + tntFrame.getTraces().size() + " TNT"); - textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Zeige die TNT dieser Aufnahme an"))); - textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace list " + tntFrame.getUniqueID())); - player.spigot().sendMessage(textComponent); - } - } - - public static LinkedList allTraces() { - LinkedList allTraces = new LinkedList<>(); - Iterator frameIterator = tntFrames.iterator(); - while (frameIterator.hasNext()) { - TNTFrame tntFrame = frameIterator.next(); - allTraces.addAll(tntFrame.getTraces().stream().map(TNTTrace::getUniqueID).collect(Collectors.toSet())); - } - return allTraces; - } - - public static long sidebar_startTime() { - if (tntFrames.isEmpty()) { - return 0; - } - return tntFrames.getLast().getStartTime(); - } - - public static int sidebar_TNT() { - if (tntFrames.isEmpty()) { - return 0; - } - return tntFrames.getLast().getTraces().size(); - } - - public enum Status{ - RECORD, - RECORD_AUTO, - IDLE, - IDLE_AUTO - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceActionbar.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceActionbar.java new file mode 100644 index 0000000..86f71ea --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceActionbar.java @@ -0,0 +1,52 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.bausystem.tracer.manager.FrameManager; +import de.steamwar.bausystem.tracer.manager.ShowManager; +import de.steamwar.bausystem.tracer.manager.TraceManager; +import org.bukkit.entity.Player; + +import java.util.Iterator; +import java.util.LinkedList; + +public class TraceActionbar { + + private static double round(double toRound, int digits) { + int x = (int)Math.pow(10, digits); + + double r = (toRound * x); + double t = r - (int) r; + + if (t >= 0.5) { + return (((double)(int)r) + 1) / x; + } else { + return (((double)(int)r) + 0) / x; + } + } + + public static String traceMemory() { + try { + long bitFrames = FrameManager.get().size() * 32L; + LinkedList traceIDs = TraceManager.get(); + long bitTraces = traceIDs.size() * 32L; + long bitTracesIntern = 0; + Iterator iterator = traceIDs.descendingIterator(); + while (iterator.hasNext()) { + bitTracesIntern += TraceManager.get(iterator.next()).realLength() * 32L; + } + double mByte = (bitFrames + bitTraces + bitTracesIntern) / 8.0 / 1024; + return "§e" + round(mByte, 4) + " §cKB"; + } catch (Exception e) { + + } + return "§e??? §cKB"; + } + + public static String traceSize() { + return "§e" + TraceManager.get().size() + " §cTraces"; + } + + public static String showRadius(Player p) { + return "§e" + ShowManager.get(p).getShowRadius() + " §cRadius"; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceSidebar.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceSidebar.java new file mode 100644 index 0000000..b67d0f1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceSidebar.java @@ -0,0 +1,22 @@ +package de.steamwar.bausystem.tracer; + +import de.steamwar.bausystem.tracer.manager.FrameManager; +import de.steamwar.bausystem.tracer.recorder.RecordManager; +import de.steamwar.bausystem.tracer.recorder.TNTRecorder; + +public class TraceSidebar { + + public static long traceStart() { + return TNTRecorder.recordStart; + } + + public static long traceTicks() { + return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50; + } + + public static int traceSize() { + if (RecordManager.activeFrameID == null) return 0; + return FrameManager.get(RecordManager.activeFrameID).size(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/FrameManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/FrameManager.java new file mode 100644 index 0000000..a3fc515 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/FrameManager.java @@ -0,0 +1,51 @@ +package de.steamwar.bausystem.tracer.manager; + +import java.util.*; + +public class FrameManager { + + private static Map> frameMap = new HashMap<>(); + + public static int createFrame() { + int id = IDManager.generateID(); + frameMap.put(id, new ArrayList<>()); + return id; + } + + static void add(int frameID, int tntID) { + if (!frameMap.containsKey(frameID)) { + return; + } + frameMap.get(frameID).add(tntID); + } + + public static List get(int frameID) { + if (!frameMap.containsKey(frameID)) { + return Arrays.asList(frameID); + } + return new ArrayList<>(frameMap.get(frameID)); + } + + public static List get() { + return new LinkedList<>(frameMap.keySet()); + } + + static void remove(int frameID, int traceID) { + if (!frameMap.containsKey(frameID)) { + return; + } + frameMap.get(frameID).remove((Integer) traceID); + cleanUp(frameID); + } + + public static void cleanUp(int frameID) { + if (!frameMap.containsKey(frameID)) { + return; + } + if (!frameMap.get(frameID).isEmpty()) { + return; + } + frameMap.remove((Integer) frameID); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/IDManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/IDManager.java new file mode 100644 index 0000000..6f75dff --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/IDManager.java @@ -0,0 +1,11 @@ +package de.steamwar.bausystem.tracer.manager; + +public class IDManager { + + private static int currentID = 0; + + public static synchronized int generateID() { + return currentID++; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/ShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/ShowManager.java new file mode 100644 index 0000000..97a9e17 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/ShowManager.java @@ -0,0 +1,336 @@ +package de.steamwar.bausystem.tracer.manager; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.TraceCache; +import de.steamwar.bausystem.tracer.trace.TNTTrace; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; + +public class ShowManager { + + public enum DisplayMode { + NONE, + Y_AXIS, + ALL + } + + public enum DisplayType { + Particle, + Block + } + + public enum ShowSelection { + NONE, + SELECTIVE, + ALL + } + + public static boolean tracer(Player player, String[] args) { + ShowStatus showStatus = showMap.get(player.getUniqueId().toString()); + showStatus.dirty = true; + switch (args[0].toLowerCase()) { + case "show": + showStatus.show(); + if (args.length == 2) { + return tracerShow(player, showStatus, args); + } + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); + break; + case "distance": + if (args.length != 2) { + return true; + } + if (args[1].equalsIgnoreCase("default")) { + ShowManager.get(player).setSlope(7.0); + player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt"); + return false; + } + try { + double radius = Double.parseDouble(args[1]); + radius = (double)(int)(radius * 10) / 10; + ShowManager.get(player).setSlope(radius); + player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt"); + return false; + } catch (NumberFormatException e) { + return true; + } + case "hide": + showStatus.hide(); + if (args.length == 2) { + return traceID(player, args[1], showStatus::removeSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"}); + } + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt"); + break; + case "toggleshow": + if (args.length == 2) { + return traceID(player, args[1], showStatus::toggleSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"}, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"}); + } + return true; + case "interpolate": + if (args.length == 2) { + return tracerInterpolate(player, showStatus, args); + } + return true; + default: + break; + } + return false; + } + + private static boolean tracerShow(Player player, ShowStatus showStatus, String[] args) { + switch (args[1].toLowerCase()) { + case "block": + case "blocks": + showStatus.displayType = DisplayType.Block; + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Blöcke, angezeigt"); + break; + case "particle": + case "particles": + case "default": + showStatus.displayType = DisplayType.Particle; + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Partikel, angezeigt"); + break; + default: + return traceID(player, args[1], showStatus::addSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"}); + } + return false; + } + + private static boolean tracerInterpolate(Player player, ShowStatus showStatus, String[] args) { + switch (args[1].toLowerCase()) { + case "none": + showStatus.displayMode = DisplayMode.NONE; + player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt"); + break; + case "yaxis": + case "y": + showStatus.displayMode = DisplayMode.Y_AXIS; + player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt"); + break; + case "all": + case "allaxis": + case "xyz": + case "default": + showStatus.displayMode = DisplayMode.ALL; + player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt"); + break; + default: + return true; + } + return false; + } + + private interface Mode { + void run(int tntID); + } + + private interface ModeChoose { + boolean run(int tntID); + } + + private static boolean traceID(Player player, String number, Mode mode, String[] messages) { + try { + mode.run(Integer.parseInt(number)); + for (String s : messages) { + player.sendMessage(s.replace("{}", number)); + } + } catch (NumberFormatException e) { + return true; + } + return false; + } + + private static boolean traceID(Player player, String number, ModeChoose mode, String[] messagesTrue, String[] messagesFalse) { + try { + boolean result = mode.run(Integer.parseInt(number)); + if (result) { + for (String s : messagesTrue) { + player.sendMessage(s.replace("{}", number)); + } + } else { + for (String s : messagesFalse) { + player.sendMessage(s.replace("{}", number)); + } + } + } catch (NumberFormatException e) { + return true; + } + return false; + } + + public static class ShowStatus { + + private ShowSelection showSelection = ShowSelection.NONE; + private DisplayType displayType = DisplayType.Particle; + private DisplayMode displayMode = DisplayMode.ALL; + + private boolean dirty = true; + private int count = 0; + + private LinkedList selected = new LinkedList<>(); + + private void clear() { + if (showSelection == ShowSelection.NONE) return; + selected.clear(); + } + + public void show() { + showSelection = ShowSelection.ALL; + } + + public void hide() { + clear(); + showSelection = ShowSelection.NONE; + } + + public void addSelection(int id) { + if (showSelection == ShowSelection.ALL) return; + if (showSelection == ShowSelection.NONE) showSelection = ShowSelection.SELECTIVE; + selected.addAll(FrameManager.get(id)); + if (selected.size() == TraceManager.get().size()) { + showSelection = ShowSelection.ALL; + clear(); + } + } + + public void removeSelection(int id) { + if (showSelection == ShowSelection.NONE) return; + if (showSelection == ShowSelection.ALL) selected = TraceManager.get(); + selected.removeAll(FrameManager.get(id)); + showSelection = ShowSelection.SELECTIVE; + if (selected.isEmpty()) showSelection = ShowSelection.NONE; + } + + public boolean toggleSelection(int id) { + if (showSelection == ShowSelection.NONE) { + addSelection(id); + return true; + } + if (showSelection == ShowSelection.ALL) { + removeSelection(id); + return false; + } + if (selected.contains(id)) { + removeSelection(id); + return false; + } else { + addSelection(id); + return true; + } + } + + public DisplayType getDisplayType() { + return displayType; + } + + public DisplayMode getDisplayMode() { + return displayMode; + } + + public LinkedList getTraces() { + if (showSelection == ShowSelection.NONE) return new LinkedList<>(); + LinkedList tntIDs; + if (showSelection == ShowSelection.ALL) { + tntIDs = TraceManager.get(); + } else { + tntIDs = selected; + } + + LinkedList traces = new LinkedList<>(); + Iterator iterator = tntIDs.descendingIterator(); + while (iterator.hasNext()) { + TNTTrace trace = TraceManager.get(iterator.next()); + if (trace == null) continue; + traces.add(trace); + } + return traces; + } + + public boolean isDirty() { + if (displayType == DisplayType.Block) { + count++; + } + if (count >= 10) { + count = 0; + return true; + } + if (dirty) { + dirty = false; + return true; + } + return false; + } + + private static double maxRadius = 80.0; + private static double minRadius = 20.0; + private static double minSlope = 3.0; + private static double maxSlope = 11.0; + private double slopeHeight = 7.0; + + private int size = 0; + + private TraceCache.Loc loc = null; + + public double getShowRadius() { + if (showSelection == ShowSelection.NONE) return maxRadius; + if (showSelection == ShowSelection.ALL) size = TraceManager.get().size(); + if (showSelection == ShowSelection.SELECTIVE) size = selected.size(); + if (size == 0) return maxRadius; + if (size >= 525) return minRadius; + + double slope = -(size / slopeHeight) + 85; + return Math.min(Math.max(slope, minRadius), maxRadius); + } + + public void setSlope(double slope) { + slopeHeight = Math.min(Math.max(slope, minSlope), maxSlope); + } + + public void move(Player player) { + if (loc != null && !loc.remove(player, 4)) { + return; + } + Location location = player.getLocation(); + loc = new TraceCache.Loc((float) location.getX(), (float) location.getY(), (float) location.getZ()); + dirty = true; + } + + } + + private static Map showMap = new HashMap<>(); + + public static void add(Player p) { + showMap.put(p.getUniqueId().toString(), new ShowStatus()); + } + + public static ShowStatus get(Player p) { + if (!showMap.containsKey(p.getUniqueId().toString())) add(p); + return showMap.get(p.getUniqueId().toString()); + } + + public static void traceAdd() { + for (Map.Entry entry : showMap.entrySet()) { + if (entry.getValue().showSelection == ShowSelection.ALL) { + entry.getValue().dirty = true; + } + } + } + + public static void traceRemove(int id) { + for (Map.Entry entry : showMap.entrySet()) { + if (entry.getValue().showSelection == ShowSelection.ALL) { + entry.getValue().dirty = true; + } + if (entry.getValue().showSelection == ShowSelection.SELECTIVE) { + entry.getValue().dirty = true; + entry.getValue().removeSelection(id); + } + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TNTManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TNTManager.java new file mode 100644 index 0000000..10a8af0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TNTManager.java @@ -0,0 +1,33 @@ +package de.steamwar.bausystem.tracer.manager; + +import de.steamwar.bausystem.tracer.trace.TNTTrace; +import org.bukkit.entity.TNTPrimed; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public class TNTManager { + + private static Map tntMap = new HashMap<>(); + + public static void explode(TNTPrimed tntPrimed) { + if (!tntMap.containsKey(tntPrimed)) return; + TraceManager.get(tntMap.get(tntPrimed)).cleanUp(); + } + + public static void add(Stream tntPrimedStream, int frameID) { + tntPrimedStream.forEach(tnt -> { + TNTTrace trace; + if (!tntMap.containsKey(tnt)) { + trace = new TNTTrace(frameID); + TraceManager.add(trace); + tntMap.put(tnt, trace.getTntID()); + } else { + trace = TraceManager.get(tntMap.get(tnt)); + } + trace.addLocation(tnt.getLocation()); + }); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TraceManager.java new file mode 100644 index 0000000..08fdaa1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/manager/TraceManager.java @@ -0,0 +1,59 @@ +package de.steamwar.bausystem.tracer.manager; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.trace.TNTTrace; +import org.bukkit.entity.Player; + +import java.util.*; + +public class TraceManager { + + private static Map traceMap = new HashMap<>(); + + public static void add(TNTTrace tntTrace) { + int id = IDManager.generateID(); + tntTrace.setTntID(id); + FrameManager.add(tntTrace.getFrameID(), id); + traceMap.put(id, tntTrace); + } + + public static void remove() { + Iterator iterator = get().descendingIterator(); + while (iterator.hasNext()) { + remove(iterator.next()); + } + } + + public static void remove(int id) { + if (!traceMap.containsKey(id)) { + return; + } + int frameID = traceMap.remove(id).getFrameID(); + ShowManager.traceRemove(id); + FrameManager.remove(frameID, id); + } + + public static TNTTrace get(int id) { + return traceMap.get(id); + } + + public static LinkedList get() { + return new LinkedList<>(traceMap.keySet()); + } + + public static boolean delete(Player player, String[] args) { + if (args.length == 2) { + try { + remove(Integer.parseInt(args[1])); + player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht"); + return false; + } catch (NumberFormatException e) { + return true; + } + } + remove(); + player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); + return false; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java new file mode 100644 index 0000000..b04e3c7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/RecordManager.java @@ -0,0 +1,141 @@ +package de.steamwar.bausystem.tracer.recorder; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.manager.FrameManager; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import static de.steamwar.bausystem.tracer.recorder.TNTRecorder.*; + +public class RecordManager { + + static Status status = Status.IDLE; + public static Integer activeFrameID = null; + + static World world; + public static void worldInit() { + if (world != null) return; + world = Bukkit.getWorlds().get(0); + } + + public static void tracer(Player player, String[] args) { + switch (args[0].toLowerCase()) { + case "start": + start(); + player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet"); + break; + case "stop": + stop(); + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); + break; + case "auto": + case "toggleauto": + toggleAuto(); + if (status == Status.IDLE || status == Status.RECORD) { + player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert"); + } else { + player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert"); + } + break; + } + } + + public static void toggleAuto() { + switch (status) { + case IDLE: + status = Status.IDLE_AUTO; + break; + case RECORD: + status = Status.RECORD_AUTO; + break; + case IDLE_AUTO: + status = Status.IDLE; + break; + case RECORD_AUTO: + status = Status.RECORD; + break; + default: + break; + } + } + + public static Status getStatus() { + return status; + } + + public static void start() { + if (activeFrameID != null) return; + status = Status.RECORD; + generateFrameID(); + startRecording(); + } + + public static void startAuto() { + if (activeFrameID != null) { + update(); + return; + } + status = Status.RECORD_AUTO; + Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet"))); + generateFrameID(); + startRecording(); + } + + public static void updateAuto() { + if (activeFrameID == null) return; + update(); + } + + public static void stop() { + if (activeFrameID == null) return; + status = Status.IDLE; + stopRecording(); + cleanUPFrameID(); + } + + static void stopAuto() { + if (activeFrameID == null) return; + status = Status.IDLE_AUTO; + Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt"))); + stopRecording(); + cleanUPFrameID(); + } + + private static void generateFrameID() { + if (activeFrameID != null) return;; + activeFrameID = FrameManager.createFrame(); + } + + private static void cleanUPFrameID() { + if (activeFrameID == null) return; + FrameManager.cleanUp(activeFrameID); + activeFrameID = null; + } + + public enum Status { + RECORD("§aan", true), + RECORD_AUTO("§aan", true), + IDLE("§caus", false), + IDLE_AUTO("§eauto", false); + + String value; + boolean tracing; + + Status(String value, boolean tracing) { + this.value = value; + this.tracing = tracing; + } + + public String getValue() { + return value; + } + + public boolean isTracing() { + return tracing; + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java new file mode 100644 index 0000000..f906bb1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/recorder/TNTRecorder.java @@ -0,0 +1,51 @@ +package de.steamwar.bausystem.tracer.recorder; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.manager.TNTManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitTask; + +import java.util.stream.Stream; + +import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto; + +public class TNTRecorder { + + private static BukkitTask task = null; + public static long recordStart = System.currentTimeMillis(); + public static long lastExplosion = System.currentTimeMillis(); + + static void update() { + if (task == null) return; + if (RecordManager.status != RecordManager.Status.RECORD_AUTO) return; + lastExplosion = System.currentTimeMillis(); + } + + static void startRecording() { + if (task != null) return; + recordStart = System.currentTimeMillis(); + lastExplosion = System.currentTimeMillis(); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1); + run(); + } + + static void stopRecording() { + if (task == null) return; + task.cancel(); + task = null; + } + + private static void run() { + Stream tntPrimedStream = RecordManager.world.getEntities() + .stream() + .filter(e -> e instanceof TNTPrimed) + .map(e -> (TNTPrimed)e); + TNTManager.add(tntPrimedStream, RecordManager.activeFrameID); + + if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) { + stopAuto(); + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java deleted file mode 100644 index 74a438e..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowManager.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.tracer.trace; - -import de.steamwar.bausystem.tracer.TNTTracer15; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; - -public class ShowManager { - - private static Map showMap = new HashMap<>(); - - public static void add(Player player) { - showMap.put(player, new ShowStatus(player)); - TNTTracer15.worldInit(); - } - - public static void dirty() { - for (Player player : Bukkit.getOnlinePlayers()) { - if (showMap.get(player).getShow() != ShowStatus.Show.NONE) { - showMap.get(player).dirty = true; - } - } - } - - public static void remove(Player player) { - showMap.remove(player); - } - - public static ShowStatus get(Player player) { - return showMap.get(player); - } - - public static void removeTrace(int traceID) { - for (Map.Entry entry : showMap.entrySet()) { - entry.getValue().removeSelection(traceID); - TNTTracer15.hideBlockTraces(entry.getKey()); - } - } - - public static void removeAllTraces() { - for (Map.Entry entry : showMap.entrySet()) { - entry.getValue().clear(); - TNTTracer15.hideBlockTraces(entry.getKey()); - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java deleted file mode 100644 index 72fdd96..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/ShowStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -package de.steamwar.bausystem.tracer.trace; - -import de.steamwar.bausystem.tracer.TNTTracer15; -import org.bukkit.entity.Player; - -import java.util.Iterator; -import java.util.LinkedList; - -public class ShowStatus { - - private Show show = Show.NONE; - private UpdatePoints updatePoints = UpdatePoints.ALL; - private ShowMode showMode = ShowMode.PARTICLE; - - private LinkedList selected = new LinkedList<>(); - - private Player p; - - boolean dirty = false; - - public ShowStatus(Player p) { - this.p = p; - } - - public enum Show { - NONE, - ALL, - SELECTIVE - } - - public enum UpdatePoints { - NONE, - Y_AXIS, - ALL - } - - public enum ShowMode { - BLOCK, - PARTICLE - } - - public boolean toggleShow(int tntID) { - dirty = true; - if (show == Show.ALL) { - removeSelection(tntID); - return false; - } - Iterator selection = selected.iterator(); - while (selection.hasNext()) { - if (selection.next() == tntID) { - removeSelection(tntID); - return false; - } - } - addSelection(tntID); - return true; - } - - public void show() { - dirty = true; - show = Show.ALL; - } - - public void hide() { - dirty = true; - selected.clear(); - TNTTracer15.hideBlockTraces(p); - show = Show.NONE; - } - - public void addSelection(int uniqueID) { - dirty = true; - if (show == Show.ALL) return; - if (show == Show.NONE) { - show = Show.SELECTIVE; - } - selected.add(uniqueID); - if (selected.size() == TNTTracer15.allTraces().size()) { - show = Show.ALL; - selected.clear(); - } - } - - public void removeSelection(int uniqueID) { - dirty = true; - if (show == Show.NONE) return; - TNTTracer15.hideBlockTraces(p); - if (show == Show.ALL) { - selected = TNTTracer15.allTraces(); - show = Show.SELECTIVE; - } - selected.remove((Integer) uniqueID); - if (selected.isEmpty()) { - show = Show.NONE; - } - } - - public void clear() { - dirty = true; - if (show == Show.NONE) return; - selected.clear(); - TNTTracer15.hideBlockTraces(p); - } - - public Show getShow() { - return show; - } - - public UpdatePoints getUpdatePoints() { - return updatePoints; - } - - public void setUpdatePoints(UpdatePoints updatePoints) { - this.updatePoints = updatePoints; - } - - public ShowMode getShowMode() { - return showMode; - } - - public void setShowMode(ShowMode showMode) { - this.showMode = showMode; - } - - public LinkedList getSelection() { - return selected; - } - - public boolean isDirty() { - if (dirty) { - dirty = false; - return true; - } - return false; - } - - public void dirty() { - dirty = true; - } - - @Override - public String toString() { - return "ShowStatus{" + - "status=" + show + - ", selected=" + selected + - '}'; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java deleted file mode 100644 index 667e8c8..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTFrame.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.steamwar.bausystem.tracer.trace; - -import de.steamwar.bausystem.tracer.TNTTracer15; -import org.bukkit.entity.TNTPrimed; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.stream.Stream; - -public class TNTFrame { - - private static int uniqueIdentifierFrame = 0; - private static int uniqueIdentifier = 0; - - private long startTime = System.currentTimeMillis(); - private Map positions = new HashMap<>(); - private Map aliveTNT = new HashMap<>(); - - private final TNTFrame instance = this; - - private final int uniqueID = uniqueIdentifierFrame++; - - public int getUniqueID() { - return uniqueID; - } - - public void add(Stream tntPrimedStream) { - if (aliveTNT == null) return; - tntPrimedStream.forEach(tnt -> aliveTNT.computeIfAbsent(tnt, k -> { - synchronized (instance) { - TNTTrace trace = new TNTTrace(uniqueIdentifier); - positions.put(uniqueIdentifier, trace); - uniqueIdentifier++; - return trace; - } - }).addLocation(tnt.getLocation())); - } - - public void explode(TNTPrimed tntPrimed) { - delete(tntPrimed); - } - - void delete(TNTPrimed tntPrimed) { - delete(tntPrimed, true); - } - - private void delete(TNTPrimed tntPrimed, boolean delete) { - if (aliveTNT == null) return; - TNTTrace tntTrace = aliveTNT.get(tntPrimed); - if (delete) { - aliveTNT.remove(tntPrimed); - } - if (TNTTracer15.isInWater(tntPrimed)) { - positions.remove(tntTrace.getUniqueID()); - } - } - - public void remove(int tntID) { - positions.remove(tntID); - } - - public LinkedList getTraces(LinkedList selection) { - LinkedList traces = new LinkedList<>(); - Iterator iterator = selection.iterator(); - while (iterator.hasNext()) { - TNTTrace trace = positions.get(iterator.next()); - if (trace != null) { - traces.add(trace); - } - } - return traces; - } - - public LinkedList getTraces() { - LinkedList traces = new LinkedList<>(); - for (Map.Entry entry : positions.entrySet()) { - traces.add(entry.getValue()); - } - return traces; - } - - public boolean finish() { - for (Map.Entry entry : aliveTNT.entrySet()) { - entry.getValue().cleanUp(); - delete(entry.getKey(), false); - } - aliveTNT.clear(); - aliveTNT = null; - return positions.isEmpty(); - } - - public long getStartTime() { - return startTime; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java index 212d6ec..9f5de80 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/trace/TNTTrace.java @@ -1,19 +1,28 @@ package de.steamwar.bausystem.tracer.trace; +import de.steamwar.bausystem.tracer.TraceCache; +import de.steamwar.bausystem.tracer.manager.ShowManager; import org.bukkit.Location; import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class TNTTrace { - private long startTime = System.currentTimeMillis(); - private int uniqueID; + private final long startTime = System.currentTimeMillis(); + private final int frameID; + private int tntID; private int index = 0; private float[] positions = new float[240]; - public TNTTrace(int uniqueID) { - this.uniqueID = uniqueID; + private Set posSet = new HashSet<>(); + private Set posYSet = new HashSet<>(); + private Set posXYZSet = new HashSet<>(); + + public TNTTrace(int frameID) { + this.frameID = frameID; } public void addLocation(Location location) { @@ -30,10 +39,6 @@ public class TNTTrace { index += 3; } - public float[] getPositions() { - return Arrays.copyOf(positions, positions.length); - } - public int size() { return index / 3; } @@ -50,12 +55,65 @@ public class TNTTrace { return startTime; } - public int getUniqueID() { - return uniqueID; + public void setTntID(int tntID) { + this.tntID = tntID; } - void cleanUp() { - positions = Arrays.copyOf(positions, index); + public int getTntID() { + return tntID; } + public int getFrameID() { + return frameID; + } + + public void cleanUp() { + positions = Arrays.copyOf(positions, index); + ShowManager.traceAdd(); + + for (int i = 0; i < length(); i++) { + posSet.add(new TraceCache.Loc(positions[i * 3 + 0], positions[i * 3 + 1], positions[i * 3 + 2])); + } + + for (int i = 0; i < realLength() - 3; i += 3) { + float x1 = positions[i + 0]; + float y1 = positions[i + 1]; + float z1 = positions[i + 2]; + + float x2 = positions[i + 3]; + float y2 = positions[i + 4]; + float z2 = positions[i + 5]; + + if (!isEqual(y2, y1)) { + TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1); + posYSet.add(loc); + posXYZSet.add(loc); + } + if (abs(x2 - x1) > abs(z2 - z1)) { + if (!isEqual(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1)); + } else { + if (!isEqual(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2)); + } + } + } + + public Set locs() { + return posSet; + } + + public Set locsUpdate(ShowManager.DisplayMode displayMode) { + if (displayMode == ShowManager.DisplayMode.NONE) return new HashSet<>(); + if (displayMode == ShowManager.DisplayMode.Y_AXIS) return posYSet; + return posXYZSet; + } + + private static boolean isEqual(float d1, float d2) { + return (d2 - d1) * (d2 - d1) < 0.01; + } + + private static float abs(float x) { + return x < 0 ? -x : x; + } + + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 5ae81d6..7ae7963 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -3,8 +3,8 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandInfo; import de.steamwar.bausystem.commands.CommandTNT; -import de.steamwar.bausystem.tracer.TNTTracer15; -import de.steamwar.core.Core; +import de.steamwar.bausystem.tracer.TraceSidebar; +import de.steamwar.bausystem.tracer.recorder.RecordManager; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.entity.Player; @@ -24,20 +24,7 @@ public class BauScoreboard implements Listener { SWScoreboard.createScoreboard(player, new ScoreboardCallback() { @Override public HashMap getData() { - HashMap data = new HashMap<>(); - - switch (Core.getVersion()) { - case 15: - render(getSidebar_15(), data); - break; - case 12: - render(getSidebar_12(), data); - break; - default: - break; - } - - return data; + return render(sidebar(player)); } @Override @@ -47,30 +34,32 @@ public class BauScoreboard implements Listener { }); } - private void render(List strings, HashMap data) { + private HashMap render(List strings) { + HashMap data = new HashMap<>(); String[] elements = strings.toArray(new String[0]); for (int i = elements.length - 1; i >= 0; i--) { data.put(elements[i], elements.length - i - 1); } + return data; } - private List getSidebar_15() { + private List sidebar(Player p) { List strings = new ArrayList<>(); strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); + strings.add("§eTrace§8: " + RecordManager.getStatus().getValue()); + strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); - boolean tracing = TNTTracer15.getStatus() == TNTTracer15.Status.RECORD || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO; - boolean autoTracer = TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO; - strings.add("§eTrace§8: " + (tracing ? "§aan" : (autoTracer ? "§eauto" : "§caus"))); - - if (tracing) { + if (RecordManager.getStatus().isTracing()) { strings.add("§3"); - strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TNTTracer15.sidebar_startTime()))); - strings.add("§eTicks§8: §7" + ((System.currentTimeMillis() - TNTTracer15.sidebar_startTime()) / 50)); - strings.add("§eAnzahl TNT§8: §7" + TNTTracer15.sidebar_TNT()); + strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TraceSidebar.traceStart()))); + strings.add("§eTicks§8: §7" + TraceSidebar.traceTicks()); + strings.add("§eAnzahl TNT§8: §7" + TraceSidebar.traceSize()); + } else if (AutoLoader.hasLoader(p)) { + // strings.add("§3"); } strings.add("§4"); @@ -78,16 +67,4 @@ public class BauScoreboard implements Listener { return strings; } - private List getSidebar_12() { - List strings = new ArrayList<>(); - strings.add("§1"); - strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); - strings.add("§2"); - strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); - strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); - strings.add("§3"); - strings.add("§eTPS§8: §7" + CommandInfo.getTps()[0]); - return strings; - } - } From 0bf5653eea80d808c83fa16d4477c115290ec5e1 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 30 Aug 2020 02:42:24 +0200 Subject: [PATCH 20/20] Fix Tracer --- .../bausystem/tracer/TNTTracerGUI_15.java | 19 ++----------------- .../guicallback/GuiCallbackRecording.java | 10 ---------- .../guicallback/GuiCallbackTNTFrame.java | 11 ----------- .../guicallback/GuiCallbackTNTTrace.java | 11 ----------- 4 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java index 24f24b2..750e69f 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracerGUI_15.java @@ -1,23 +1,8 @@ package de.steamwar.bausystem.tracer; -import de.steamwar.bausystem.tracer.guicallback.GuiCallbackRecording; -import de.steamwar.bausystem.tracer.guicallback.GuiCallbackTNTFrame; -import de.steamwar.bausystem.tracer.guicallback.GuiCallbackTNTTrace; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.Arrays; -import java.util.List; - public class TNTTracerGUI_15 { - private static GuiCallbackTNTFrame guiCallbackTNTFrame; + /*private static GuiCallbackTNTFrame guiCallbackTNTFrame; private static GuiCallbackTNTTrace guiCallbackTNTTrace; private static GuiCallbackRecording guiCallbackRecording; @@ -90,6 +75,6 @@ public class TNTTracerGUI_15 { public static void show(Player p, int page, Menu menu) { - } + }*/ } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java deleted file mode 100644 index 66b03d8..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackRecording.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.steamwar.bausystem.tracer.guicallback; - -import org.bukkit.inventory.ItemStack; - -@FunctionalInterface -public interface GuiCallbackRecording { - - ItemStack run(); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java deleted file mode 100644 index ee1b77e..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTFrame.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.steamwar.bausystem.tracer.guicallback; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -@FunctionalInterface -public interface GuiCallbackTNTFrame { - - ItemStack[] run(Player p); - -} diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java deleted file mode 100644 index cc57b60..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/guicallback/GuiCallbackTNTTrace.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.steamwar.bausystem.tracer.guicallback; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -@FunctionalInterface -public interface GuiCallbackTNTTrace { - - ItemStack[] run(Player p); - -}