From 1b9afcd5daf7274adf6ceeb31363b5793a015e08 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 2 Apr 2019 16:43:42 +0200 Subject: [PATCH] Funktionierender Tracer --- src/de/warking/bausystem/world/TNTTracer.java | 46 +++++-------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/src/de/warking/bausystem/world/TNTTracer.java b/src/de/warking/bausystem/world/TNTTracer.java index a5569a9..ae4e2ce 100644 --- a/src/de/warking/bausystem/world/TNTTracer.java +++ b/src/de/warking/bausystem/world/TNTTracer.java @@ -6,14 +6,12 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.scheduler.BukkitTask; @@ -29,13 +27,11 @@ public class TNTTracer implements Listener, Runnable { private final World world; private final BukkitTask task; private final Set locations; - private final Set tnts; private boolean printed; private TNTTracer(World world){ this.world = world; this.locations = new HashSet<>(); - this.tnts = new HashSet<>(); this.printed = false; this.task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this, 1, 1); Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); @@ -44,7 +40,6 @@ public class TNTTracer implements Listener, Runnable { private void stop(){ task.cancel(); - tnts.clear(); HandlerList.unregisterAll(this); } @@ -71,7 +66,6 @@ public class TNTTracer implements Listener, Runnable { } public void hide(){ - end(); if(!printed) return; for(Location l : locations){ @@ -80,32 +74,7 @@ public class TNTTracer implements Listener, Runnable { continue; b.setType(Material.AIR); } - } - - @EventHandler - public void onExplode(EntityExplodeEvent e){ - if(e.getEntityType() != EntityType.PRIMED_TNT) - return; - - tnts.remove((TNTPrimed) e.getEntity()); - } - - @EventHandler - public void onSpawn(EntitySpawnEvent e){ - if(e.getEntityType() != EntityType.PRIMED_TNT) - return; - - if(e.getLocation().getWorld() != world) - return; - - if(tnts.size() > 150){ - for(Player p : Bukkit.getOnlinePlayers()){ - p.sendMessage(BauSystem.PREFIX + "§cEs können nicht mehr als 150 TNT verfolgt werden!"); - } - return; - } - - tnts.add((TNTPrimed) e.getEntity()); + end(); } @EventHandler @@ -117,8 +86,15 @@ public class TNTTracer implements Listener, Runnable { @Override public void run() { - for(TNTPrimed tnt : tnts){ - locations.add(tnt.getLocation()); + if(locations.size() < 20000){ + 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)"); + } + } } }