From f1b3b27c1419aee0868b24d5755802db5ddb21d7 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Mon, 22 Apr 2024 20:15:05 +0200 Subject: [PATCH] Trace now closes on being deleted --- .../bausystem/features/tracer/TraceManager.java | 6 ++++++ .../bausystem/features/tracer/TraceRecorder.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java index d735fe8d..582ddba7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java @@ -132,6 +132,11 @@ public class TraceManager implements Listener { * @param trace the trace to be removed */ public boolean remove(Trace trace) { + Optional activeTrace = TraceRecorder.instance.getActiveTraceForRegion(trace.getRegion()); + if (activeTrace.isPresent() && activeTrace.get() == trace) { + TraceRecorder.instance.stopRecording(trace.getRegion()); + } + Map 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 -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java index 52b87156..76a76025 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java @@ -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 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;