SteamWar/BauSystem2.0
Archiviert
12
0

Fix ObserverTracerListener

Fix ObserverTracer

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-06-20 09:18:17 +02:00
Ursprung 2a4f980813
Commit 2c88381146
2 geänderte Dateien mit 11 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -39,31 +39,23 @@ public class ObserverTracer {
private Player player; private Player player;
private Block block; private Block block;
private Set<Location> seen = new HashSet<>(); Set<Location> seen = new HashSet<>();
private List<Block> blockList = new ArrayList<>(); private List<Block> blockList = new ArrayList<>();
private int retrace = 0;
public ObserverTracer(Player player, Block block) { public ObserverTracer(Player player, Block block) {
this.player = player; this.player = player;
this.block = block; this.block = block;
} }
public void show() { public void show() {
retrace++;
if (retrace > 4) {
retrace = 0;
seen.clear();
blockList.clear();
trace();
return;
}
for (Location l : seen) { for (Location l : seen) {
spawnParticle(player, l, l.getBlock()); spawnParticle(player, l, l.getBlock());
} }
} }
public void trace() { public void trace() {
seen.clear();
blockList.clear();
if (block.getType() != Material.OBSERVER) { if (block.getType() != Material.OBSERVER) {
return; return;
} }

Datei anzeigen

@ -47,15 +47,19 @@ public class ObserverTracerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getMaterial() == Material.OBSERVER) { if (event.getClickedBlock() == null) {
return; return;
} }
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;
}
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return; return;
} }
if (event.getClickedBlock() == null) {
return;
}
if (event.getClickedBlock().getType() == Material.OBSERVER) { if (event.getClickedBlock().getType() == Material.OBSERVER) {
ObserverTracer observerTracer = new ObserverTracer(event.getPlayer(), event.getClickedBlock()); ObserverTracer observerTracer = new ObserverTracer(event.getPlayer(), event.getClickedBlock());
observerTracer.trace(); observerTracer.trace();