2020-08-30 02:23:23 +02:00
|
|
|
package de.steamwar.bausystem.tracer;
|
|
|
|
|
|
|
|
import de.steamwar.bausystem.BauSystem;
|
|
|
|
import de.steamwar.core.Core;
|
2020-08-30 07:13:11 +02:00
|
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
|
|
import org.bukkit.Bukkit;
|
2020-08-30 08:01:51 +02:00
|
|
|
import org.bukkit.Location;
|
2020-08-30 07:13:11 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Particle;
|
2020-08-30 02:23:23 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class TNTTracer {
|
2020-08-30 07:13:11 +02:00
|
|
|
private TNTTracer(){}
|
|
|
|
|
2020-08-30 08:01:51 +02:00
|
|
|
static final boolean DEBUG = false;
|
|
|
|
|
2020-08-30 07:13:11 +02:00
|
|
|
private static final Object synchronizer = new Object();
|
|
|
|
private static final TraceCache traceCache = new TraceCache();
|
2020-08-30 02:23:23 +02:00
|
|
|
|
2020-08-30 07:13:11 +02:00
|
|
|
public static void init(){
|
|
|
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
|
|
|
synchronized (synchronizer) {
|
|
|
|
synchronizer.notifyAll();
|
|
|
|
}
|
|
|
|
}, 1, 20);
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(BauSystem.getPlugin(), () -> {
|
|
|
|
while (true) {
|
|
|
|
synchronized (synchronizer) {
|
|
|
|
try {
|
|
|
|
synchronizer.wait();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run();
|
|
|
|
}
|
|
|
|
});
|
2020-08-30 02:23:23 +02:00
|
|
|
}
|
|
|
|
|
2020-08-30 07:13:11 +02:00
|
|
|
private static void run(){
|
|
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
|
|
if (DEBUG) {
|
2020-08-30 12:01:47 +02:00
|
|
|
String actionBar = "§e" + TraceManager.getAllTraces().size() + " §cTraces §e" + ShowManager.get(p).getShowRadius() + " §cRadius";
|
2020-08-30 07:13:11 +02:00
|
|
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
|
|
|
}
|
|
|
|
|
2020-08-30 12:01:47 +02:00
|
|
|
boolean dirty = ShowManager.get(p).isDirty();
|
|
|
|
if (ShowManager.get(p).getDisplayType() == ShowManager.DisplayType.Block && !dirty) {
|
2020-08-30 07:13:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
2020-08-30 07:45:32 +02:00
|
|
|
Set<TraceCache.Loc> toHide = traceCache.update(p, dirty);
|
2020-08-30 07:13:11 +02:00
|
|
|
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
|
|
|
|
|
|
|
hideBlockTraces(toHide, p);
|
2020-08-30 12:01:47 +02:00
|
|
|
showTraces(toShow, ShowManager.get(p).getDisplayType(), p);
|
2020-08-30 07:13:11 +02:00
|
|
|
}
|
2020-08-30 02:23:23 +02:00
|
|
|
}
|
|
|
|
|
2020-08-30 07:13:11 +02:00
|
|
|
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
|
|
|
|
if (locs.isEmpty()) return;
|
|
|
|
|
|
|
|
for (TraceCache.Loc l : locs) {
|
2020-08-30 08:01:51 +02:00
|
|
|
hideBlock(player, l.x, l.y - 0.49F, l.z);
|
2020-08-30 07:13:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-30 07:45:32 +02:00
|
|
|
private static void showTraces(Set<TraceCache.Loc> locs, ShowManager.DisplayType displayMode, Player player) {
|
2020-08-30 07:13:11 +02:00
|
|
|
if (locs.isEmpty()) return;
|
|
|
|
|
|
|
|
for (TraceCache.Loc l : locs) {
|
2020-08-30 07:45:32 +02:00
|
|
|
if (displayMode == ShowManager.DisplayType.Block) {
|
2020-08-30 08:01:51 +02:00
|
|
|
showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14));
|
2020-08-30 07:13:11 +02:00
|
|
|
} else {
|
2020-08-30 08:01:51 +02:00
|
|
|
showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
2020-08-30 07:13:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Material getMaterial(TraceCache.Loc l){
|
|
|
|
switch(Core.getVersion()){
|
2020-08-30 02:23:23 +02:00
|
|
|
case 15:
|
2020-08-30 07:13:11 +02:00
|
|
|
return TNTTracer_15.getMaterial(l.updatePoint);
|
2020-08-30 02:23:23 +02:00
|
|
|
default:
|
2020-08-30 07:13:11 +02:00
|
|
|
return TNTTracer_12.getMaterial();
|
2020-08-30 02:23:23 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-30 08:01:51 +02:00
|
|
|
|
|
|
|
private static void showCorner(Player player, float x, float y, float z, Particle particle) {
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.00F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.00F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.00F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
player.spawnParticle(particle, makeLocation(x + 0.98F, y + 0.98F, z + 0.98F), 1, 0F, 0F, 0F, 0.001);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void showBlock(Player p, float x, float y, float z, Material block, byte b) {
|
|
|
|
if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) {
|
|
|
|
p.sendBlockChange(makeLocation(x, y, z), block, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void hideBlock(Player p, float x, float y, float z) {
|
|
|
|
if (makeLocation(x, y, z).getBlock().getType() == Material.AIR) {
|
|
|
|
p.sendBlockChange(makeLocation(x, y, z), Material.AIR, (byte) 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
|
|
|
private static Location makeLocation(float x, float y, float z) {
|
|
|
|
location.setX(x);
|
|
|
|
location.setY(y);
|
|
|
|
location.setZ(z);
|
|
|
|
return location;
|
|
|
|
}
|
2020-08-30 02:23:23 +02:00
|
|
|
}
|