package de.steamwar.bausystem; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.scheduler.BukkitTask; import java.util.HashSet; import java.util.Set; public class TNTTracer implements Runnable { private BukkitTask task; private final Set locations; private boolean printed; private boolean active; TNTTracer(){ this.locations = new HashSet<>(); this.printed = false; this.active = false; } public void start(){ active = true; this.task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this, 1, 1); } private void end(){ active = false; task.cancel(); } public boolean isActive(){ return active; } public boolean isPrinted(){ return printed; } public void stop(){ end(); if(!printed){ locations.clear(); } } public void show(){ end(); printed = true; Set unsetLoc = new HashSet<>(); World world = Bukkit.getWorlds().get(0); for(Location l : locations){ Block b = world.getBlockAt(l); if(b.getType() != Material.AIR){ unsetLoc.add(l); continue; } b.setType(Material.STAINED_GLASS); b.setData((byte) 1); } locations.removeAll(unsetLoc); } public void hide(){ if(!printed) return; World world = Bukkit.getWorlds().get(0); for(Location l : locations){ Block b = world.getBlockAt(l); if(b.getType() != Material.STAINED_GLASS || b.getData() != 1) continue; b.setType(Material.AIR); } printed = false; stop(); } @Override public void run() { if(locations.size() < 20000){ World world = Bukkit.getWorlds().get(0); for(Entity e : world.getEntitiesByClass(TNTPrimed.class)){ locations.add(e.getLocation()); } if(locations.size() >= 20000){ for(Player p : world.getPlayers()){ p.sendMessage(BauSystem.PREFIX + "§cEs werden keine weiteren Positionen mehr erfasst (20.000 Block Limit)"); } } } } }