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/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTracer.java

91 Zeilen
3.1 KiB
Java

2020-08-30 02:23:23 +02:00
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.manager.ShowManager;
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;
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;
2020-08-30 07:13:11 +02:00
import static de.steamwar.bausystem.tracer.TraceUtils.DEBUG;
2020-08-30 02:23:23 +02:00
public class TNTTracer {
2020-08-30 07:13:11 +02:00
private TNTTracer(){}
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 07:45:32 +02:00
String actionBar = TracerUpdater.actionBar(p);
2020-08-30 07:13:11 +02:00
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
}
2020-08-30 07:45:32 +02:00
boolean dirty = TracerUpdater.needsUpdate(p);
if (TracerUpdater.getDisplayType(p) == 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 07:45:32 +02:00
showTraces(toShow, TracerUpdater.getDisplayType(p), 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) {
TraceUtils.hideBlock(player, l.x, l.y - 0.49F, l.z);
}
}
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 07:13:11 +02:00
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()){
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
}
}
}