Add ObserverTracer
Add ObserverTracerListener Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
adaff21d0f
Commit
d3249f8968
@ -38,14 +38,36 @@ public class ObserverTracer {
|
|||||||
private static final Set<BlockFace> ALLOWED = EnumSet.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
|
private static final Set<BlockFace> ALLOWED = EnumSet.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
|
private Block block;
|
||||||
private Set<Location> seen = new HashSet<>();
|
private Set<Location> seen = new HashSet<>();
|
||||||
private List<Block> blockList = new ArrayList<>();
|
private List<Block> blockList = new ArrayList<>();
|
||||||
|
|
||||||
public ObserverTracer(Player player) {
|
private int retrace = 0;
|
||||||
|
|
||||||
|
public ObserverTracer(Player player, Block block) {
|
||||||
this.player = player;
|
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) {
|
if (block.getType() != Material.OBSERVER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -59,7 +81,7 @@ public class ObserverTracer {
|
|||||||
|
|
||||||
Block b = blockList.remove(0);
|
Block b = blockList.remove(0);
|
||||||
seen.add(b.getLocation());
|
seen.add(b.getLocation());
|
||||||
spawnParticle(player, b.getLocation());
|
spawnParticle(player, b.getLocation(), b);
|
||||||
|
|
||||||
switch (b.getType()) {
|
switch (b.getType()) {
|
||||||
case OBSERVER:
|
case OBSERVER:
|
||||||
@ -86,15 +108,8 @@ public class ObserverTracer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnParticle(Player player, Location location) {
|
private void spawnParticle(Player player, Location location, Block block) {
|
||||||
player.spawnParticle(Particle.FLAME, location.clone().add(0, 0, 0), 1, 0, 0, 0, 0);
|
player.spawnParticle(Particle.FLAME, location.clone().add(0.5, 0.5, 0.5), 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 calculateObserver(Block block) {
|
private void calculateObserver(Block block) {
|
||||||
|
@ -19,24 +19,49 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.observer;
|
package de.steamwar.bausystem.features.observer;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class ObserverTracerListener implements Listener {
|
public class ObserverTracerListener implements Listener {
|
||||||
|
|
||||||
|
private Map<Player, ObserverTracer> observerTracerMap = new HashMap<>();
|
||||||
|
|
||||||
|
public ObserverTracerListener() {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
|
observerTracerMap.forEach((player, observerTracer) -> observerTracer.show());
|
||||||
|
}, 15L, 15L);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
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) {
|
||||||
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren