SteamWar/BauSystem
Archiviert
13
0

Funktionierender Tracer

Dieser Commit ist enthalten in:
Lixfel 2019-04-02 16:43:42 +02:00
Ursprung 7b9c1da8ae
Commit 1b9afcd5da

Datei anzeigen

@ -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<Location> locations;
private final Set<TNTPrimed> 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)");
}
}
}
}