From c558db31b3a88fc84e4090f1ac7a86f9fe33904c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 13:29:52 +0200 Subject: [PATCH] Fix ObserverTracerListener Fix ObserverTracer Signed-off-by: yoyosource --- .../features/observer/ObserverTracer.java | 7 +++++-- .../observer/ObserverTracerListener.java | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) 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 16427962..a61a2d3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -53,11 +53,13 @@ public class ObserverTracer { } } - public void trace() { + public boolean trace() { + int size = seen.size(); + seen.clear(); blockList.clear(); if (block.getType() != Material.OBSERVER) { - return; + return seen.size() != size; } blockList.add(block); @@ -97,6 +99,7 @@ public class ObserverTracer { calculateSolidBlock(b); } } + return seen.size() != size; } private void spawnParticle(Player player, Location location, Block block) { 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 a2542d61..e01375ab 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java @@ -52,11 +52,20 @@ public class ObserverTracerListener implements Listener { } if (observerTracerMap.containsKey(event.getPlayer())) { ObserverTracer observerTracer = observerTracerMap.get(event.getPlayer()); - if (observerTracer.seen.contains(event.getClickedBlock().getLocation())) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), observerTracer::trace, 1L); - return; - } + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (!observerTracer.trace()) { + createNew(event); + } + observerTracerMap.forEach((player, o) -> { + o.trace(); + }); + }, 1L); + } else { + createNew(event); } + } + + private void createNew(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; }