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..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) && traceCache.nearLastLocation(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)) { - 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_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) {