SteamWar/BauSystem2.0
Archiviert
12
0

Reintroduced trace id
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
D4rkr34lm 2024-03-02 22:14:56 +01:00
Ursprung 335e2cc437
Commit 6ec62d9720

Datei anzeigen

@ -36,7 +36,7 @@ public class TraceManager implements Listener {
/**
* List of all current traces
*/
private final List<Trace> traces = new ArrayList<>();
private final Map<Integer, Trace> traces = new HashMap<>();
/**
* A map saving the view flags used by Players
@ -48,6 +48,11 @@ public class TraceManager implements Listener {
*/
private final Map<Player, BundleFilter> bundleFilterMap = new HashMap<>();
/**
* Utility variable to keep track of the next open trace id;
*/
private int nextOpenId = 0;
/** Adds a new trace to the global record
*
* @param trace Trace to be added
@ -55,17 +60,18 @@ public class TraceManager implements Listener {
protected void add(Trace trace){
for(Player player: viewFlagMap.keySet())
trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player));
traces.add(trace);
traces.put(nextOpenId, trace);
nextOpenId++;
}
/** Removes the trace with the given id
*
* @param index index of the trace to be removed
* @param id id of the trace to be removed
*/
public void remove(int index){
public void remove(int id){
for(Player player: viewFlagMap.keySet())
traces.get(index).hide(player);
traces.remove(index);
traces.get(id).hide(player);
traces.remove(id);
}
/** Clears all traces
@ -73,9 +79,10 @@ public class TraceManager implements Listener {
*/
public void clear(){
for (Player player: viewFlagMap.keySet())
for(Trace trace: traces)
for(Trace trace: traces.values())
trace.hide(player);
traces.clear();
nextOpenId = 0;
}
/** Methode to get all traces in a certain region
@ -84,7 +91,7 @@ public class TraceManager implements Listener {
* @return All traces recorded in the given Region
*/
public Set<Trace> get(Region region){
return traces.stream()
return traces.values().stream()
.filter((Trace trace) -> trace.getRegion() == region)
.collect(Collectors.toSet());
}
@ -102,10 +109,10 @@ public class TraceManager implements Listener {
/** Methode to get all traces
*
* @return fresh set of all current traces
* @return fresh list of all current traces
*/
public List<Trace> getAll(){
return new ArrayList<>(traces);
return new ArrayList<>(traces.values());
}
/** Toggles trace show on for player
@ -118,7 +125,7 @@ public class TraceManager implements Listener {
viewFlagMap.put(player, viewFlags);
bundleFilterMap.put(player, bundleFilter);
for(Trace trace: traces)
for(Trace trace: traces.values())
trace.render(player, viewFlags, bundleFilter);
}
@ -127,7 +134,7 @@ public class TraceManager implements Listener {
* @param player
*/
public void hide(Player player){
for(Trace trace: traces)
for(Trace trace: traces.values())
trace.hide(player);
viewFlagMap.remove(player);