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 e4e39b4c..ae1da278 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -38,14 +38,36 @@ public class ObserverTracer { private static final Set ALLOWED = EnumSet.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN); private Player player; + private Block block; private Set seen = new HashSet<>(); private List blockList = new ArrayList<>(); - public ObserverTracer(Player player) { + private int retrace = 0; + + public ObserverTracer(Player player, Block block) { this.player = player; + this.block = block; } - public void trace(Block block) { + public void show() { + retrace++; + if (retrace > 4) { + retrace = 0; + seen.clear(); + blockList.clear(); + trace(); + return; + } + for (Location l : seen) { + spawnParticle(player, l, l.getBlock()); + } + } + + public boolean shouldHide(Location location) { + return seen.contains(location); + } + + public void trace() { if (block.getType() != Material.OBSERVER) { return; } @@ -59,7 +81,7 @@ public class ObserverTracer { Block b = blockList.remove(0); seen.add(b.getLocation()); - spawnParticle(player, b.getLocation()); + spawnParticle(player, b.getLocation(), b); switch (b.getType()) { case OBSERVER: @@ -86,15 +108,8 @@ public class ObserverTracer { } } - private void spawnParticle(Player player, Location location) { - player.spawnParticle(Particle.FLAME, location.clone().add(0, 0, 0), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(1, 0, 0), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(1, 0, 1), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(0, 0, 1), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(0, 1, 0), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(1, 1, 0), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(1, 1, 1), 1, 0, 0, 0, 0); - player.spawnParticle(Particle.FLAME, location.clone().add(0, 1, 1), 1, 0, 0, 0, 0); + private void spawnParticle(Player player, Location location, Block block) { + player.spawnParticle(Particle.FLAME, location.clone().add(0.5, 0.5, 0.5), 1, 0, 0, 0, 0); } private void calculateObserver(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 34b7de77..ef94d336 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java @@ -19,24 +19,49 @@ package de.steamwar.bausystem.features.observer; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.Player; 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.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; @Linked(LinkageType.LISTENER) public class ObserverTracerListener implements Listener { + private Map observerTracerMap = new HashMap<>(); + + public ObserverTracerListener() { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + observerTracerMap.forEach((player, observerTracer) -> observerTracer.show()); + }, 15L, 15L); + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } + if (event.getClickedBlock() == null) { + return; + } if (event.getClickedBlock().getType() == Material.OBSERVER) { - new ObserverTracer(event.getPlayer()).trace(event.getClickedBlock()); + ObserverTracer observerTracer = new ObserverTracer(event.getPlayer(), event.getClickedBlock()); + observerTracer.trace(); + observerTracerMap.put(event.getPlayer(), observerTracer); } } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + observerTracerMap.remove(event.getPlayer()); + } }