SteamWar/BauSystem2.0
Archiviert
12
0

Trace now closes on being deleted #238

Zusammengeführt
YoyoNow hat 1 Commits von trace/trace-clear-not-stopping-trace-fix nach master 2024-04-22 20:20:10 +02:00 zusammengeführt
2 geänderte Dateien mit 22 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -132,6 +132,11 @@ public class TraceManager implements Listener {
* @param trace the trace to be removed
*/
public boolean remove(Trace trace) {
Optional<Trace> activeTrace = TraceRecorder.instance.getActiveTraceForRegion(trace.getRegion());
if (activeTrace.isPresent() && activeTrace.get() == trace) {
TraceRecorder.instance.stopRecording(trace.getRegion());
}
Map<Integer, Trace> traces = tracesByRegion.getOrDefault(trace.getRegion(), Collections.emptyMap());
Integer traceId = traces.entrySet().stream()
.filter(entry -> entry.getValue() == trace)
@ -148,6 +153,7 @@ public class TraceManager implements Listener {
* Clears all traces
*/
public void clear(Region region) {
TraceRecorder.instance.stopRecording(region);
showDataPerRegionPerPlayer.getOrDefault(region, new HashMap<>())
.keySet()
.forEach(player -> {

Datei anzeigen

@ -185,6 +185,22 @@ public class TraceRecorder implements Listener {
return activeTraces.containsKey(region);
}
/**
* Get the trace that is currently recorded in the given region
*
* @param region the region to get the trace for
* @return the trace recorded in region or empty if no trace is recorded in region
*/
public Optional<Trace> getActiveTraceForRegion(Region region) {
TraceRecordingWrapper traceWrapper = activeTraces.get(region);
if (traceWrapper == null) {
return Optional.empty();
} else {
return Optional.of(traceWrapper.getTrace());
}
}
public long getStartTimeOfTraceInRegion(Region region) {
TraceRecordingWrapper wrapper = activeTraces.get(region);
if (wrapper == null) return 0;