Add Trace 1.15 Support and Rework
Dieser Commit ist enthalten in:
Ursprung
90357e4fd2
Commit
619498a898
147
BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java
Normale Datei
147
BauSystem_15/src/de/steamwar/bausystem/tracer/PlayerTraceCache_15.java
Normale Datei
@ -0,0 +1,147 @@
|
|||||||
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.showcallback.TNTShowCallback_15;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import static de.steamwar.bausystem.tracer.TNTTracer_15.square;
|
||||||
|
|
||||||
|
public class PlayerTraceCache_15 {
|
||||||
|
|
||||||
|
private static Location location;
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float[] positions = new float[0];
|
||||||
|
private float[] updatePoints = new float[0];
|
||||||
|
|
||||||
|
private float[] pLocation;
|
||||||
|
private float locationThreshold = square(10.0F);
|
||||||
|
|
||||||
|
public PlayerTraceCache_15() {
|
||||||
|
this.pLocation = new float[]{0.0F, 0.0F, 0.0F};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPositions(float[] positions) {
|
||||||
|
this.positions = positions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatePoints(float[] updatePoints) {
|
||||||
|
this.updatePoints = updatePoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean nearLastLocation(Player player) {
|
||||||
|
float x = (float)player.getLocation().getX();
|
||||||
|
float y = (float)player.getLocation().getY();
|
||||||
|
float z = (float)player.getLocation().getZ();
|
||||||
|
|
||||||
|
if (square(pLocation[0] - x) + square(pLocation[1] - y) + square(pLocation[2] - z) > locationThreshold) {
|
||||||
|
pLocation[0] = x;
|
||||||
|
pLocation[1] = y;
|
||||||
|
pLocation[2] = z;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void show(Player player, TNTShowCallback_15.ShowMode showMode) {
|
||||||
|
if (positions.length == 0 || positions.length % 3 != 0) return;
|
||||||
|
for (int i = 0; i < positions.length; i += 3) {
|
||||||
|
float x = positions[i + 0];
|
||||||
|
float y = positions[i + 1];
|
||||||
|
float z = positions[i + 2];
|
||||||
|
|
||||||
|
if (showMode == TNTShowCallback_15.ShowMode.PARTICLE && positions.length / 3 < 1000) {
|
||||||
|
showCorner(player, x - 0.49F, y, z - 0.49F, Particle.FLAME);
|
||||||
|
} else {
|
||||||
|
showBlock(player, x, y + 0.49F, z, Material.RED_STAINED_GLASS, (byte) 14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (positions.length / 3 >= 1000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updatePoints.length == 0 || updatePoints.length % 3 != 0) return;
|
||||||
|
for (int i = 0; i < updatePoints.length; i += 3) {
|
||||||
|
float x = updatePoints[i + 0];
|
||||||
|
float y = updatePoints[i + 1];
|
||||||
|
float z = updatePoints[i + 2];
|
||||||
|
|
||||||
|
if (hasBlock(positions, x, y, z)) continue;
|
||||||
|
|
||||||
|
if (showMode == TNTShowCallback_15.ShowMode.PARTICLE) {
|
||||||
|
showCorner(player, x - 0.49F, y, z - 0.49F, Particle.VILLAGER_HAPPY);
|
||||||
|
} else {
|
||||||
|
showBlock(player, x, y + 0.49F, z, Material.LIME_STAINED_GLASS, (byte) 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void hide(Player player) {
|
||||||
|
if (positions.length == 0 || positions.length % 3 != 0) return;
|
||||||
|
for (int i = 0; i < positions.length; i += 3) {
|
||||||
|
float x = positions[i + 0];
|
||||||
|
float y = positions[i + 1];
|
||||||
|
float z = positions[i + 2];
|
||||||
|
|
||||||
|
hideBlock(player, x, y + 0.49F, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updatePoints.length == 0 || updatePoints.length % 3 != 0) return;
|
||||||
|
for (int i = 0; i < updatePoints.length; i += 3) {
|
||||||
|
float x = updatePoints[i + 0];
|
||||||
|
float y = updatePoints[i + 1];
|
||||||
|
float z = updatePoints[i + 2];
|
||||||
|
|
||||||
|
hideBlock(player, x, y + 0.49F, z);
|
||||||
|
}
|
||||||
|
updatePoints = new float[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 boolean hasBlock(float[] floats, float x, float y, float z) {
|
||||||
|
for (int i = 0; i < floats.length; i += 3) {
|
||||||
|
if (square(floats[i + 0] - x) + square(floats[i + 1] - y) + square(floats[i + 2] - z) < 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Location makeLocation(float x, float y, float z) {
|
||||||
|
location.setX(x);
|
||||||
|
location.setY(y);
|
||||||
|
location.setZ(z);
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.guicallback.RecordingCallback_15;
|
||||||
|
import de.steamwar.bausystem.tracer.guicallback.TNTFrameCallback_15;
|
||||||
|
import de.steamwar.bausystem.tracer.guicallback.TNTTraceCallback_15;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
@ -1,78 +1,160 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import de.steamwar.bausystem.tracer.showcallback.*;
|
||||||
import org.bukkit.block.Block;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
class TNTTracer_15 {
|
class TNTTracer_15 {
|
||||||
|
|
||||||
private TNTTracer_15(){}
|
private TNTTracer_15(){}
|
||||||
|
|
||||||
private static Location location;
|
|
||||||
|
|
||||||
private static BukkitTask task;
|
|
||||||
private static TracerCallback_15 tracerCallback;
|
private static TracerCallback_15 tracerCallback;
|
||||||
|
private static TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints;
|
||||||
|
private static TracerActionBarCallback_15 tracerActionBarCallback;
|
||||||
|
private static TNTShowCallback_15 tntShowCallback;
|
||||||
|
private static CacheUpdateCallback_15 cacheUpdateCallback;
|
||||||
|
|
||||||
private static final double showRadius = square(50.0);
|
private static Map<Player, PlayerTraceCache_15> playerMap = new HashMap<>();
|
||||||
|
|
||||||
public static double square(double d) {
|
private static boolean actionBar = true;
|
||||||
|
|
||||||
|
private static final float showRadius = square(50.0F);
|
||||||
|
|
||||||
|
private static class Synchronizer {}
|
||||||
|
|
||||||
|
private static final Synchronizer synchronizer = new Synchronizer();
|
||||||
|
|
||||||
|
public static float square(float d) {
|
||||||
return d * d;
|
return d * d;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init(Plugin plugin, TracerCallback_15 tracerCallback) {
|
static void init(Plugin plugin, TracerCallback_15 tracerCallback, TracerCallbackUpdatePoints_15 tracerCallbackUpdatePoints, TracerActionBarCallback_15 tracerActionBarCallback, TNTShowCallback_15 tntShowCallback, CacheUpdateCallback_15 cacheUpdateCallback) {
|
||||||
task = Bukkit.getScheduler().runTaskTimer(plugin, TNTTracer_15::run, 1, 20);
|
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
|
synchronized (synchronizer) {
|
||||||
|
synchronizer.notifyAll();
|
||||||
|
}
|
||||||
|
}, 1, 20);
|
||||||
|
Thread traceRenderer = new Thread(() -> {
|
||||||
|
while (true) {
|
||||||
|
synchronized (synchronizer) {
|
||||||
|
try {
|
||||||
|
synchronizer.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
traceRenderer.setDaemon(true);
|
||||||
|
traceRenderer.setName("Trace Renderer");
|
||||||
|
traceRenderer.start();
|
||||||
|
|
||||||
TNTTracer_15.tracerCallback = tracerCallback;
|
TNTTracer_15.tracerCallback = tracerCallback;
|
||||||
|
TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints;
|
||||||
|
TNTTracer_15.tracerActionBarCallback = tracerActionBarCallback;
|
||||||
|
TNTTracer_15.tntShowCallback = tntShowCallback;
|
||||||
|
TNTTracer_15.cacheUpdateCallback = cacheUpdateCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initWorld() {
|
||||||
|
PlayerTraceCache_15.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isInWater(TNTPrimed tnt) {
|
||||||
|
return tnt.getLocation().getBlock().getType() == Material.WATER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void run() {
|
private static void run() {
|
||||||
|
if (actionBar) {
|
||||||
|
String actionBar = tracerActionBarCallback.run();
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar)));
|
||||||
|
}
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
double[] doubles = tracerCallback.run(p);
|
PlayerTraceCache_15 traceCache;
|
||||||
if (doubles.length == 0 || doubles.length % 3 != 0) continue;
|
if (!playerMap.containsKey(p)) {
|
||||||
|
traceCache = new PlayerTraceCache_15();
|
||||||
|
playerMap.put(p, traceCache);
|
||||||
|
} else {
|
||||||
|
traceCache = playerMap.get(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!traceCache.nearLastLocation(p) && !cacheUpdateCallback.run(p)) {
|
||||||
|
traceCache.show(p, tntShowCallback.run(p));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(p, traceCache);
|
||||||
|
traceCache.show(p, tntShowCallback.run(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] noValue = new float[0];
|
||||||
|
|
||||||
|
private static void update(Player p, PlayerTraceCache_15 traceCache) {
|
||||||
|
float[] floats = tracerCallback.run(p);
|
||||||
|
if (floats.length == 0 || floats.length % 3 != 0) {
|
||||||
|
traceCache.setPositions(noValue);
|
||||||
|
traceCache.setUpdatePoints(noValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = p.getLocation();
|
Location location = p.getLocation();
|
||||||
World world = location.getWorld();
|
float px = (float)location.getX();
|
||||||
double px = location.getX();
|
float py = (float)location.getY();
|
||||||
double py = location.getY();
|
float pz = (float)location.getZ();
|
||||||
double pz = location.getZ();
|
|
||||||
|
|
||||||
for (int i = 0; i < doubles.length; i += 3) {
|
traceCache.setPositions(accumulatePositions(floats, px, py, pz));
|
||||||
double x = doubles[i + 0];
|
|
||||||
double y = doubles[i + 1];
|
|
||||||
double z = doubles[i + 2];
|
|
||||||
|
|
||||||
if (square((x + 0.5) - px) + square((y + 0.5) - py) + square((z + 0.5) - pz) > showRadius) continue;
|
floats = tracerCallbackUpdatePoints.run(p);
|
||||||
|
if (floats.length == 0 || floats.length % 3 != 0) {
|
||||||
showCorner(world, p, x, y, z);
|
traceCache.setUpdatePoints(noValue);
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showCorner(World world, Player player, double x, double y, double z) {
|
traceCache.setUpdatePoints(accumulatePositions(floats, px, py, pz));
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 0, y + 0, z + 0), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 1, y + 0, z + 0), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 0, y + 0, z + 1), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 1, y + 0, z + 1), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 0, y + 1, z + 0), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 1, y + 1, z + 0), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 0, y + 1, z + 1), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
player.spawnParticle(Particle.FLAME, makeLocation(world, x + 1, y + 1, z + 1), 1, 0F, 0F, 0F, 0.001);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Location makeLocation(World world, double x, double y, double z) {
|
private static float[] accumulatePositions(float[] floatss, float px, float py, float pz) {
|
||||||
if (!location.getWorld().equals(world)) {
|
LinkedList<Float> linkedList = new LinkedList<>();
|
||||||
location.setWorld(world);
|
|
||||||
|
for (int i = 0; i < floatss.length; i += 3) {
|
||||||
|
float x = floatss[i + 0];
|
||||||
|
float y = floatss[i + 1];
|
||||||
|
float z = floatss[i + 2];
|
||||||
|
|
||||||
|
if (square(x - px) + square(y + 0.49F - py) + square(z - pz) > showRadius) continue;
|
||||||
|
|
||||||
|
linkedList.add(x);
|
||||||
|
linkedList.add(y);
|
||||||
|
linkedList.add(z);
|
||||||
}
|
}
|
||||||
location.setX(x);
|
|
||||||
location.setY(y);
|
float[] result = new float[linkedList.size()];
|
||||||
location.setZ(z);
|
Iterator<Float> floatIterator = linkedList.iterator();
|
||||||
return location;
|
int index = 0;
|
||||||
|
while (floatIterator.hasNext()) {
|
||||||
|
result[index] = floatIterator.next();
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hide(Player p) {
|
||||||
|
PlayerTraceCache_15 tracerCache15 = playerMap.get(p);
|
||||||
|
if (tracerCache15 == null) return;
|
||||||
|
tracerCache15.hide(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer.guicallback;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer.guicallback;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
@ -1,4 +1,4 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer.guicallback;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
@ -0,0 +1,10 @@
|
|||||||
|
package de.steamwar.bausystem.tracer.showcallback;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface CacheUpdateCallback_15 {
|
||||||
|
|
||||||
|
boolean run(Player p);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package de.steamwar.bausystem.tracer.showcallback;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TNTShowCallback_15 {
|
||||||
|
|
||||||
|
public static enum ShowMode {
|
||||||
|
BLOCK,
|
||||||
|
PARTICLE
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowMode run(Player p);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package de.steamwar.bausystem.tracer.showcallback;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TracerActionBarCallback_15 {
|
||||||
|
|
||||||
|
String run();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package de.steamwar.bausystem.tracer.showcallback;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TracerCallbackUpdatePoints_15 {
|
||||||
|
|
||||||
|
float[] run(Player p);
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer.showcallback;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface TracerCallback_15 {
|
public interface TracerCallback_15 {
|
||||||
|
|
||||||
double[] run(Player p);
|
float[] run(Player p);
|
||||||
|
|
||||||
}
|
}
|
@ -78,6 +78,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCommand("trace").setExecutor(new CommandTrace());
|
getCommand("trace").setExecutor(new CommandTrace());
|
||||||
|
getCommand("trace").setTabCompleter(new CommandTraceTabCompleter());
|
||||||
getCommand("nightvision").setExecutor(new CommandNV());
|
getCommand("nightvision").setExecutor(new CommandNV());
|
||||||
getCommand("reset").setExecutor(new CommandReset());
|
getCommand("reset").setExecutor(new CommandReset());
|
||||||
getCommand("speed").setExecutor(new CommandSpeed());
|
getCommand("speed").setExecutor(new CommandSpeed());
|
||||||
|
@ -5,6 +5,7 @@ import de.steamwar.bausystem.Permission;
|
|||||||
import de.steamwar.bausystem.tracer.TNTTracer12;
|
import de.steamwar.bausystem.tracer.TNTTracer12;
|
||||||
import de.steamwar.bausystem.tracer.TNTTracer15;
|
import de.steamwar.bausystem.tracer.TNTTracer15;
|
||||||
import de.steamwar.bausystem.tracer.trace.ShowManager;
|
import de.steamwar.bausystem.tracer.trace.ShowManager;
|
||||||
|
import de.steamwar.bausystem.tracer.trace.ShowStatus;
|
||||||
import de.steamwar.bausystem.world.Welt;
|
import de.steamwar.bausystem.world.Welt;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -23,17 +24,20 @@ public class CommandTrace implements CommandExecutor {
|
|||||||
private void help15(Player player) {
|
private void help15(Player player) {
|
||||||
player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen");
|
player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen");
|
||||||
player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer");
|
player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer");
|
||||||
player.sendMessage("§8/§etrace auto §8- §7Startet und stoppt die Aufnahme automatisch");
|
player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart");
|
||||||
player.sendMessage("§8/§etrace show §8- §7Zeigt alle TNT-Positionen");
|
player.sendMessage("§8/§etrace togglewater §8- §7Tracet auch TNT im Wasser");
|
||||||
player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen");
|
player.sendMessage("§8/§etrace show §8<§eblock§8|§eparticle§8|§7TNT-ID§8> §8- §7Zeigt alle TNT-Positionen");
|
||||||
player.sendMessage("§8/§etrace clear §8- §7Löscht alle TNT-Positionen");
|
player.sendMessage("§8/§etrace hide §8<§7TNT-ID§8> §8- §7Versteckt alle TNT-Positionen");
|
||||||
player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an");
|
player.sendMessage("§8/§etrace delete §8<§7TNT-ID§8> §8- §7Löscht alle TNT-Positionen");
|
||||||
|
player.sendMessage("§8/§etrace interpolate §8[§eall§8|§eyaxis§8|§enone§8] §8- §7Interpolationsoptionen");
|
||||||
|
player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8>§8- §7Listet alle TNT auf");
|
||||||
|
//player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an");
|
||||||
|
player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player))
|
if(!(sender instanceof Player)) return false;
|
||||||
return false;
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
switch (Core.getVersion()) {
|
switch (Core.getVersion()) {
|
||||||
@ -85,18 +89,24 @@ public class CommandTrace implements CommandExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!permissionCheck(player)) return false;
|
//if (!permissionCheck(player)) return false;
|
||||||
|
|
||||||
switch(args[0].toLowerCase()){
|
switch(args[0].toLowerCase()){
|
||||||
case "start":
|
case "start":
|
||||||
|
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) {
|
||||||
|
TNTTracer15.toggleAuto();
|
||||||
|
}
|
||||||
TNTTracer15.start();
|
TNTTracer15.start();
|
||||||
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
|
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
|
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) {
|
||||||
|
TNTTracer15.toggleAuto();
|
||||||
|
}
|
||||||
TNTTracer15.stop();
|
TNTTracer15.stop();
|
||||||
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
|
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
|
||||||
break;
|
break;
|
||||||
case "auto":
|
case "toggleauto":
|
||||||
boolean mode = TNTTracer15.toggleAuto();
|
boolean mode = TNTTracer15.toggleAuto();
|
||||||
if (mode) {
|
if (mode) {
|
||||||
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
|
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
|
||||||
@ -104,18 +114,106 @@ public class CommandTrace implements CommandExecutor {
|
|||||||
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
|
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "togglewater":
|
||||||
|
mode = TNTTracer15.toggleRemoveInWater();
|
||||||
|
if (mode) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aTraces im Wasser werden gelöscht");
|
||||||
|
} else {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cTraces im Wasser werden behalten");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "show":
|
case "show":
|
||||||
|
if (args.length == 2) {
|
||||||
|
switch (args[1].toLowerCase()) {
|
||||||
|
case "block":
|
||||||
|
case "blocks":
|
||||||
|
ShowManager.get(player).setShowMode(ShowStatus.ShowMode.BLOCK);
|
||||||
|
break;
|
||||||
|
case "particle":
|
||||||
|
case "particles":
|
||||||
|
TNTTracer15.hideBlockTraces(player);
|
||||||
|
ShowManager.get(player).setShowMode(ShowStatus.ShowMode.PARTICLE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
try {
|
||||||
|
int tntID = Integer.parseInt(args[1]);
|
||||||
|
ShowManager.get(player).addSelection(tntID);
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen vom TNT mit ID " + tntID + " angezeigt");
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
help15(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
ShowManager.get(player).show();
|
ShowManager.get(player).show();
|
||||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
|
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen");
|
||||||
break;
|
break;
|
||||||
case "hide":
|
case "hide":
|
||||||
|
if (args.length == 2) {
|
||||||
|
try {
|
||||||
|
int tntID = Integer.parseInt(args[1]);
|
||||||
|
ShowManager.get(player).removeSelection(tntID);
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen vom TNT mit ID " + tntID + " versteckt");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
help15(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ShowManager.get(player).hide();
|
ShowManager.get(player).hide();
|
||||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt");
|
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt");
|
||||||
break;
|
break;
|
||||||
case "clear":
|
case "delete":
|
||||||
|
if (args.length == 2) {
|
||||||
|
try {
|
||||||
|
int tntID = Integer.parseInt(args[1]);
|
||||||
|
ShowManager.removeTrace(tntID);
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + tntID + " gelöscht");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
help15(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
TNTTracer15.clear();
|
TNTTracer15.clear();
|
||||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
||||||
break;
|
break;
|
||||||
|
case "interpolate":
|
||||||
|
if (args.length != 2) {
|
||||||
|
help15(player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (args[1].toLowerCase()) {
|
||||||
|
case "none":
|
||||||
|
TNTTracer15.hideBlockTraces(player);
|
||||||
|
ShowManager.get(player).setUpdatePoints(ShowStatus.UpdatePoints.NONE);
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt");
|
||||||
|
break;
|
||||||
|
case "yaxis":
|
||||||
|
TNTTracer15.hideBlockTraces(player);
|
||||||
|
ShowManager.get(player).setUpdatePoints(ShowStatus.UpdatePoints.Y_AXIS);
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt");
|
||||||
|
break;
|
||||||
|
case "all":
|
||||||
|
ShowManager.get(player).setUpdatePoints(ShowStatus.UpdatePoints.ALL);
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
help15(player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
if (args.length == 2) {
|
||||||
|
try {
|
||||||
|
TNTTracer15.printFrames(player, Integer.parseInt(args[1]));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
help15(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TNTTracer15.printList(player);
|
||||||
|
break;
|
||||||
case "gui":
|
case "gui":
|
||||||
player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
|
player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
|
||||||
break;
|
break;
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
package de.steamwar.bausystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.TNTTracer15;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandTraceTabCompleter implements TabCompleter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if(!(sender instanceof Player)) return new ArrayList<>();
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
switch (Core.getVersion()) {
|
||||||
|
case 15:
|
||||||
|
return tracer15TabComplete(player, args);
|
||||||
|
default:
|
||||||
|
return tracer12TabComplete(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> tracer12TabComplete(Player player, String[] args) {
|
||||||
|
List<String> tabComplete = new ArrayList<>();
|
||||||
|
tabComplete.add("start");
|
||||||
|
tabComplete.add("show");
|
||||||
|
tabComplete.add("stop");
|
||||||
|
|
||||||
|
return manageList(tabComplete, args, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> tracer15TabComplete(Player player, String[] args) {
|
||||||
|
List<String> tabComplete = new ArrayList<>();
|
||||||
|
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE || TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO) {
|
||||||
|
tabComplete.add("start");
|
||||||
|
} else {
|
||||||
|
tabComplete.add("stop");
|
||||||
|
}
|
||||||
|
tabComplete.add("toggleauto");
|
||||||
|
tabComplete.add("togglewater");
|
||||||
|
tabComplete.add("show");
|
||||||
|
if (args[0].equalsIgnoreCase("show") && args.length == 2) {
|
||||||
|
return manageList(new ArrayList<>(Arrays.asList("block", "particle")), args, 1);
|
||||||
|
}
|
||||||
|
tabComplete.add("hide");
|
||||||
|
tabComplete.add("delete");
|
||||||
|
tabComplete.add("interpolate");
|
||||||
|
if (args[0].equalsIgnoreCase("interpolate") && args.length == 2) {
|
||||||
|
return manageList(new ArrayList<>(Arrays.asList("all", "yaxis", "none")), args, 1);
|
||||||
|
}
|
||||||
|
//tabComplete.add("gui");
|
||||||
|
tabComplete.add("list");
|
||||||
|
|
||||||
|
if (args.length == 2) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return manageList(tabComplete, args, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> manageList(List<String> strings, String[] args, int index) {
|
||||||
|
for (int i = strings.size() - 1; i >= 0; i--) {
|
||||||
|
if (!strings.get(i).startsWith(args[index])) {
|
||||||
|
strings.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,8 +27,10 @@ public class TNTListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onEntityExplode15(EntityExplodeEvent event) {
|
private void onEntityExplode15(EntityExplodeEvent event) {
|
||||||
if (TNTTracer15.getStatus() != TNTTracer15.Status.RECORD_AUTO) return;
|
|
||||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||||
|
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) {
|
||||||
TNTTracer15.start();
|
TNTTracer15.start();
|
||||||
}
|
}
|
||||||
|
TNTTracer15.explode((TNTPrimed) event.getEntity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,39 @@
|
|||||||
package de.steamwar.bausystem.tracer;
|
package de.steamwar.bausystem.tracer;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.tracer.showcallback.TNTShowCallback_15;
|
||||||
import de.steamwar.bausystem.tracer.trace.ShowManager;
|
import de.steamwar.bausystem.tracer.trace.ShowManager;
|
||||||
import de.steamwar.bausystem.tracer.trace.ShowStatus;
|
import de.steamwar.bausystem.tracer.trace.ShowStatus;
|
||||||
import de.steamwar.bausystem.tracer.trace.TNTFrame;
|
import de.steamwar.bausystem.tracer.trace.TNTFrame;
|
||||||
import de.steamwar.bausystem.tracer.trace.TNTTrace;
|
import de.steamwar.bausystem.tracer.trace.TNTTrace;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.LinkedList;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TNTTracer15 {
|
public class TNTTracer15 {
|
||||||
|
|
||||||
private static BukkitTask task;
|
private static BukkitTask task;
|
||||||
private static long current = System.currentTimeMillis();
|
private static long current = System.currentTimeMillis();
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
|
||||||
|
private static boolean removeInWater = true;
|
||||||
|
|
||||||
|
private static World world;
|
||||||
|
public static void worldInit() {
|
||||||
|
if (world != null) return;
|
||||||
|
world = Bukkit.getWorlds().get(0);
|
||||||
|
TNTTracer_15.initWorld();
|
||||||
|
}
|
||||||
|
|
||||||
private static LinkedList<TNTFrame> tntFrames = new LinkedList<>();
|
private static LinkedList<TNTFrame> tntFrames = new LinkedList<>();
|
||||||
|
|
||||||
public static TNTTracer15.Status getStatus() {
|
public static TNTTracer15.Status getStatus() {
|
||||||
@ -27,12 +41,66 @@ public class TNTTracer15 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static TNTTracer15.Status status = Status.IDLE;
|
private static TNTTracer15.Status status = Status.IDLE;
|
||||||
private static final double[] noValue = new double[0];
|
private static final float[] noValue = new float[0];
|
||||||
|
|
||||||
public static void initTNTTracer_15() {
|
public static void initTNTTracer_15() {
|
||||||
TNTTracer_15.init(BauSystem.getPlugin(), p -> {
|
TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, p -> ShowManager.get(p).isDirty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] accumulate(LinkedList<TNTTrace> traces) {
|
||||||
|
Map<String, float[]> locations = new HashMap<>();
|
||||||
|
Iterator<TNTTrace> traceIterator = traces.iterator();
|
||||||
|
while (traceIterator.hasNext()) {
|
||||||
|
float[] positions = traceIterator.next().getPositions();
|
||||||
|
for (int i = 0; i < positions.length; i += 3) {
|
||||||
|
float x = positions[i + 0];
|
||||||
|
float y = positions[i + 1];
|
||||||
|
float z = positions[i + 2];
|
||||||
|
locations.computeIfAbsent(round(x) + ":" + round(y) + ":" + round(z), t -> new float[]{x, y, z});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float[] floats = new float[locations.size() * 3];
|
||||||
|
int index = 0;
|
||||||
|
for (Map.Entry<String, float[]> entry : locations.entrySet()) {
|
||||||
|
floats[index + 0] = entry.getValue()[0];
|
||||||
|
floats[index + 1] = entry.getValue()[1];
|
||||||
|
floats[index + 2] = entry.getValue()[2];
|
||||||
|
index += 3;
|
||||||
|
}
|
||||||
|
return floats;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] accumulateInterpolate(LinkedList<TNTTrace> traces, ShowStatus.UpdatePoints updatePoints) {
|
||||||
|
Map<String, float[]> locations = new HashMap<>();
|
||||||
|
Iterator<TNTTrace> traceIterator = traces.iterator();
|
||||||
|
while (traceIterator.hasNext()) {
|
||||||
|
float[] positions = interpolate(traceIterator.next().getPositions(), updatePoints);
|
||||||
|
for (int i = 0; i < positions.length; i += 3) {
|
||||||
|
float x = positions[i + 0];
|
||||||
|
float y = positions[i + 1];
|
||||||
|
float z = positions[i + 2];
|
||||||
|
locations.computeIfAbsent(round(x) + ":" + round(y) + ":" + round(z), t -> new float[]{x, y, z});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float[] floats = new float[locations.size() * 3];
|
||||||
|
int index = 0;
|
||||||
|
for (Map.Entry<String, float[]> entry : locations.entrySet()) {
|
||||||
|
floats[index + 0] = entry.getValue()[0];
|
||||||
|
floats[index + 1] = entry.getValue()[1];
|
||||||
|
floats[index + 2] = entry.getValue()[2];
|
||||||
|
index += 3;
|
||||||
|
}
|
||||||
|
return floats;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] getTracePoints(Player p) {
|
||||||
ShowStatus showStatus = ShowManager.get(p);
|
ShowStatus showStatus = ShowManager.get(p);
|
||||||
if (showStatus.getStatus() == ShowStatus.Status.NONE) return noValue;
|
if (showStatus.getShow() == ShowStatus.Show.NONE) return noValue;
|
||||||
|
if (showStatus.getShow() == ShowStatus.Show.ALL) {
|
||||||
|
return getAllTraces();
|
||||||
|
}
|
||||||
LinkedList<Integer> selection = showStatus.getSelection();
|
LinkedList<Integer> selection = showStatus.getSelection();
|
||||||
|
|
||||||
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
@ -41,22 +109,171 @@ public class TNTTracer15 {
|
|||||||
traces.addAll(frameIterator.next().getTraces(selection));
|
traces.addAll(frameIterator.next().getTraces(selection));
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = traces.stream().mapToInt(TNTTrace::length).sum();
|
return accumulate(traces);
|
||||||
double[] doubles = new double[size * 3];
|
|
||||||
int index = 0;
|
|
||||||
Iterator<TNTTrace> traceIterator = traces.iterator();
|
|
||||||
while (traceIterator.hasNext()) {
|
|
||||||
double[] positions = traceIterator.next().getPositions();
|
|
||||||
for (int i = 0; i < positions.length; i++) {
|
|
||||||
if (index >= doubles.length) break;
|
|
||||||
doubles[index] = positions[i];
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (index >= doubles.length) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return doubles;
|
private static float[] getAllTraces() {
|
||||||
});
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
traces.addAll(frameIterator.next().getTraces());
|
||||||
|
}
|
||||||
|
|
||||||
|
return accumulate(traces);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] getTraceUpdatePoints(Player p) {
|
||||||
|
ShowStatus showStatus = ShowManager.get(p);
|
||||||
|
if (showStatus.getShow() == ShowStatus.Show.NONE) return noValue;
|
||||||
|
if (showStatus.getShow() == ShowStatus.Show.ALL) {
|
||||||
|
return getTraceUpdatePointsAll(showStatus);
|
||||||
|
}
|
||||||
|
if (showStatus.getUpdatePoints() == ShowStatus.UpdatePoints.NONE) return noValue;
|
||||||
|
LinkedList<Integer> selection = showStatus.getSelection();
|
||||||
|
|
||||||
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
traces.addAll(frameIterator.next().getTraces(selection));
|
||||||
|
}
|
||||||
|
|
||||||
|
return accumulateInterpolate(traces, showStatus.getUpdatePoints());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] getTraceUpdatePointsAll(ShowStatus showStatus) {
|
||||||
|
if (showStatus.getUpdatePoints() == ShowStatus.UpdatePoints.NONE) return noValue;
|
||||||
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
traces.addAll(frameIterator.next().getTraces());
|
||||||
|
}
|
||||||
|
|
||||||
|
return accumulateInterpolate(traces, showStatus.getUpdatePoints());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int roundValue = 100;
|
||||||
|
|
||||||
|
private static float round(float toRound) {
|
||||||
|
float r = (toRound * roundValue);
|
||||||
|
if (r - (int)r >= 0.5) {
|
||||||
|
return (((float)(int)r) + 1) / roundValue;
|
||||||
|
} else {
|
||||||
|
return (((float)(int)r) + 0) / roundValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double round(double toRound, int digits) {
|
||||||
|
int x = (int)Math.pow(10, digits);
|
||||||
|
|
||||||
|
double r = (toRound * x);
|
||||||
|
double t = r - (int) r;
|
||||||
|
|
||||||
|
if (t >= 0.5) {
|
||||||
|
return (((double)(int)r) + 1) / x;
|
||||||
|
} else {
|
||||||
|
return (((double)(int)r) + 0) / x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getActionBar() {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
st.append("§7Frames: §e").append(tntFrames.size()).append(" ");
|
||||||
|
int traces = calcTraces();
|
||||||
|
st.append("§7Traces: §e").append(traces).append(" ");
|
||||||
|
st.append("§7RAM: §c").append(round(traces * 32 / 8.0 / 1024 / 1024, 8)).append("MB");
|
||||||
|
return st.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int calcTraces() {
|
||||||
|
int traces = 0;
|
||||||
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
Iterator<TNTTrace> traceIterator = frameIterator.next().getTraces().iterator();
|
||||||
|
while (traceIterator.hasNext()) {
|
||||||
|
traces += traceIterator.next().realLength();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return traces;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TNTShowCallback_15.ShowMode showMode(Player player) {
|
||||||
|
if (ShowManager.get(player).getShowMode() == ShowStatus.ShowMode.BLOCK) {
|
||||||
|
return TNTShowCallback_15.ShowMode.BLOCK;
|
||||||
|
} else {
|
||||||
|
return TNTShowCallback_15.ShowMode.PARTICLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] interpolate(float[] floats, ShowStatus.UpdatePoints updatePoints) {
|
||||||
|
LinkedList<Float> linkedList = new LinkedList<>();
|
||||||
|
if (floats.length < 6) {
|
||||||
|
return noValue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < floats.length - 3; i += 3) {
|
||||||
|
float x1 = floats[i + 0];
|
||||||
|
float y1 = floats[i + 1];
|
||||||
|
float z1 = floats[i + 2];
|
||||||
|
|
||||||
|
float x2 = floats[i + 3];
|
||||||
|
float y2 = floats[i + 4];
|
||||||
|
float z2 = floats[i + 5];
|
||||||
|
|
||||||
|
if (!isEqual(y2, y1)) {
|
||||||
|
linkedList.add(x1);
|
||||||
|
linkedList.add(y2);
|
||||||
|
linkedList.add(z1);
|
||||||
|
}
|
||||||
|
if (updatePoints != ShowStatus.UpdatePoints.ALL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (abs(x2 - x1) > abs(z2 - z1)) {
|
||||||
|
if (!isEqual(x2, x1)) {
|
||||||
|
linkedList.add(x2);
|
||||||
|
linkedList.add(y2);
|
||||||
|
linkedList.add(z1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!isEqual(z2, z1)) {
|
||||||
|
linkedList.add(x1);
|
||||||
|
linkedList.add(y2);
|
||||||
|
linkedList.add(z2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toFloat(linkedList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isEqual(float d1, float d2) {
|
||||||
|
return TNTTracer_15.square(d2 - d1) < 0.01;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] toFloat(LinkedList<Float> floats) {
|
||||||
|
float[] value = new float[floats.size()];
|
||||||
|
Iterator<Float> linkedListIterator = floats.listIterator();
|
||||||
|
int index = 0;
|
||||||
|
while (linkedListIterator.hasNext()) {
|
||||||
|
value[index] = linkedListIterator.next();
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float abs(float x) {
|
||||||
|
return x < 0 ? -x : x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void explode(TNTPrimed tntPrimed) {
|
||||||
|
if (tntFrames.isEmpty()) return;
|
||||||
|
tntFrames.getLast().explode(tntPrimed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInWater(TNTPrimed tntPrimed) {
|
||||||
|
return TNTTracer_15.isInWater(tntPrimed) && removeInWater;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean toggleRemoveInWater() {
|
||||||
|
removeInWater = !removeInWater;
|
||||||
|
return removeInWater;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
@ -67,6 +284,10 @@ public class TNTTracer15 {
|
|||||||
ShowManager.removeAllTraces();
|
ShowManager.removeAllTraces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void hideBlockTraces(Player p) {
|
||||||
|
TNTTracer_15.hide(p);
|
||||||
|
}
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
if (status == Status.IDLE || status == Status.IDLE_AUTO) {
|
if (status == Status.IDLE || status == Status.IDLE_AUTO) {
|
||||||
if (status == Status.IDLE) {
|
if (status == Status.IDLE) {
|
||||||
@ -75,8 +296,12 @@ public class TNTTracer15 {
|
|||||||
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet")));
|
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet")));
|
||||||
status = Status.RECORD_AUTO;
|
status = Status.RECORD_AUTO;
|
||||||
}
|
}
|
||||||
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer15::run, 1, 1);
|
|
||||||
tntFrames.addLast(new TNTFrame());
|
tntFrames.addLast(new TNTFrame());
|
||||||
|
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer15::run, 1, 1);
|
||||||
|
current = System.currentTimeMillis();
|
||||||
|
if (status == Status.RECORD_AUTO) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (status == Status.RECORD_AUTO) {
|
if (status == Status.RECORD_AUTO) {
|
||||||
current = System.currentTimeMillis();
|
current = System.currentTimeMillis();
|
||||||
@ -95,7 +320,9 @@ public class TNTTracer15 {
|
|||||||
status = Status.IDLE_AUTO;
|
status = Status.IDLE_AUTO;
|
||||||
}
|
}
|
||||||
if (task != null) task.cancel();
|
if (task != null) task.cancel();
|
||||||
tntFrames.getLast().finish();
|
if (tntFrames.getLast().finish()) {
|
||||||
|
tntFrames.removeLast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean toggleAuto() {
|
public static boolean toggleAuto() {
|
||||||
@ -130,6 +357,104 @@ public class TNTTracer15 {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String format(long time) {
|
||||||
|
return new SimpleDateFormat("HH:mm:ss").format(new Date(time));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long calcTick(long startTime, long time) {
|
||||||
|
return (time - startTime) / 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(long startTime, long time, int length) {
|
||||||
|
return calcTick(startTime, time) + "-" + (calcTick(startTime, time) + length);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(int length, int uniqueID) {
|
||||||
|
if (length == 0) {
|
||||||
|
return uniqueID + "";
|
||||||
|
}
|
||||||
|
return repeat(length - (int)Math.log10(uniqueID) - 1) + uniqueID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String repeat(int length) {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
for (int i = 0; i < length; i++) st.append('0');
|
||||||
|
return st.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printFrames(Player player, int uniqueID) {
|
||||||
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
LinkedList<Integer> integerList = ShowManager.get(player).getSelection();
|
||||||
|
TNTFrame tntFrame = null;
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
TNTFrame frame = frameIterator.next();
|
||||||
|
if (frame.getUniqueID() == uniqueID) {
|
||||||
|
tntFrame = frame;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tntFrame == null) {
|
||||||
|
player.sendMessage("§cUnbekannte Aufnahme");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage("");
|
||||||
|
player.sendMessage("§eAufnahme §7aufgenommen um §e" + format(tntFrame.getStartTime()) + " §7mit §a" + tntFrame.getTraces().size() + " TNT");
|
||||||
|
int length = (int)Math.log10(tntFrame.getTraces().getLast().getUniqueID()) + 1;
|
||||||
|
Iterator<TNTTrace> traceIterator = tntFrame.getTraces().iterator();
|
||||||
|
while (traceIterator.hasNext()) {
|
||||||
|
TNTTrace tntTrace = traceIterator.next();
|
||||||
|
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
st.append("§8 ");
|
||||||
|
if (integerList.contains(tntTrace.getUniqueID()) || ShowManager.get(player).getShow() == ShowStatus.Show.ALL) st.append("§a");
|
||||||
|
else st.append("§c");
|
||||||
|
st.append(format(length, tntTrace.getUniqueID())).append(" §eTick: ").append(format(tntFrame.getStartTime(), tntTrace.getStartTime(), tntTrace.length()));
|
||||||
|
player.sendMessage(st.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printList(Player player) {
|
||||||
|
if (tntFrames.isEmpty()) {
|
||||||
|
player.sendMessage("§cKeine Aufnahme vorhanden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
TNTFrame tntFrame = frameIterator.next();
|
||||||
|
|
||||||
|
TextComponent textComponent = new TextComponent();
|
||||||
|
textComponent.setText("§eAufnahme §7aufgenommen um §e" + format(tntFrame.getStartTime()) + " §7mit §a" + tntFrame.getTraces().size() + " TNT");
|
||||||
|
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Zeige die TNT dieser Aufnahme an")));
|
||||||
|
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace list " + tntFrame.getUniqueID()));
|
||||||
|
player.spigot().sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinkedList<Integer> allTraces() {
|
||||||
|
LinkedList<Integer> allTraces = new LinkedList<>();
|
||||||
|
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
|
||||||
|
while (frameIterator.hasNext()) {
|
||||||
|
TNTFrame tntFrame = frameIterator.next();
|
||||||
|
allTraces.addAll(tntFrame.getTraces().stream().map(TNTTrace::getUniqueID).collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
|
return allTraces;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long sidebar_startTime() {
|
||||||
|
if (tntFrames.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tntFrames.getLast().getStartTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int sidebar_TNT() {
|
||||||
|
if (tntFrames.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tntFrames.getLast().getTraces().size();
|
||||||
|
}
|
||||||
|
|
||||||
public enum Status{
|
public enum Status{
|
||||||
RECORD,
|
RECORD,
|
||||||
RECORD_AUTO,
|
RECORD_AUTO,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.steamwar.bausystem.tracer.trace;
|
package de.steamwar.bausystem.tracer.trace;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.TNTTracer15;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -10,7 +11,8 @@ public class ShowManager {
|
|||||||
private static Map<Player, ShowStatus> showMap = new HashMap<>();
|
private static Map<Player, ShowStatus> showMap = new HashMap<>();
|
||||||
|
|
||||||
public static void add(Player player) {
|
public static void add(Player player) {
|
||||||
showMap.put(player, new ShowStatus());
|
showMap.put(player, new ShowStatus(player));
|
||||||
|
TNTTracer15.worldInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void remove(Player player) {
|
public static void remove(Player player) {
|
||||||
@ -24,12 +26,14 @@ public class ShowManager {
|
|||||||
public static void removeTrace(int traceID) {
|
public static void removeTrace(int traceID) {
|
||||||
for (Map.Entry<Player, ShowStatus> entry : showMap.entrySet()) {
|
for (Map.Entry<Player, ShowStatus> entry : showMap.entrySet()) {
|
||||||
entry.getValue().removeSelection(traceID);
|
entry.getValue().removeSelection(traceID);
|
||||||
|
TNTTracer15.hideBlockTraces(entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAllTraces() {
|
public static void removeAllTraces() {
|
||||||
for (Map.Entry<Player, ShowStatus> entry : showMap.entrySet()) {
|
for (Map.Entry<Player, ShowStatus> entry : showMap.entrySet()) {
|
||||||
entry.getValue().clear();
|
entry.getValue().clear();
|
||||||
|
TNTTracer15.hideBlockTraces(entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,68 +1,139 @@
|
|||||||
package de.steamwar.bausystem.tracer.trace;
|
package de.steamwar.bausystem.tracer.trace;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.TNTTracer15;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class ShowStatus {
|
public class ShowStatus {
|
||||||
|
|
||||||
private Status status = Status.NONE;
|
private Show show = Show.NONE;
|
||||||
|
private UpdatePoints updatePoints = UpdatePoints.ALL;
|
||||||
|
private ShowMode showMode = ShowMode.PARTICLE;
|
||||||
|
|
||||||
private LinkedList<Integer> selected = new LinkedList<>();
|
private LinkedList<Integer> selected = new LinkedList<>();
|
||||||
|
|
||||||
public enum Status {
|
private Player p;
|
||||||
|
|
||||||
|
private boolean dirty = false;
|
||||||
|
|
||||||
|
public ShowStatus(Player p) {
|
||||||
|
this.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Show {
|
||||||
NONE,
|
NONE,
|
||||||
ALL,
|
ALL,
|
||||||
SELECTIVE
|
SELECTIVE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum UpdatePoints {
|
||||||
|
NONE,
|
||||||
|
Y_AXIS,
|
||||||
|
ALL
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ShowMode {
|
||||||
|
BLOCK,
|
||||||
|
PARTICLE
|
||||||
|
}
|
||||||
|
|
||||||
public boolean toggleShow() {
|
public boolean toggleShow() {
|
||||||
if (status == Status.NONE) {
|
dirty = true;
|
||||||
status = Status.ALL;
|
if (show == Show.NONE) {
|
||||||
|
show = Show.ALL;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
selected.clear();
|
selected.clear();
|
||||||
status = Status.NONE;
|
show = Show.NONE;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
status = Status.ALL;
|
dirty = true;
|
||||||
|
show = Show.ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide() {
|
public void hide() {
|
||||||
|
dirty = true;
|
||||||
selected.clear();
|
selected.clear();
|
||||||
status = Status.NONE;
|
TNTTracer15.hideBlockTraces(p);
|
||||||
|
show = Show.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSelection(int uniqueID) {
|
public void addSelection(int uniqueID) {
|
||||||
if (status == Status.ALL) return;
|
dirty = true;
|
||||||
if (status == Status.NONE) {
|
if (show == Show.ALL) return;
|
||||||
status = Status.SELECTIVE;
|
if (show == Show.NONE) {
|
||||||
|
show = Show.SELECTIVE;
|
||||||
}
|
}
|
||||||
selected.add(uniqueID);
|
selected.add(uniqueID);
|
||||||
|
if (selected.size() == TNTTracer15.allTraces().size()) {
|
||||||
|
show = Show.ALL;
|
||||||
|
selected.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSelection(int uniqueID) {
|
public void removeSelection(int uniqueID) {
|
||||||
if (status == Status.NONE) return;
|
dirty = true;
|
||||||
if (status == Status.ALL) {
|
if (show == Show.NONE) return;
|
||||||
status = Status.SELECTIVE;
|
TNTTracer15.hideBlockTraces(p);
|
||||||
|
if (show == Show.ALL) {
|
||||||
|
selected = TNTTracer15.allTraces();
|
||||||
|
show = Show.SELECTIVE;
|
||||||
}
|
}
|
||||||
selected.remove(uniqueID);
|
selected.remove((Integer) uniqueID);
|
||||||
if (selected.isEmpty()) {
|
if (selected.isEmpty()) {
|
||||||
status = Status.NONE;
|
show = Show.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
if (status == Status.NONE) return;
|
dirty = true;
|
||||||
|
if (show == Show.NONE) return;
|
||||||
selected.clear();
|
selected.clear();
|
||||||
|
TNTTracer15.hideBlockTraces(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Status getStatus() {
|
public Show getShow() {
|
||||||
return status;
|
return show;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdatePoints getUpdatePoints() {
|
||||||
|
return updatePoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatePoints(UpdatePoints updatePoints) {
|
||||||
|
this.updatePoints = updatePoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShowMode getShowMode() {
|
||||||
|
return showMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowMode(ShowMode showMode) {
|
||||||
|
this.showMode = showMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<Integer> getSelection() {
|
public LinkedList<Integer> getSelection() {
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDirty() {
|
||||||
|
if (dirty) {
|
||||||
|
dirty = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ShowStatus{" +
|
||||||
|
"status=" + show +
|
||||||
|
", selected=" + selected +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.steamwar.bausystem.tracer.trace;
|
package de.steamwar.bausystem.tracer.trace;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.tracer.TNTTracer15;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -10,19 +11,27 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class TNTFrame {
|
public class TNTFrame {
|
||||||
|
|
||||||
|
private static int uniqueIdentifierFrame = 0;
|
||||||
private static int uniqueIdentifier = 0;
|
private static int uniqueIdentifier = 0;
|
||||||
|
|
||||||
private long time = System.currentTimeMillis();
|
private long startTime = System.currentTimeMillis();
|
||||||
|
private long endTime = System.currentTimeMillis();
|
||||||
private Map<Integer, TNTTrace> positions = new HashMap<>();
|
private Map<Integer, TNTTrace> positions = new HashMap<>();
|
||||||
private Map<TNTPrimed, TNTTrace> aliveTNT = new HashMap<>();
|
private Map<TNTPrimed, TNTTrace> aliveTNT = new HashMap<>();
|
||||||
|
|
||||||
private final TNTFrame instance = this;
|
private final TNTFrame instance = this;
|
||||||
|
|
||||||
|
private final int uniqueID = uniqueIdentifierFrame++;
|
||||||
|
|
||||||
|
public int getUniqueID() {
|
||||||
|
return uniqueID;
|
||||||
|
}
|
||||||
|
|
||||||
public void add(Stream<TNTPrimed> tntPrimedStream) {
|
public void add(Stream<TNTPrimed> tntPrimedStream) {
|
||||||
if (aliveTNT == null) return;
|
if (aliveTNT == null) return;
|
||||||
tntPrimedStream.forEach(tnt -> aliveTNT.computeIfAbsent(tnt, k -> {
|
tntPrimedStream.forEach(tnt -> aliveTNT.computeIfAbsent(tnt, k -> {
|
||||||
synchronized (instance) {
|
synchronized (instance) {
|
||||||
TNTTrace trace = new TNTTrace(uniqueIdentifier, this, tnt);
|
TNTTrace trace = new TNTTrace(uniqueIdentifier);
|
||||||
positions.put(uniqueIdentifier, trace);
|
positions.put(uniqueIdentifier, trace);
|
||||||
uniqueIdentifier++;
|
uniqueIdentifier++;
|
||||||
return trace;
|
return trace;
|
||||||
@ -30,10 +39,25 @@ public class TNTFrame {
|
|||||||
}).addLocation(tnt.getLocation()));
|
}).addLocation(tnt.getLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void explode(TNTPrimed tntPrimed) {
|
||||||
|
delete(tntPrimed);
|
||||||
|
}
|
||||||
|
|
||||||
void delete(TNTPrimed tntPrimed) {
|
void delete(TNTPrimed tntPrimed) {
|
||||||
|
delete(tntPrimed, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void delete(TNTPrimed tntPrimed, boolean delete) {
|
||||||
if (aliveTNT == null) return;
|
if (aliveTNT == null) return;
|
||||||
|
TNTTrace tntTrace = aliveTNT.get(tntPrimed);
|
||||||
|
tntTrace.addLocation(tntPrimed.getLocation());
|
||||||
|
if (delete) {
|
||||||
aliveTNT.remove(tntPrimed);
|
aliveTNT.remove(tntPrimed);
|
||||||
}
|
}
|
||||||
|
if (TNTTracer15.isInWater(tntPrimed)) {
|
||||||
|
positions.remove(tntTrace.getUniqueID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LinkedList<TNTTrace> getTraces(LinkedList<Integer> selection) {
|
public LinkedList<TNTTrace> getTraces(LinkedList<Integer> selection) {
|
||||||
LinkedList<TNTTrace> traces = new LinkedList<>();
|
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||||
@ -47,13 +71,27 @@ public class TNTFrame {
|
|||||||
return traces;
|
return traces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish() {
|
public LinkedList<TNTTrace> getTraces() {
|
||||||
aliveTNT.clear();
|
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||||
aliveTNT = null;
|
for (Map.Entry<Integer, TNTTrace> entry : positions.entrySet()) {
|
||||||
|
traces.add(entry.getValue());
|
||||||
|
}
|
||||||
|
return traces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTime() {
|
public boolean finish() {
|
||||||
return time;
|
for (Map.Entry<TNTPrimed, TNTTrace> entry : aliveTNT.entrySet()) {
|
||||||
|
entry.getValue().cleanUp();
|
||||||
|
delete(entry.getKey(), false);
|
||||||
|
}
|
||||||
|
endTime = System.currentTimeMillis();
|
||||||
|
aliveTNT.clear();
|
||||||
|
aliveTNT = null;
|
||||||
|
return positions.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTime() {
|
||||||
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,19 @@
|
|||||||
package de.steamwar.bausystem.tracer.trace;
|
package de.steamwar.bausystem.tracer.trace;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class TNTTrace {
|
public class TNTTrace {
|
||||||
|
|
||||||
private long startTime = System.currentTimeMillis();
|
private long startTime = System.currentTimeMillis();
|
||||||
private long lastUpdate = System.currentTimeMillis();
|
|
||||||
|
|
||||||
private int uniqueID;
|
private int uniqueID;
|
||||||
|
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
private double[] positions = new double[240];
|
private float[] positions = new float[243];
|
||||||
|
|
||||||
private TNTFrame frame;
|
public TNTTrace(int uniqueID) {
|
||||||
private TNTPrimed tntPrimed;
|
|
||||||
|
|
||||||
public TNTTrace(int uniqueID, TNTFrame frame, TNTPrimed tntPrimed) {
|
|
||||||
this.uniqueID = uniqueID;
|
this.uniqueID = uniqueID;
|
||||||
this.frame = frame;
|
|
||||||
this.tntPrimed = tntPrimed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLocation(Location location) {
|
public void addLocation(Location location) {
|
||||||
@ -27,23 +21,14 @@ public class TNTTrace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addLocation(double x, double y, double z) {
|
public void addLocation(double x, double y, double z) {
|
||||||
positions[index + 0] = x;
|
positions[index + 0] = (float)x;
|
||||||
positions[index + 1] = y;
|
positions[index + 1] = (float)y;
|
||||||
positions[index + 2] = z;
|
positions[index + 2] = (float)z;
|
||||||
index += 3;
|
index += 3;
|
||||||
if (index >= positions.length) {
|
|
||||||
frame.delete(tntPrimed);
|
|
||||||
tntPrimed = null;
|
|
||||||
}
|
|
||||||
lastUpdate = System.currentTimeMillis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getPositions() {
|
public float[] getPositions() {
|
||||||
double[] doubles = new double[index];
|
return Arrays.copyOf(positions, positions.length);
|
||||||
for (int i = 0; i < doubles.length; i++) {
|
|
||||||
doubles[i] = positions[i];
|
|
||||||
}
|
|
||||||
return doubles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
@ -54,13 +39,20 @@ public class TNTTrace {
|
|||||||
return size();
|
return size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int realLength() {
|
||||||
|
return positions.length;
|
||||||
|
}
|
||||||
|
|
||||||
public long getStartTime() {
|
public long getStartTime() {
|
||||||
return startTime;
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastUpdate() {
|
public int getUniqueID() {
|
||||||
return lastUpdate;
|
return uniqueID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanUp() {
|
||||||
|
positions = Arrays.copyOf(positions, index);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package de.steamwar.bausystem.world;
|
|||||||
import de.steamwar.bausystem.commands.CommandFreeze;
|
import de.steamwar.bausystem.commands.CommandFreeze;
|
||||||
import de.steamwar.bausystem.commands.CommandInfo;
|
import de.steamwar.bausystem.commands.CommandInfo;
|
||||||
import de.steamwar.bausystem.commands.CommandTNT;
|
import de.steamwar.bausystem.commands.CommandTNT;
|
||||||
|
import de.steamwar.bausystem.tracer.TNTTracer15;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.scoreboard.SWScoreboard;
|
import de.steamwar.scoreboard.SWScoreboard;
|
||||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -11,8 +13,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class BauScoreboard implements Listener {
|
public class BauScoreboard implements Listener {
|
||||||
|
|
||||||
@ -24,13 +25,18 @@ public class BauScoreboard implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public HashMap<String, Integer> getData() {
|
public HashMap<String, Integer> getData() {
|
||||||
HashMap<String, Integer> data = new HashMap<>();
|
HashMap<String, Integer> data = new HashMap<>();
|
||||||
data.put("§1 ", 7);
|
|
||||||
data.put("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()), 6);
|
switch (Core.getVersion()) {
|
||||||
data.put("§2 ", 5);
|
case 15:
|
||||||
data.put("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"), 4);
|
render(getSidebar_15(), data);
|
||||||
data.put("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"), 3);
|
break;
|
||||||
data.put("§3 ", 2);
|
case 12:
|
||||||
data.put("§eTPS§8: §7" + CommandInfo.getTps()[0], 1);
|
render(getSidebar_12(), data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,5 +47,47 @@ public class BauScoreboard implements Listener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void render(List<String> strings, HashMap<String, Integer> data) {
|
||||||
|
String[] elements = strings.toArray(new String[0]);
|
||||||
|
for (int i = elements.length - 1; i >= 0; i--) {
|
||||||
|
data.put(elements[i], elements.length - i - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getSidebar_15() {
|
||||||
|
List<String> strings = new ArrayList<>();
|
||||||
|
strings.add("§1");
|
||||||
|
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||||
|
strings.add("§2");
|
||||||
|
strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"));
|
||||||
|
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
|
||||||
|
|
||||||
|
boolean tracing = TNTTracer15.getStatus() == TNTTracer15.Status.RECORD || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO;
|
||||||
|
boolean autoTracer = TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO;
|
||||||
|
strings.add("§eTrace§8: " + (tracing ? "§aan" : (autoTracer ? "§eauto" : "§caus")));
|
||||||
|
|
||||||
|
if (tracing) {
|
||||||
|
strings.add("§3");
|
||||||
|
strings.add("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TNTTracer15.sidebar_startTime())));
|
||||||
|
strings.add("§eTicks§8: §7" + ((System.currentTimeMillis() - TNTTracer15.sidebar_startTime()) / 50));
|
||||||
|
strings.add("§eAnzahl TNT§8: §7" + TNTTracer15.sidebar_TNT());
|
||||||
|
}
|
||||||
|
|
||||||
|
strings.add("§4");
|
||||||
|
strings.add("§eTPS§8: §7" + CommandInfo.getTps()[0]);
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getSidebar_12() {
|
||||||
|
List<String> strings = new ArrayList<>();
|
||||||
|
strings.add("§1");
|
||||||
|
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||||
|
strings.add("§2");
|
||||||
|
strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"));
|
||||||
|
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
|
||||||
|
strings.add("§3");
|
||||||
|
strings.add("§eTPS§8: §7" + CommandInfo.getTps()[0]);
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren