Trace Refactor #233
@ -36,7 +36,7 @@ public class TraceManager implements Listener {
|
|||||||
/**
|
/**
|
||||||
* List of all current traces
|
* 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
|
* 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<>();
|
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
|
/** Adds a new trace to the global record
|
||||||
*
|
*
|
||||||
* @param trace Trace to be added
|
* @param trace Trace to be added
|
||||||
@ -55,17 +60,18 @@ public class TraceManager implements Listener {
|
|||||||
protected void add(Trace trace){
|
protected void add(Trace trace){
|
||||||
for(Player player: viewFlagMap.keySet())
|
for(Player player: viewFlagMap.keySet())
|
||||||
trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player));
|
trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player));
|
||||||
traces.add(trace);
|
traces.put(nextOpenId, trace);
|
||||||
|
nextOpenId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the trace with the given id
|
/** 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())
|
for(Player player: viewFlagMap.keySet())
|
||||||
traces.get(index).hide(player);
|
traces.get(id).hide(player);
|
||||||
traces.remove(index);
|
traces.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Clears all traces
|
/** Clears all traces
|
||||||
@ -73,9 +79,10 @@ public class TraceManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
public void clear(){
|
public void clear(){
|
||||||
for (Player player: viewFlagMap.keySet())
|
for (Player player: viewFlagMap.keySet())
|
||||||
for(Trace trace: traces)
|
for(Trace trace: traces.values())
|
||||||
trace.hide(player);
|
trace.hide(player);
|
||||||
traces.clear();
|
traces.clear();
|
||||||
|
nextOpenId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Methode to get all traces in a certain region
|
/** 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
|
* @return All traces recorded in the given Region
|
||||||
*/
|
*/
|
||||||
public Set<Trace> get(Region region){
|
public Set<Trace> get(Region region){
|
||||||
return traces.stream()
|
return traces.values().stream()
|
||||||
.filter((Trace trace) -> trace.getRegion() == region)
|
.filter((Trace trace) -> trace.getRegion() == region)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
@ -102,10 +109,10 @@ public class TraceManager implements Listener {
|
|||||||
|
|
||||||
/** Methode to get all traces
|
/** Methode to get all traces
|
||||||
*
|
*
|
||||||
* @return fresh set of all current traces
|
* @return fresh list of all current traces
|
||||||
*/
|
*/
|
||||||
public List<Trace> getAll(){
|
public List<Trace> getAll(){
|
||||||
return new ArrayList<>(traces);
|
return new ArrayList<>(traces.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Toggles trace show on for player
|
/** Toggles trace show on for player
|
||||||
@ -118,7 +125,7 @@ public class TraceManager implements Listener {
|
|||||||
viewFlagMap.put(player, viewFlags);
|
viewFlagMap.put(player, viewFlags);
|
||||||
bundleFilterMap.put(player, bundleFilter);
|
bundleFilterMap.put(player, bundleFilter);
|
||||||
|
|
||||||
for(Trace trace: traces)
|
for(Trace trace: traces.values())
|
||||||
trace.render(player, viewFlags, bundleFilter);
|
trace.render(player, viewFlags, bundleFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +134,7 @@ public class TraceManager implements Listener {
|
|||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void hide(Player player){
|
public void hide(Player player){
|
||||||
for(Trace trace: traces)
|
for(Trace trace: traces.values())
|
||||||
trace.hide(player);
|
trace.hide(player);
|
||||||
|
|
||||||
viewFlagMap.remove(player);
|
viewFlagMap.remove(player);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren