Untangle spagetti code part 1
Dieser Commit ist enthalten in:
Ursprung
1f2b6a0290
Commit
6831ada70f
@ -2,7 +2,6 @@ package de.steamwar.bausystem.tracer;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||||
import de.steamwar.bausystem.tracer.trace.TNTTrace;
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
@ -11,8 +10,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static de.steamwar.bausystem.tracer.TraceUtils.DEBUG;
|
import static de.steamwar.bausystem.tracer.TraceUtils.DEBUG;
|
||||||
@ -23,55 +20,6 @@ public class TNTTracer {
|
|||||||
private static final Object synchronizer = new Object();
|
private static final Object synchronizer = new Object();
|
||||||
private static final TraceCache traceCache = new TraceCache();
|
private static final TraceCache traceCache = new TraceCache();
|
||||||
|
|
||||||
private static final TracerUpdater tracerUpdater = new TracerUpdater() {
|
|
||||||
@Override
|
|
||||||
public Set<TraceCache.Loc> updateLocations(Player player) {
|
|
||||||
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
|
||||||
Set<TraceCache.Loc> 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<TraceCache.Loc> updatePoints(Player player) {
|
|
||||||
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
|
||||||
Set<TraceCache.Loc> 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 init(){
|
public static void init(){
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||||
synchronized (synchronizer) {
|
synchronized (synchronizer) {
|
||||||
@ -95,19 +43,19 @@ public class TNTTracer {
|
|||||||
private static void run(){
|
private static void run(){
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
String actionBar = tracerUpdater.actionBar(p);
|
String actionBar = TracerUpdater.actionBar(p);
|
||||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dirty = tracerUpdater.needsUpdate(p);
|
boolean dirty = TracerUpdater.needsUpdate(p);
|
||||||
if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) {
|
if (TracerUpdater.getDisplayType(p) == ShowManager.DisplayType.Block && !dirty) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Set<TraceCache.Loc> toHide = traceCache.update(p, tracerUpdater, dirty);
|
Set<TraceCache.Loc> toHide = traceCache.update(p, dirty);
|
||||||
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
||||||
|
|
||||||
hideBlockTraces(toHide, p);
|
hideBlockTraces(toHide, p);
|
||||||
showTraces(toShow, tracerUpdater.getDisplayType(p), p);
|
showTraces(toShow, TracerUpdater.getDisplayType(p), p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,11 +67,11 @@ public class TNTTracer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showTraces(Set<TraceCache.Loc> locs, TracerUpdater.DisplayMode displayMode, Player player) {
|
private static void showTraces(Set<TraceCache.Loc> locs, ShowManager.DisplayType displayMode, Player player) {
|
||||||
if (locs.isEmpty()) return;
|
if (locs.isEmpty()) return;
|
||||||
|
|
||||||
for (TraceCache.Loc l : locs) {
|
for (TraceCache.Loc l : locs) {
|
||||||
if (displayMode == TracerUpdater.DisplayMode.Block) {
|
if (displayMode == ShowManager.DisplayType.Block) {
|
||||||
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14));
|
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14));
|
||||||
} else {
|
} else {
|
||||||
TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
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 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<Integer> traceIDs = TraceManager.get();
|
|
||||||
long bitTraces = traceIDs.size() * 32L;
|
|
||||||
long bitTracesIntern = 0;
|
|
||||||
Iterator<Integer> 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";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +1,62 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class TraceCache {
|
public class TraceCache {
|
||||||
|
|
||||||
private static final Set<Loc> empty = new HashSet();
|
private static final Set<Loc> empty = new HashSet<>();
|
||||||
private Map<String, Set<Loc>> playerMap = new HashMap<>();
|
private Map<String, Set<Loc>> playerMap = new HashMap<>();
|
||||||
private Map<String, TracerUpdater.DisplayMode> playerDisplayMap = new HashMap<>();
|
private Map<String, ShowManager.DisplayType> playerDisplayMap = new HashMap<>();
|
||||||
|
|
||||||
public Set<Loc> get(Player player) {
|
public Set<Loc> get(Player player) {
|
||||||
return playerMap.getOrDefault(player.getUniqueId().toString(), empty);
|
return playerMap.getOrDefault(player.getUniqueId().toString(), empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Loc> update(Player player, TracerUpdater tracerUpdater, boolean dirty) {
|
Set<Loc> update(Player player, boolean dirty) {
|
||||||
if (!dirty) return empty;
|
if (!dirty) return empty;
|
||||||
String key = player.getUniqueId().toString();
|
String key = player.getUniqueId().toString();
|
||||||
Set<Loc> locOld;
|
Set<Loc> locOld;
|
||||||
TracerUpdater.DisplayMode displayMode;
|
ShowManager.DisplayType displayMode;
|
||||||
if (!playerMap.containsKey(key)) {
|
if (!playerMap.containsKey(key)) {
|
||||||
locOld = new HashSet<>();
|
locOld = new HashSet<>();
|
||||||
displayMode = tracerUpdater.getDisplayType(player);
|
displayMode = TracerUpdater.getDisplayType(player);
|
||||||
} else {
|
} else {
|
||||||
locOld = playerMap.get(key);
|
locOld = playerMap.get(key);
|
||||||
displayMode = playerDisplayMap.get(key);
|
displayMode = playerDisplayMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Loc> locSet = new HashSet<>();
|
Set<Loc> locSet = new HashSet<>();
|
||||||
tracerUpdater.updatePoints(player).forEach(loc -> {
|
TracerUpdater.updatePoints(player).forEach(loc -> {
|
||||||
loc.updatePoint = true;
|
loc.updatePoint = true;
|
||||||
locSet.add(loc);
|
locSet.add(loc);
|
||||||
});
|
});
|
||||||
tracerUpdater.updateLocations(player).forEach(loc -> {
|
TracerUpdater.updateLocations(player).forEach(loc -> {
|
||||||
loc.updatePoint = false;
|
loc.updatePoint = false;
|
||||||
locSet.add(loc);
|
locSet.add(loc);
|
||||||
});
|
});
|
||||||
|
|
||||||
playerMap.put(key, locSet);
|
playerMap.put(key, locSet);
|
||||||
TracerUpdater.DisplayMode currentMode = tracerUpdater.getDisplayType(player);
|
ShowManager.DisplayType currentMode = TracerUpdater.getDisplayType(player);
|
||||||
playerDisplayMap.put(key, currentMode);
|
playerDisplayMap.put(key, currentMode);
|
||||||
|
|
||||||
if (currentMode == TracerUpdater.DisplayMode.Particle && displayMode == TracerUpdater.DisplayMode.Block) return locOld;
|
if (currentMode == ShowManager.DisplayType.Particle && displayMode == ShowManager.DisplayType.Block) return locOld;
|
||||||
if (currentMode == TracerUpdater.DisplayMode.Block) return diff(locOld, locSet);
|
if (currentMode == ShowManager.DisplayType.Block) return diff(locOld, locSet);
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Loc {
|
public static class Loc {
|
||||||
public final float x;
|
final float x;
|
||||||
public final float y;
|
final float y;
|
||||||
public final float z;
|
final float z;
|
||||||
|
|
||||||
private final float dx;
|
private final float dx;
|
||||||
private final float dy;
|
private final float dy;
|
||||||
private final float dz;
|
private final float dz;
|
||||||
|
|
||||||
public boolean updatePoint = false;
|
boolean updatePoint = false;
|
||||||
|
|
||||||
public Loc(float x, float y, float z) {
|
public Loc(float x, float y, float z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -66,8 +67,8 @@ public class TraceCache {
|
|||||||
this.dz = round(z);
|
this.dz = round(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int roundNumber = 10;
|
|
||||||
private static float round(float toRound) {
|
private static float round(float toRound) {
|
||||||
|
final int roundNumber = 10;
|
||||||
float r = (toRound * roundNumber);
|
float r = (toRound * roundNumber);
|
||||||
float t = r - (int) r;
|
float t = r - (int) r;
|
||||||
if (t >= 0.5) {
|
if (t >= 0.5) {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||||
import de.steamwar.bausystem.tracer.manager.TNTManager;
|
import de.steamwar.bausystem.tracer.manager.TraceManager;
|
||||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||||
|
import de.steamwar.bausystem.tracer.trace.TNTTrace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -10,18 +11,41 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class TraceListener implements Listener {
|
public class TraceListener implements Listener {
|
||||||
|
|
||||||
|
private static final Map<TNTPrimed, TNTTrace> tntMap = new HashMap<>();
|
||||||
|
|
||||||
|
public static void add(Stream<TNTPrimed> tntPrimedStream, int frameID) {
|
||||||
|
tntPrimedStream.forEach(tnt -> {
|
||||||
|
TNTTrace trace;
|
||||||
|
if (!tntMap.containsKey(tnt)) {
|
||||||
|
trace = new TNTTrace(frameID);
|
||||||
|
TraceManager.add(trace);
|
||||||
|
tntMap.put(tnt, trace);
|
||||||
|
} else {
|
||||||
|
trace = tntMap.get(tnt);
|
||||||
|
}
|
||||||
|
trace.addLocation(tnt.getLocation());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
if (!(event.getEntity() instanceof TNTPrimed))
|
||||||
|
return;
|
||||||
|
|
||||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO)
|
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO)
|
||||||
RecordManager.startAuto();
|
RecordManager.startAuto();
|
||||||
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO)
|
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO)
|
||||||
RecordManager.updateAuto();
|
RecordManager.updateAuto();
|
||||||
|
|
||||||
TNTManager.explode((TNTPrimed) event.getEntity());
|
TNTTrace trace = tntMap.get((TNTPrimed) event.getEntity());
|
||||||
|
if (trace != null)
|
||||||
|
trace.cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,21 +1,48 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||||
|
import de.steamwar.bausystem.tracer.manager.TraceManager;
|
||||||
|
import de.steamwar.bausystem.tracer.trace.TNTTrace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface TracerUpdater {
|
class TracerUpdater {
|
||||||
|
private TracerUpdater(){}
|
||||||
|
|
||||||
enum DisplayMode {
|
static Set<TraceCache.Loc> updateLocations(Player player) {
|
||||||
Block,
|
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
||||||
Particle,
|
Set<TraceCache.Loc> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<TraceCache.Loc> updateLocations(Player player);
|
static Set<TraceCache.Loc> updatePoints(Player player) {
|
||||||
Set<TraceCache.Loc> updatePoints(Player player);
|
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
||||||
boolean needsUpdate(Player player);
|
Set<TraceCache.Loc> locSet = new HashSet<>();
|
||||||
DisplayMode getDisplayType(Player player);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
String actionBar(Player player);
|
static boolean needsUpdate(Player player) {
|
||||||
|
return ShowManager.get(player).isDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
static ShowManager.DisplayType getDisplayType(Player player) {
|
||||||
|
return ShowManager.get(player).getDisplayType();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String actionBar(Player player) {
|
||||||
|
return "§e" + TraceManager.get().size() + " §cTraces §e" + ShowManager.get(player).getShowRadius() + " §cRadius";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class FrameManager {
|
|||||||
if (!frameMap.get(frameID).isEmpty()) {
|
if (!frameMap.get(frameID).isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frameMap.remove((Integer) frameID);
|
frameMap.remove(frameID);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ public class IDManager {
|
|||||||
|
|
||||||
private static int currentID = 0;
|
private static int currentID = 0;
|
||||||
|
|
||||||
public static synchronized int generateID() {
|
static synchronized int generateID() {
|
||||||
return currentID++;
|
return currentID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,16 +179,16 @@ public class ShowManager {
|
|||||||
selected.clear();
|
selected.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
void show() {
|
||||||
showSelection = ShowSelection.ALL;
|
showSelection = ShowSelection.ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide() {
|
void hide() {
|
||||||
clear();
|
clear();
|
||||||
showSelection = ShowSelection.NONE;
|
showSelection = ShowSelection.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSelection(int id) {
|
void addSelection(int id) {
|
||||||
if (showSelection == ShowSelection.ALL) return;
|
if (showSelection == ShowSelection.ALL) return;
|
||||||
if (showSelection == ShowSelection.NONE) showSelection = ShowSelection.SELECTIVE;
|
if (showSelection == ShowSelection.NONE) showSelection = ShowSelection.SELECTIVE;
|
||||||
selected.addAll(FrameManager.get(id));
|
selected.addAll(FrameManager.get(id));
|
||||||
@ -198,7 +198,7 @@ public class ShowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSelection(int id) {
|
void removeSelection(int id) {
|
||||||
if (showSelection == ShowSelection.NONE) return;
|
if (showSelection == ShowSelection.NONE) return;
|
||||||
if (showSelection == ShowSelection.ALL) selected = TraceManager.get();
|
if (showSelection == ShowSelection.ALL) selected = TraceManager.get();
|
||||||
selected.removeAll(FrameManager.get(id));
|
selected.removeAll(FrameManager.get(id));
|
||||||
@ -206,7 +206,7 @@ public class ShowManager {
|
|||||||
if (selected.isEmpty()) showSelection = ShowSelection.NONE;
|
if (selected.isEmpty()) showSelection = ShowSelection.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean toggleSelection(int id) {
|
boolean toggleSelection(int id) {
|
||||||
if (showSelection == ShowSelection.NONE) {
|
if (showSelection == ShowSelection.NONE) {
|
||||||
addSelection(id);
|
addSelection(id);
|
||||||
return true;
|
return true;
|
||||||
@ -266,10 +266,6 @@ public class ShowManager {
|
|||||||
return false;
|
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 double slopeHeight = 7.0;
|
||||||
|
|
||||||
private int size = 0;
|
private int size = 0;
|
||||||
@ -277,17 +273,21 @@ public class ShowManager {
|
|||||||
private TraceCache.Loc loc = null;
|
private TraceCache.Loc loc = null;
|
||||||
|
|
||||||
public double getShowRadius() {
|
public double getShowRadius() {
|
||||||
|
double maxRadius = 80.0;
|
||||||
if (showSelection == ShowSelection.NONE) return maxRadius;
|
if (showSelection == ShowSelection.NONE) return maxRadius;
|
||||||
if (showSelection == ShowSelection.ALL) size = TraceManager.get().size();
|
if (showSelection == ShowSelection.ALL) size = TraceManager.get().size();
|
||||||
if (showSelection == ShowSelection.SELECTIVE) size = selected.size();
|
if (showSelection == ShowSelection.SELECTIVE) size = selected.size();
|
||||||
if (size == 0) return maxRadius;
|
if (size == 0) return maxRadius;
|
||||||
|
double minRadius = 20.0;
|
||||||
if (size >= 950) return minRadius;
|
if (size >= 950) return minRadius;
|
||||||
|
|
||||||
double slope = -(size / slopeHeight) + 85;
|
double slope = -(size / slopeHeight) + 85;
|
||||||
return Math.min(Math.max(slope, minRadius), maxRadius);
|
return Math.min(Math.max(slope, minRadius), maxRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSlope(double slope) {
|
void setSlope(double slope) {
|
||||||
|
double minSlope = 3.0;
|
||||||
|
double maxSlope = 11.0;
|
||||||
slopeHeight = Math.min(Math.max(slope, minSlope), maxSlope);
|
slopeHeight = Math.min(Math.max(slope, minSlope), maxSlope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,13 +321,13 @@ public class ShowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void traceRemove(int id) {
|
static void traceRemove(int id) {
|
||||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||||
entry.getValue().removeSelection(id);
|
entry.getValue().removeSelection(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void globalDirty() {
|
static void globalDirty() {
|
||||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||||
entry.getValue().dirty = true;
|
entry.getValue().dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
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<TNTPrimed, Integer> 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<TNTPrimed> 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());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -17,14 +17,14 @@ public class TraceManager {
|
|||||||
traceMap.put(id, tntTrace);
|
traceMap.put(id, tntTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void remove() {
|
private static void remove() {
|
||||||
Iterator<Integer> iterator = get().descendingIterator();
|
Iterator<Integer> iterator = get().descendingIterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
remove(iterator.next());
|
remove(iterator.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void remove(int id) {
|
private static void remove(int id) {
|
||||||
if (!traceMap.containsKey(id)) {
|
if (!traceMap.containsKey(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.steamwar.bausystem.tracer.recorder;
|
package de.steamwar.bausystem.tracer.recorder;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.tracer.manager.TNTManager;
|
import de.steamwar.bausystem.tracer.TraceListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
@ -41,7 +41,7 @@ public class TNTRecorder {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(e -> e instanceof TNTPrimed)
|
.filter(e -> e instanceof TNTPrimed)
|
||||||
.map(e -> (TNTPrimed)e);
|
.map(e -> (TNTPrimed)e);
|
||||||
TNTManager.add(tntPrimedStream, RecordManager.activeFrameID);
|
TraceListener.add(tntPrimedStream, RecordManager.activeFrameID);
|
||||||
|
|
||||||
if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) {
|
if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) {
|
||||||
stopAuto();
|
stopAuto();
|
||||||
|
@ -10,7 +10,6 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class TNTTrace {
|
public class TNTTrace {
|
||||||
|
|
||||||
private final long startTime = System.currentTimeMillis();
|
|
||||||
private final int frameID;
|
private final int frameID;
|
||||||
private int tntID;
|
private int tntID;
|
||||||
|
|
||||||
@ -26,20 +25,16 @@ public class TNTTrace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addLocation(Location location) {
|
public void addLocation(Location location) {
|
||||||
addLocation(location.getX(), location.getY(), location.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLocation(double x, double y, double z) {
|
|
||||||
if (index >= positions.length) {
|
if (index >= positions.length) {
|
||||||
positions = Arrays.copyOf(positions, positions.length + 240);
|
positions = Arrays.copyOf(positions, positions.length + 3);
|
||||||
}
|
}
|
||||||
positions[index + 0] = (float)x;
|
positions[index] = (float)location.getX();
|
||||||
positions[index + 1] = (float)y;
|
positions[index + 1] = (float)location.getY();
|
||||||
positions[index + 2] = (float)z;
|
positions[index + 2] = (float)location.getZ();
|
||||||
index += 3;
|
index += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
private int size() {
|
||||||
return index / 3;
|
return index / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +46,6 @@ public class TNTTrace {
|
|||||||
return positions.length;
|
return positions.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartTime() {
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTntID(int tntID) {
|
public void setTntID(int tntID) {
|
||||||
this.tntID = tntID;
|
this.tntID = tntID;
|
||||||
}
|
}
|
||||||
@ -72,11 +63,11 @@ public class TNTTrace {
|
|||||||
ShowManager.traceAdd();
|
ShowManager.traceAdd();
|
||||||
|
|
||||||
for (int i = 0; i < length(); i++) {
|
for (int i = 0; i < length(); i++) {
|
||||||
posSet.add(new TraceCache.Loc(positions[i * 3 + 0], positions[i * 3 + 1], positions[i * 3 + 2]));
|
posSet.add(new TraceCache.Loc(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < realLength() - 3; i += 3) {
|
for (int i = 0; i < realLength() - 3; i += 3) {
|
||||||
float x1 = positions[i + 0];
|
float x1 = positions[i];
|
||||||
float y1 = positions[i + 1];
|
float y1 = positions[i + 1];
|
||||||
float z1 = positions[i + 2];
|
float z1 = positions[i + 2];
|
||||||
|
|
||||||
@ -84,15 +75,15 @@ public class TNTTrace {
|
|||||||
float y2 = positions[i + 4];
|
float y2 = positions[i + 4];
|
||||||
float z2 = positions[i + 5];
|
float z2 = positions[i + 5];
|
||||||
|
|
||||||
if (!isEqual(y2, y1)) {
|
if (isDifferent(y2, y1)) {
|
||||||
TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1);
|
TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1);
|
||||||
posYSet.add(loc);
|
posYSet.add(loc);
|
||||||
posXYZSet.add(loc);
|
posXYZSet.add(loc);
|
||||||
}
|
}
|
||||||
if (abs(x2 - x1) > abs(z2 - z1)) {
|
if (Math.abs(x2 - x1) > Math.abs(z2 - z1)) {
|
||||||
if (!isEqual(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1));
|
if (isDifferent(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1));
|
||||||
} else {
|
} else {
|
||||||
if (!isEqual(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2));
|
if (isDifferent(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,13 +98,7 @@ public class TNTTrace {
|
|||||||
return posXYZSet;
|
return posXYZSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isEqual(float d1, float d2) {
|
private static boolean isDifferent(float d1, float d2) {
|
||||||
return (d2 - d1) * (d2 - d1) < 0.01;
|
return (d2 - d1) * (d2 - d1) >= 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float abs(float x) {
|
|
||||||
return x < 0 ? -x : x;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren