From 9c050370a9046bda622803b1d9c2eae1f39218bc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 1 Aug 2021 21:40:21 +0200 Subject: [PATCH] Add ObserverTraceCommand.enable Add ObserverTraceCommand.disable Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 ++ .../features/observer/ObserverTracer.java | 3 +++ .../features/observer/ObserverTracerCommand.java | 15 ++++++++++++++- .../features/observer/ObserverTracerListener.java | 13 +++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 84c72d32..60cac58f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -328,6 +328,8 @@ LOADTIMER_SUMARY_STATS_FREQ=§7Belade Frequenz: §e{0}/m§8, §7Schuss Frequenz: # Observer OBSERVER_HELP = §7Rechts-Klicke einen Observer um den Trace zu bekommen. Hierfür müssen Flammenpartikel an sein. Die Partikel werden im Block angezeigt. +OBSERVER_ENABLE = §7Observer Trace gestartet +OBSERVER_DISABLE = §7Observer Trace gestoppt OBSERVER_DELETE = §7Observer Trace gelöscht OBSERVER_RETRACE_DONE = §7Observer Trace neu berechnet OBSERVER_RETRACE_NO-TRACE = §7Kein Observer Trace zum neu berechnen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index 793289e7..fe9f9b44 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -49,6 +49,9 @@ public class ObserverTracer { } public void show() { + if (!ObserverTracerListener.enabled.contains(player)) { + return; + } for (Point p : seen) { Location location = p.toLocation(player); spawnParticle(player, location, location.getBlock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java index de1cf3a1..ed9d422b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java @@ -38,8 +38,21 @@ public class ObserverTracerCommand extends SWCommand { BauSystem.MESSAGE.sendPrefixless("OBSERVER_HELP", p); } + @Register(value = "enable") + public void enable(Player p) { + ObserverTracerListener.enabled.add(p); + BauSystem.MESSAGE.send("OBSERVER_ENABLE", p); + } + + @Register(value = "disable") + public void disable(Player p) { + ObserverTracerListener.enabled.remove(p); + ObserverTracerListener.observerTracerMap.remove(p); + BauSystem.MESSAGE.send("OBSERVER_DISABLE", p); + } + @Register(value = "delete") - public void hide(Player p) { + public void delete(Player p) { ObserverTracerListener.observerTracerMap.remove(p); BauSystem.MESSAGE.send("OBSERVER_DELETE", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java index e01375ab..276e5acf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java @@ -29,14 +29,18 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; @Linked(LinkageType.LISTENER) public class ObserverTracerListener implements Listener { + static Set enabled = new HashSet<>(); static Map observerTracerMap = new HashMap<>(); public ObserverTracerListener() { @@ -47,6 +51,9 @@ public class ObserverTracerListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (!enabled.contains(event.getPlayer())) { + return; + } if (event.getClickedBlock() == null) { return; } @@ -76,8 +83,14 @@ public class ObserverTracerListener implements Listener { } } + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + enabled.add(event.getPlayer()); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { + enabled.remove(event.getPlayer()); observerTracerMap.remove(event.getPlayer()); } }