SteamWar/BauSystem
Archiviert
13
0
Dieses Repository wurde am 2024-08-04 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
BauSystem/src/de/steamwar/bausystem/TNTTracer.java

99 Zeilen
2.5 KiB
Java

package de.steamwar.bausystem;
2019-04-02 07:08:27 +02:00
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
2019-04-02 16:43:42 +02:00
import org.bukkit.entity.Entity;
2019-04-02 07:08:27 +02:00
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 {
2019-04-02 07:08:27 +02:00
private BukkitTask task;
2019-04-02 07:08:27 +02:00
private final Set<Location> locations;
private boolean printed;
private boolean active;
2019-04-02 07:08:27 +02:00
TNTTracer(){
2019-04-02 07:08:27 +02:00
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);
2019-04-02 07:08:27 +02:00
}
private void end(){
active = false;
2019-04-02 07:08:27 +02:00
task.cancel();
}
public boolean isActive(){
return active;
}
public boolean isPrinted(){
return printed;
}
public void stop(){
end();
2019-04-02 16:52:08 +02:00
if(!printed){
locations.clear();
}
2019-04-02 07:08:27 +02:00
}
public void show(){
end();
2019-04-02 07:08:27 +02:00
printed = true;
Set<Location> unsetLoc = new HashSet<>();
World world = Bukkit.getWorlds().get(0);
2019-04-02 07:08:27 +02:00
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);
2019-04-02 07:08:27 +02:00
for(Location l : locations){
Block b = world.getBlockAt(l);
if(b.getType() != Material.STAINED_GLASS || b.getData() != 1)
continue;
b.setType(Material.AIR);
}
2019-04-02 16:52:08 +02:00
printed = false;
stop();
2019-04-02 07:08:27 +02:00
}
@Override
public void run() {
2019-04-02 16:43:42 +02:00
if(locations.size() < 20000){
World world = Bukkit.getWorlds().get(0);
2019-04-02 16:43:42 +02:00
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)");
}
}
2019-04-02 07:08:27 +02:00
}
}
}