91 Zeilen
3.1 KiB
Java
91 Zeilen
3.1 KiB
Java
package de.steamwar.bausystem.tracer;
|
|
|
|
import de.steamwar.bausystem.BauSystem;
|
|
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
|
import de.steamwar.core.Core;
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Particle;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.Set;
|
|
|
|
import static de.steamwar.bausystem.tracer.TraceUtils.DEBUG;
|
|
|
|
public class TNTTracer {
|
|
private TNTTracer(){}
|
|
|
|
private static final Object synchronizer = new Object();
|
|
private static final TraceCache traceCache = new TraceCache();
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
|
|
private static void run(){
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
if (DEBUG) {
|
|
String actionBar = TracerUpdater.actionBar(p);
|
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
|
}
|
|
|
|
boolean dirty = TracerUpdater.needsUpdate(p);
|
|
if (TracerUpdater.getDisplayType(p) == ShowManager.DisplayType.Block && !dirty) {
|
|
continue;
|
|
}
|
|
Set<TraceCache.Loc> toHide = traceCache.update(p, dirty);
|
|
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
|
|
|
hideBlockTraces(toHide, p);
|
|
showTraces(toShow, TracerUpdater.getDisplayType(p), p);
|
|
}
|
|
}
|
|
|
|
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
|
|
if (locs.isEmpty()) return;
|
|
|
|
for (TraceCache.Loc l : locs) {
|
|
TraceUtils.hideBlock(player, l.x, l.y - 0.49F, l.z);
|
|
}
|
|
}
|
|
|
|
private static void showTraces(Set<TraceCache.Loc> locs, ShowManager.DisplayType displayMode, Player player) {
|
|
if (locs.isEmpty()) return;
|
|
|
|
for (TraceCache.Loc l : locs) {
|
|
if (displayMode == ShowManager.DisplayType.Block) {
|
|
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14));
|
|
} else {
|
|
TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
|
}
|
|
}
|
|
}
|
|
|
|
private static Material getMaterial(TraceCache.Loc l){
|
|
switch(Core.getVersion()){
|
|
case 15:
|
|
return TNTTracer_15.getMaterial(l.updatePoint);
|
|
default:
|
|
return TNTTracer_12.getMaterial();
|
|
}
|
|
}
|
|
}
|