From 75edfc8375e3be3ec27c816506f01495198b52ab Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sat, 2 Mar 2024 22:10:36 +0100 Subject: [PATCH] Made for easier interfacing with api by allowing to toggle show from manager --- .../bausystem/features/tracer/Trace.java | 2 + .../features/tracer/TraceCommand.java | 15 +++++--- .../features/tracer/TraceManager.java | 38 +++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java index 30b4c2b4..97cff2f5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java @@ -217,6 +217,8 @@ public class Trace { REntityServer server = serverMap.get(player); if(server == null) return; + bundleFilterMap.remove(player); + viewFlagMap.remove(player); server.close(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index f048e1be..fd4f9eab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -60,17 +60,20 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player); } + @Register(value = "auto", description = "TRACE_COMMAND_HELP_SHOW") + public void auto (Player player) { + Region region = Region.getRegion(player.getLocation()); + recorder.toggleAutoTrace(region); + } + @Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW") public void show(Player player, @OptionalValue("STRICT") BundleFilter filter, ViewFlag... flags){ - Region region = Region.getRegion(player.getLocation()); - - for(Trace trace : manager.get(region)){ - trace.render(player, flags, filter); - } - + manager.show(player, flags, filter); BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", player); } + + @ClassMapper(value = BundleFilter.class, local = true) public TypeMapper bundleFilterClassMapper() { return new TypeMapper() { 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 f697bb69..eebcda5c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceManager.java @@ -19,9 +19,14 @@ package de.steamwar.bausystem.features.tracer; +import de.steamwar.bausystem.features.tracer.rendering.BundleFilter; +import de.steamwar.bausystem.features.tracer.rendering.ViewFlag; import de.steamwar.bausystem.region.Region; import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; import java.util.*; import java.util.stream.Collectors; @@ -33,11 +38,23 @@ public class TraceManager implements Listener { */ private final List traces = new ArrayList<>(); + /** + * A map saving the view flags used by Players + */ + private final Map viewFlagMap = new HashMap<>(); + + /** + * A map saving the bundle filter used by Players + */ + private final Map bundleFilterMap = new HashMap<>(); + /** Adds a new trace to the global record * * @param trace Trace to be added */ protected void add(Trace trace){ + for(Player player: viewFlagMap.keySet()) + trace.render(player, viewFlagMap.get(player), bundleFilterMap.get(player)); traces.add(trace); } @@ -46,6 +63,8 @@ public class TraceManager implements Listener { * @param index index of the trace to be removed */ public void remove(int index){ + for(Player player: viewFlagMap.keySet()) + traces.get(index).hide(player); traces.remove(index); } @@ -53,6 +72,9 @@ public class TraceManager implements Listener { * */ public void clear(){ + for (Player player: viewFlagMap.keySet()) + for(Trace trace: traces) + trace.hide(player); traces.clear(); } @@ -85,4 +107,20 @@ public class TraceManager implements Listener { public List getAll(){ return new ArrayList<>(traces); } + + public void show(Player player, ViewFlag[] viewFlags, BundleFilter bundleFilter) { + viewFlagMap.put(player, viewFlags); + bundleFilterMap.put(player, bundleFilter); + + for(Trace trace: traces) + trace.render(player, viewFlags, bundleFilter); + } + + public void hide(Player player){ + for(Trace trace: traces) + trace.hide(player); + + viewFlagMap.remove(player); + bundleFilterMap.remove(player); + }; }