SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'TNTTracer' (#84) from TNTTracer into master

Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
YoyoNow 2020-07-25 21:30:20 +02:00
Commit 06b6978442
3 geänderte Dateien mit 31 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -24,10 +24,10 @@ class TNTTracer_15 {
private static TracerCallbackPositions tracerCallbackPositions; private static TracerCallbackPositions tracerCallbackPositions;
private static TracerCallbackUpdatePoints tracerCallbackUpdatePoints; private static TracerCallbackUpdatePoints tracerCallbackUpdatePoints;
private static TracerCallbackTracing tracerCallbackTracing;
private static DebugCallbackActionBar debugCallbackActionBar; private static DebugCallbackActionBar debugCallbackActionBar;
private static TNTCallbackShow tntCallbackShow; private static TNTCallbackShow tntCallbackShow;
private static TNTCallbackCacheUpdate tntCallbackCacheUpdate;
private static TracerUpdateManager tracerUpdateManager;
private static Map<Player, PlayerTraceCache_15> playerMap = new HashMap<>(); private static Map<Player, PlayerTraceCache_15> playerMap = new HashMap<>();
@ -43,7 +43,7 @@ class TNTTracer_15 {
return d * d; 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, () -> { Bukkit.getScheduler().runTaskTimer(plugin, () -> {
synchronized (synchronizer) { synchronized (synchronizer) {
synchronizer.notifyAll(); synchronizer.notifyAll();
@ -66,8 +66,8 @@ class TNTTracer_15 {
TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints; TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints;
TNTTracer_15.debugCallbackActionBar = debugCallbackActionBar; TNTTracer_15.debugCallbackActionBar = debugCallbackActionBar;
TNTTracer_15.tntCallbackShow = tntCallbackShow; TNTTracer_15.tntCallbackShow = tntCallbackShow;
TNTTracer_15.tntCallbackCacheUpdate = tntCallbackCacheUpdate;
TNTTracer_15.tracerCallbackTracing = tracerCallbackTracing; TNTTracer_15.tracerUpdateManager = tracerUpdateManager;
} }
static void initWorld() { static void initWorld() {
@ -97,7 +97,7 @@ class TNTTracer_15 {
} }
private static void updateShowPlayer(Player p, PlayerTraceCache_15 traceCache) { 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); update(p, traceCache);
} }
traceCache.show(p, tntCallbackShow.run(p)); traceCache.show(p, tntCallbackShow.run(p));
@ -106,10 +106,6 @@ class TNTTracer_15 {
private static float[] noValue = new float[0]; private static float[] noValue = new float[0];
private static void update(Player p, PlayerTraceCache_15 traceCache) { private static void update(Player p, PlayerTraceCache_15 traceCache) {
if (tracerCallbackTracing.run(p)) {
return;
}
float[] floats = tracerCallbackPositions.run(p); float[] floats = tracerCallbackPositions.run(p);
if (floats.length == 0 || floats.length % 3 != 0) { if (floats.length == 0 || floats.length % 3 != 0) {
traceCache.setPositions(noValue); traceCache.setPositions(noValue);

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -45,12 +45,12 @@ public class TNTTracer15 {
private static final float[] noValue = new float[0]; private static final float[] noValue = new float[0];
public static void initTNTTracer_15() { 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) { if (System.currentTimeMillis() - lastExplosion < 4500) {
ShowManager.get(p).dirty(); ShowManager.get(p).dirty();
} }
return System.currentTimeMillis() - lastExplosion < 4500; return System.currentTimeMillis() - lastExplosion < 4500;
}); }));
} }
private static float[] accumulate(LinkedList<TNTTrace> traces) { private static float[] accumulate(LinkedList<TNTTrace> traces) {