SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
2 geänderte Dateien mit 23 neuen und 15 gelöschten Zeilen
Nur Änderungen aus Commit b8e79f9c55 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -32,8 +32,9 @@ import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class Trace { public class Trace { // TODO: Add UUID for file saving and so on!
/** /**
* Region this trace has been recorded in * Region this trace has been recorded in
*/ */
@ -61,8 +62,13 @@ public class Trace {
/** /**
* List of all used ids * List of all used ids
*/ */
@Getter public List<String> getUsedIds() {
private final List<String> usedIds = new ArrayList(); return getRecords()
.stream()
.map(TNTRecord::getTntId)
.map(i -> i + "")
.collect(Collectors.toList());
}
/** /**
* A map of players -> REntityServers for rendering traces to a player * A map of players -> REntityServers for rendering traces to a player
@ -89,9 +95,7 @@ public class Trace {
* @return next open record id * @return next open record id
*/ */
protected int getAndIncrementNextOpenRecordId() { protected int getAndIncrementNextOpenRecordId() {
nextOpenRecordId++; return ++nextOpenRecordId;
usedIds.add(Integer.toString(nextOpenRecordId));
return nextOpenRecordId;
} }
/** /**

Datei anzeigen

@ -27,7 +27,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Linked @Linked
public class TraceManager implements Listener { public class TraceManager implements Listener {
@ -36,6 +35,8 @@ public class TraceManager implements Listener {
*/ */
private final Map<Integer, Trace> traces = new HashMap<>(); private final Map<Integer, Trace> traces = new HashMap<>();
private final Map<Region, Map<Integer, Trace>> tracesByRegion = new HashMap<>();
/** /**
* A map saving the view flags used by Players * A map saving the view flags used by Players
*/ */
@ -62,6 +63,7 @@ public class TraceManager implements Listener {
trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player)); trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player));
} }
traces.put(nextOpenId, trace); traces.put(nextOpenId, trace);
tracesByRegion.computeIfAbsent(trace.getRegion(), region -> new HashMap<>()).put(nextOpenId, trace);
nextOpenId++; nextOpenId++;
return nextOpenId; return nextOpenId;
} }
@ -77,7 +79,10 @@ public class TraceManager implements Listener {
for (Player player : viewFlagMap.keySet()) { for (Player player : viewFlagMap.keySet()) {
traces.get(id).hide(player); traces.get(id).hide(player);
} }
traces.remove(id); Trace trace = traces.remove(id);
if (trace != null) {
tracesByRegion.get(trace.getRegion()).remove(id);
}
return true; return true;
} }
@ -91,6 +96,7 @@ public class TraceManager implements Listener {
} }
} }
traces.clear(); traces.clear();
tracesByRegion.clear();
nextOpenId = 0; nextOpenId = 0;
} }
@ -100,10 +106,8 @@ public class TraceManager implements Listener {
* @param region Region to look for traces in * @param region Region to look for traces in
* @return All traces recorded in the given Region * @return All traces recorded in the given Region
*/ */
public Set<Trace> get(Region region) { public Collection<Trace> get(Region region) {
return traces.values().stream() return tracesByRegion.getOrDefault(region, Collections.emptyMap()).values();
.filter((Trace trace) -> trace.getRegion() == region)
.collect(Collectors.toSet());
} }
/** /**
@ -122,10 +126,10 @@ public class TraceManager implements Listener {
/** /**
* Methode to get all traces * Methode to get all traces
* *
* @return fresh list of all current traces * @return internal list of all current traces
*/ */
public List<Trace> getAll() { public Collection<Trace> getAll() {
return new ArrayList<>(traces.values()); return traces.values();
} }
/** /**