Simplify Tracer #91
@ -1,95 +1,11 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.material.Step;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static de.steamwar.bausystem.tracer.TraceUtils.actionBar;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class TNTTracer_12 {
|
||||
|
||||
private TNTTracer_12(){}
|
||||
|
||||
private static TracerUpdater tracerUpdater;
|
||||
private static TraceCache traceCache = new TraceCache();
|
||||
|
||||
private static class Synchronizer {}
|
||||
private static final Synchronizer synchronizer = new Synchronizer();
|
||||
|
||||
private static World world;
|
||||
static void worldInit() {
|
||||
if (world != null) return;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
static Material getMaterial(){
|
||||
return Material.STAINED_GLASS;
|
||||
}
|
||||
|
||||
static void init(Plugin plugin, TracerUpdater tracerUpdater) {
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
synchronized (synchronizer) {
|
||||
synchronizer.notifyAll();
|
||||
}
|
||||
}, 1, 20);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
while (true) {
|
||||
synchronized (synchronizer) {
|
||||
try {
|
||||
synchronizer.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
TNTTracer_12.tracerUpdater = tracerUpdater;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (actionBar) {
|
||||
String actionBar = tracerUpdater.actionBar(p);
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||
}
|
||||
|
||||
boolean dirty = tracerUpdater.needsUpdate(p);
|
||||
if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, tracerUpdater, 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, TracerUpdater.DisplayMode displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == TracerUpdater.DisplayMode.Block) {
|
||||
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, Material.STAINED_GLASS, (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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,94 +1,11 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
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.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static de.steamwar.bausystem.tracer.TraceUtils.actionBar;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class TNTTracer_15 {
|
||||
|
||||
private TNTTracer_15(){}
|
||||
|
||||
private static TracerUpdater tracerUpdater;
|
||||
private static TraceCache traceCache = new TraceCache();
|
||||
|
||||
private static class Synchronizer {}
|
||||
private static final Synchronizer synchronizer = new Synchronizer();
|
||||
|
||||
private static World world;
|
||||
static void worldInit() {
|
||||
if (world != null) return;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
static Material getMaterial(boolean updatePoint){
|
||||
return updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS;
|
||||
}
|
||||
|
||||
static void init(Plugin plugin, TracerUpdater tracerUpdater) {
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
synchronized (synchronizer) {
|
||||
synchronizer.notifyAll();
|
||||
}
|
||||
}, 1, 20);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
while (true) {
|
||||
synchronized (synchronizer) {
|
||||
try {
|
||||
synchronizer.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
TNTTracer_15.tracerUpdater = tracerUpdater;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (actionBar) {
|
||||
String actionBar = tracerUpdater.actionBar(p);
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||
}
|
||||
|
||||
boolean dirty = tracerUpdater.needsUpdate(p);
|
||||
if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, tracerUpdater, 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, TracerUpdater.DisplayMode displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == TracerUpdater.DisplayMode.Block) {
|
||||
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, (l.updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS), (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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
public class TracerGuiUpdater {
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
package de.steamwar.bausystem;
|
||||
|
||||
import de.steamwar.bausystem.commands.*;
|
||||
import de.steamwar.bausystem.tracer.MoveEvent;
|
||||
import de.steamwar.bausystem.tracer.TNTListener;
|
||||
import de.steamwar.bausystem.tracer.TraceListener;
|
||||
import de.steamwar.bausystem.tracer.TNTTracer;
|
||||
import de.steamwar.bausystem.tracer.TraceUtils;
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.world.AFKStopper;
|
||||
import de.steamwar.bausystem.world.ArenaSection;
|
||||
import de.steamwar.bausystem.world.BauScoreboard;
|
||||
@ -104,15 +101,10 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TNTListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new MoveEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TraceListener(), this);
|
||||
new AFKStopper();
|
||||
if (Core.getVersion() == 15) {
|
||||
TNTTracer.init15();
|
||||
} else {
|
||||
TNTTracer.init12();
|
||||
}
|
||||
TNTTracer.init();
|
||||
|
||||
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
||||
}
|
||||
@ -277,16 +269,10 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
attachment.setPermission("worldedit.calc", true);
|
||||
attachment.setPermission("worldedit.fill", true);*/
|
||||
|
||||
RecordManager.worldInit();
|
||||
TNTTracer.worldInit();
|
||||
TraceUtils.locationInit();
|
||||
|
||||
ShowManager.add(p);
|
||||
|
||||
if (Core.getVersion() == 15){
|
||||
ShowManager.add(p);
|
||||
if (Core.getVersion() == 15)
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -301,8 +287,9 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
ItemStack stack = e.getCursor();
|
||||
if (stack == null) return;
|
||||
if (!stack.hasItemMeta()) return;
|
||||
if (stack == null || !stack.hasItemMeta())
|
||||
return;
|
||||
assert stack.getItemMeta() != null;
|
||||
if (stack.getItemMeta().hasEnchants()) {
|
||||
for (Enchantment en : Enchantment.values()) {
|
||||
if (stack.getEnchantmentLevel(en) > en.getMaxLevel())
|
||||
|
@ -1,17 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class MoveEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
ShowManager.get(p).move(p);
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.manager.TNTManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class TNTListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
|
||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) {
|
||||
RecordManager.startAuto();
|
||||
}
|
||||
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO) {
|
||||
RecordManager.updateAuto();
|
||||
}
|
||||
|
||||
TNTManager.explode((TNTPrimed) event.getEntity());
|
||||
}
|
||||
|
||||
/*private void onEntityExplode12(EntityExplodeEvent event) {
|
||||
if(TNTTracer12.getStatus() != TNTTracer12.Status.RECORD) return;
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
TNTPrimed entity = (TNTPrimed) event.getEntity();
|
||||
TNTTracer12.remove(entity);
|
||||
}
|
||||
|
||||
private void onEntityExplode15(EntityExplodeEvent event) {
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
if (TraceRecorder.getStatus() == TraceRecorder.Status.IDLE_AUTO || TraceRecorder.getStatus() == TraceRecorder.Status.RECORD_AUTO) {
|
||||
TraceRecorder.start();
|
||||
}
|
||||
TraceRecorder.explode((TNTPrimed) event.getEntity());
|
||||
}*/
|
||||
}
|
@ -4,15 +4,26 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.trace.TNTTrace;
|
||||
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.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class TNTTracer {
|
||||
import static de.steamwar.bausystem.tracer.TraceUtils.DEBUG;
|
||||
|
||||
private static TracerUpdater tracerUpdater = new TracerUpdater() {
|
||||
public class TNTTracer {
|
||||
private TNTTracer(){}
|
||||
|
||||
private static final Object synchronizer = new Object();
|
||||
private static final TraceCache traceCache = new TraceCache();
|
||||
|
||||
private static final TracerUpdater tracerUpdater = new TracerUpdater() {
|
||||
@Override
|
||||
public Set<TraceCache.Loc> updateLocations(Player player) {
|
||||
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
|
||||
@ -61,23 +72,71 @@ public class TNTTracer {
|
||||
}
|
||||
};
|
||||
|
||||
public static void init15() {
|
||||
TNTTracer_15.init(BauSystem.getPlugin(), tracerUpdater);
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void init12() {
|
||||
TNTTracer_12.init(BauSystem.getPlugin(), tracerUpdater);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
public static void worldInit() {
|
||||
switch (Core.getVersion()) {
|
||||
case 15:
|
||||
TNTTracer_15.worldInit();
|
||||
break;
|
||||
default:
|
||||
TNTTracer_12.worldInit();
|
||||
break;
|
||||
boolean dirty = tracerUpdater.needsUpdate(p);
|
||||
if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, tracerUpdater, 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, TracerUpdater.DisplayMode displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == TracerUpdater.DisplayMode.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TraceActionbar {
|
||||
private TraceActionbar(){}
|
||||
|
||||
private static double round(double toRound, int digits) {
|
||||
int x = (int)Math.pow(10, digits);
|
||||
|
33
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java
Normale Datei
33
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java
Normale Datei
@ -0,0 +1,33 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.manager.TNTManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class TraceListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
|
||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO)
|
||||
RecordManager.startAuto();
|
||||
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO)
|
||||
RecordManager.updateAuto();
|
||||
|
||||
TNTManager.explode((TNTPrimed) event.getEntity());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
ShowManager.get(p).move(p);
|
||||
}
|
||||
}
|
@ -7,14 +7,11 @@ import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TraceUtils {
|
||||
private TraceUtils(){}
|
||||
|
||||
private static Location location;
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
public static boolean actionBar = false;
|
||||
|
||||
public static void locationInit() {
|
||||
location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
}
|
||||
private static Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
|
||||
public 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);
|
||||
@ -40,7 +37,7 @@ public class TraceUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Location makeLocation(float x, float y, float z) {
|
||||
private static Location makeLocation(float x, float y, float z) {
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
@ -15,11 +15,7 @@ public class RecordManager {
|
||||
static Status status = Status.IDLE;
|
||||
public static Integer activeFrameID = null;
|
||||
|
||||
static World world;
|
||||
public static void worldInit() {
|
||||
if (world != null) return;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
}
|
||||
static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public static void tracer(Player player, String[] args) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren