SteamWar/BauSystem2.0
Archiviert
12
0

Update Trace and TraceManager
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-04-08 11:56:52 +02:00
Ursprung 41d4ce2472
Commit b8e79f9c55
2 geänderte Dateien mit 23 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -32,8 +32,9 @@ import lombok.Getter;
import org.bukkit.entity.Player;
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
*/
@ -61,8 +62,13 @@ public class Trace {
/**
* List of all used ids
*/
@Getter
private final List<String> usedIds = new ArrayList();
public List<String> getUsedIds() {
return getRecords()
.stream()
.map(TNTRecord::getTntId)
.map(i -> i + "")
.collect(Collectors.toList());
}
/**
* A map of players -> REntityServers for rendering traces to a player
@ -89,9 +95,7 @@ public class Trace {
* @return next open record id
*/
protected int getAndIncrementNextOpenRecordId() {
nextOpenRecordId++;
usedIds.add(Integer.toString(nextOpenRecordId));
return nextOpenRecordId;
return ++nextOpenRecordId;
}
/**

Datei anzeigen

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