SteamWar/BauSystem
Archiviert
13
0
Dieser Commit ist enthalten in:
jojo 2020-08-30 02:23:23 +02:00
Ursprung 8aee883a8e
Commit b13dcc57a1
35 geänderte Dateien mit 1307 neuen und 1663 gelöschten Zeilen

Datei anzeigen

@ -1,196 +1,95 @@
package de.steamwar.bausystem.tracer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
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 java.util.*;
@SuppressWarnings("deprecation")
class TNTTracer_12 {
private TNTTracer_12(){}
private static final byte BRICK_STEP = new Step(Material.BRICK).getData();
private static final byte INVERTED_BRICK_STEP = (byte)(BRICK_STEP + 8);
private static final World world = Bukkit.getWorlds().get(0);
private static TracerUpdater tracerUpdater;
private static TraceCache traceCache = new TraceCache();
static void remove(Map<TNTPrimed, LinkedList<Location>> locations, TNTPrimed tnt){
Material material = tnt.getLocation().getBlock().getType();
if(material == Material.WATER || material == Material.STATIONARY_WATER)
locations.remove(tnt);
private static boolean actionBar = true;
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 int show(Map<TNTPrimed, LinkedList<Location>> locations, Set<Location> printedLocs){
for(LinkedList<Location> tntTrace : locations.values()){
if(tntTrace.size() == 1)
printLocation(tntTrace.getFirst(), printedLocs);
else if(tntTrace.size() > 1)
interpolate(tntTrace, printedLocs);
}
locations.clear();
return printedLocs.size();
}
static boolean airOrBrick(Block block){
Material material = block.getType();
if(material == Material.AIR || material == Material.BRICK)
return true;
if(material != Material.STEP)
return false;
byte data = block.getData();
return data == BRICK_STEP || data == INVERTED_BRICK_STEP;
}
private static void interpolate(LinkedList<Location> trace, Set<Location> printedLocs){
ListIterator<Location> it = trace.listIterator();
Location previous = it.next();
printLocation(previous, printedLocs);
while(it.hasNext()){
Location actual = it.next();
Set<Double> xSteps = getSteps(previous.getX(), actual.getX());
Set<Double> ySteps = getSteps(previous.getY(), actual.getY());
Set<Double> zSteps = getSteps(previous.getZ(), actual.getZ());
for(double y : ySteps)
printLocation(new Location(world, previous.getX(), y, previous.getZ()), printedLocs);
for(double x : xSteps)
printLocation(new Location(world, x, actual.getY(), previous.getZ()), printedLocs);
for(double z : zSteps)
printLocation(new Location(world, actual.getX(), actual.getY(), z), printedLocs);
previous = actual;
}
}
private static Set<Double> getSteps(double previous, double actual){
Set<Double> steps = new HashSet<>();
if(actual < previous){
double temp = previous;
previous = actual;
actual = temp;
}
steps.add(actual);
steps.add(previous);
double iterator = previous;
while(actual - iterator > 1){
iterator++;
steps.add(iterator);
}
return steps;
}
private static void printLocation(Location l, Set<Location> printedLocs){
Block block = l.getBlock();
double rx = l.getX() - Math.floor(l.getX());
double ry = l.getY() - Math.floor(l.getY());
double rz = l.getZ() - Math.floor(l.getZ());
BlockStatus main;
BlockStatus upper;
if(ry <= 0.02){
main = BlockStatus.BLOCK;
upper = BlockStatus.NONE;
}else if(ry <= 0.5){
main = BlockStatus.BLOCK;
upper = BlockStatus.SLAB;
}else if(ry <= 0.52){
main = BlockStatus.INVERTED_SLAB;
upper = BlockStatus.SLAB;
}else{
main = BlockStatus.INVERTED_SLAB;
upper = BlockStatus.BLOCK;
}
Block nearX = null;
Block nearZ = null;
Block nearCross = null;
if(rx < 0.48){
nearX = block.getRelative(BlockFace.WEST);
if(rz < 0.48){
nearZ = block.getRelative(BlockFace.NORTH);
nearCross = block.getRelative(BlockFace.NORTH_WEST);
}else if(rz > 0.52){
nearZ = block.getRelative(BlockFace.SOUTH);
nearCross = block.getRelative(BlockFace.SOUTH_WEST);
static void init(Plugin plugin, TracerUpdater tracerUpdater) {
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
synchronized (synchronizer) {
synchronizer.notifyAll();
}
}else if(rx > 0.52){
nearX = block.getRelative(BlockFace.EAST);
if(rz < 0.48){
nearZ = block.getRelative(BlockFace.NORTH);
nearCross = block.getRelative(BlockFace.NORTH_EAST);
}else if(rz > 0.52){
nearZ = block.getRelative(BlockFace.SOUTH);
nearCross = block.getRelative(BlockFace.SOUTH_EAST);
}, 1, 20);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
while (true) {
synchronized (synchronizer) {
try {
synchronizer.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
run();
}
}else{
if(rz < 0.48){
nearZ = block.getRelative(BlockFace.NORTH);
}else if(rz > 0.52){
nearZ = block.getRelative(BlockFace.SOUTH);
}
}
});
setBlock(block, main, printedLocs);
setBlock(block.getRelative(BlockFace.UP), upper, printedLocs);
if(nearX != null){
setBlock(nearX, main, printedLocs);
setBlock(nearX.getRelative(BlockFace.UP), upper, printedLocs);
}
if(nearZ != null){
setBlock(nearZ, main, printedLocs);
setBlock(nearZ.getRelative(BlockFace.UP), upper, printedLocs);
}
if(nearCross != null){
setBlock(nearCross, main, printedLocs);
setBlock(nearCross.getRelative(BlockFace.UP), upper, printedLocs);
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 setBlock(Block block, BlockStatus status, Set<Location> printedLocs){
if(status == BlockStatus.NONE)
return;
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
if (locs.isEmpty()) return;
Material material = block.getType();
if(material == Material.AIR){
status.setBlock(block);
printedLocs.add(block.getLocation());
}else if(material == Material.STEP){
byte data = block.getData();
if(data == BRICK_STEP){
if(status == BlockStatus.BLOCK)
status.setBlock(block);
else if(status == BlockStatus.INVERTED_SLAB)
BlockStatus.BLOCK.setBlock(block);
}else if(data == INVERTED_BRICK_STEP){
if(status == BlockStatus.BLOCK)
status.setBlock(block);
else if(status == BlockStatus.SLAB)
BlockStatus.BLOCK.setBlock(block);
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));
}
}
}
enum BlockStatus{
NONE(Material.AIR, 0),
BLOCK(Material.BRICK, 0),
SLAB(Material.STEP, BRICK_STEP),
INVERTED_SLAB(Material.STEP, INVERTED_BRICK_STEP);
private final Material material;
private final byte data;
BlockStatus(Material material, int data){
this.material = material;
this.data = (byte)data;
}
void setBlock(Block b){
b.setTypeIdAndData(material.getId(), data, true);
}
}
}

Datei anzeigen

@ -1,152 +0,0 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow;
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);
private boolean hiding = false;
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 void show(Player player, TNTCallbackShow.ShowMode showMode) {
if (hiding) return;
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 == TNTCallbackShow.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 == TNTCallbackShow.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 void hideBlockTraces(Player player) {
hiding = true;
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];
hiding = false;
}
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;
}
}

Datei anzeigen

@ -1,48 +1,33 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.tracer.debugcallback.DebugCallbackActionBar;
import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow;
import de.steamwar.bausystem.tracer.updatecallback.*;
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.*;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
@SuppressWarnings("deprecation")
class TNTTracer_15 {
private TNTTracer_15(){}
private static TracerCallbackPositions tracerCallbackPositions;
private static TracerCallbackUpdatePoints tracerCallbackUpdatePoints;
private static DebugCallbackActionBar debugCallbackActionBar;
private static TNTCallbackShow tntCallbackShow;
private static TracerUpdateManager tracerUpdateManager;
private static Map<Player, PlayerTraceCache_15> playerMap = new HashMap<>();
private static TracerUpdater tracerUpdater;
private static TraceCache traceCache = new TraceCache();
private static boolean actionBar = false;
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;
private static World world;
static void worldInit() {
if (world != null) return;
world = Bukkit.getWorlds().get(0);
}
static void init(Plugin plugin, TracerCallbackPositions tracerCallbackPositions, TracerCallbackUpdatePoints tracerCallbackUpdatePoints, DebugCallbackActionBar debugCallbackActionBar, TNTCallbackShow tntCallbackShow, TracerUpdateManager tracerUpdateManager) {
static void init(Plugin plugin, TracerUpdater tracerUpdater) {
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
synchronized (synchronizer) {
synchronizer.notifyAll();
@ -61,106 +46,46 @@ class TNTTracer_15 {
}
});
TNTTracer_15.tracerCallbackPositions = tracerCallbackPositions;
TNTTracer_15.tracerCallbackUpdatePoints = tracerCallbackUpdatePoints;
TNTTracer_15.debugCallbackActionBar = debugCallbackActionBar;
TNTTracer_15.tntCallbackShow = tntCallbackShow;
TNTTracer_15.tracerUpdateManager = tracerUpdateManager;
}
static void initWorld() {
PlayerTraceCache_15.init();
}
static boolean isInWater(TNTPrimed tnt) {
return tnt.getLocation().getBlock().getType() == Material.WATER;
TNTTracer_15.tracerUpdater = tracerUpdater;
}
private static void run() {
if (actionBar) {
String actionBar = debugCallbackActionBar.run();
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar)));
}
for (Player p : Bukkit.getOnlinePlayers()) {
PlayerTraceCache_15 traceCache;
if (!playerMap.containsKey(p)) {
traceCache = new PlayerTraceCache_15();
playerMap.put(p, traceCache);
} else {
traceCache = playerMap.get(p);
if (actionBar) {
String actionBar = tracerUpdater.actionBar(p);
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
}
updateShowPlayer(p, traceCache);
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 updateShowPlayer(Player p, PlayerTraceCache_15 traceCache) {
if (tracerUpdateManager.run(p, traceCache.nearLastLocation(p))) {
update(p, traceCache);
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);
}
traceCache.show(p, tntCallbackShow.run(p));
}
private static float[] noValue = new float[0];
private static void showTraces(Set<TraceCache.Loc> locs, TracerUpdater.DisplayMode displayMode, Player player) {
if (locs.isEmpty()) return;
private static void update(Player p, PlayerTraceCache_15 traceCache) {
float[] floats = tracerCallbackPositions.run(p);
if (floats.length == 0 || floats.length % 3 != 0) {
traceCache.setPositions(noValue);
traceCache.setUpdatePoints(noValue);
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));
}
}
Location location = p.getLocation();
float px = (float)location.getX();
float py = (float)location.getY();
float pz = (float)location.getZ();
traceCache.setPositions(accumulatePositions(floats, px, py, pz));
floats = tracerCallbackUpdatePoints.run(p);
if (floats.length == 0 || floats.length % 3 != 0) {
traceCache.setUpdatePoints(noValue);
return;
}
traceCache.setUpdatePoints(accumulatePositions(floats, px, py, pz));
}
private static float[] accumulatePositions(float[] floats, float px, float py, float pz) {
if (true) {
return floats;
}
LinkedList<Float> linkedList = new LinkedList<>();
for (int i = 0; i < floats.length; i += 3) {
float x = floats[i + 0];
float y = floats[i + 1];
float z = floats[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);
}
float[] result = new float[linkedList.size()];
Iterator<Float> floatIterator = linkedList.iterator();
int index = 0;
while (floatIterator.hasNext()) {
result[index] = floatIterator.next();
index++;
}
return result;
}
static void hideBlockTraces(Player p) {
PlayerTraceCache_15 tracerCache15 = playerMap.get(p);
if (tracerCache15 == null) return;
tracerCache15.hideBlockTraces(p);
}
}

Datei anzeigen

@ -0,0 +1,126 @@
package de.steamwar.bausystem.tracer;
import org.bukkit.entity.Player;
import java.util.*;
public class TraceCache {
private static final Set<Loc> empty = new HashSet();
private Map<String, Set<Loc>> playerMap = new HashMap<>();
private Map<String, TracerUpdater.DisplayMode> playerDisplayMap = new HashMap<>();
public Set<Loc> get(Player player) {
return playerMap.getOrDefault(player.getUniqueId().toString(), empty);
}
public Set<Loc> update(Player player, TracerUpdater tracerUpdater, boolean dirty) {
if (!dirty) return empty;
String key = player.getUniqueId().toString();
Set<Loc> locOld;
TracerUpdater.DisplayMode displayMode;
if (!playerMap.containsKey(key)) {
locOld = new HashSet<>();
displayMode = tracerUpdater.getDisplayType(player);
} else {
locOld = playerMap.get(key);
displayMode = playerDisplayMap.get(key);
}
Set<Loc> locSet = new HashSet<>();
tracerUpdater.updatePoints(player).forEach(loc -> {
loc.updatePoint = true;
locSet.add(loc);
});
tracerUpdater.updateLocations(player).forEach(loc -> {
loc.updatePoint = false;
locSet.add(loc);
});
playerMap.put(key, locSet);
TracerUpdater.DisplayMode currentMode = tracerUpdater.getDisplayType(player);
playerDisplayMap.put(key, currentMode);
if (currentMode == TracerUpdater.DisplayMode.Particle && displayMode == TracerUpdater.DisplayMode.Block) return locOld;
if (currentMode == TracerUpdater.DisplayMode.Block) return diff(locOld, locSet);
return empty;
}
public static class Loc {
public final float x;
public final float y;
public final float z;
private final float dx;
private final float dy;
private final float dz;
public boolean updatePoint = false;
public Loc(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
this.dx = round(x);
this.dy = round(y);
this.dz = round(z);
}
private static int roundNumber = 10;
private static float round(float toRound) {
float r = (toRound * roundNumber);
float t = r - (int) r;
if (t >= 0.5) {
return (((float)(int)r) + 1) / roundNumber;
} else {
return (((float)(int)r) + 0) / roundNumber;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Loc)) return false;
Loc loc = (Loc) o;
return Float.compare(loc.dx, dx) == 0 &&
Float.compare(loc.dy, dy) == 0 &&
Float.compare(loc.dz, dz) == 0;
}
@Override
public int hashCode() {
return Objects.hash(dx, dy, dz);
}
@Override
public String toString() {
return "Loc{" +
"x=" + x +
", y=" + y +
", z=" + z +
'}';
}
public boolean remove(Player player, double radius) {
double x = player.getLocation().getX();
double y = player.getLocation().getY();
double z = player.getLocation().getZ();
double dx = (this.x - x) * (this.x - x);
double dy = (this.y - y) * (this.y - y);
double dz = (this.z - z) * (this.z - z);
return (dx + dy + dz) > radius * radius;
}
}
private Set<Loc> diff(Set<Loc> locOld, Set<Loc> locNew) {
if (locOld.isEmpty()) return empty;
if (locNew.isEmpty()) return locOld;
for (Loc l : locNew) {
locOld.remove(l);
}
return locOld;
}
}

Datei anzeigen

@ -0,0 +1,48 @@
package de.steamwar.bausystem.tracer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
public class TraceUtils {
private static Location location;
public static void locationInit() {
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);
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);
}
public 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);
}
}
public 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);
}
}
public static Location makeLocation(float x, float y, float z) {
location.setX(x);
location.setY(y);
location.setZ(z);
return location;
}
}

Datei anzeigen

@ -1,23 +0,0 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.tracer.showcallback.TNTCallbackCacheUpdate;
import de.steamwar.bausystem.tracer.updatecallback.TracerCallbackTracing;
import org.bukkit.entity.Player;
public class TracerUpdateManager {
private TracerCallbackTracing tracerCallbackTracing;
private TNTCallbackCacheUpdate tntCallbackCacheUpdate;
public TracerUpdateManager(TracerCallbackTracing tracerCallbackTracing, TNTCallbackCacheUpdate tntCallbackCacheUpdate) {
this.tracerCallbackTracing = tracerCallbackTracing;
this.tntCallbackCacheUpdate = tntCallbackCacheUpdate;
}
boolean run(Player p, boolean nearLastLocation) {
if (tntCallbackCacheUpdate.run(p)) return false;
if (!tracerCallbackTracing.run(p) && nearLastLocation) return false;
return true;
}
}

Datei anzeigen

@ -0,0 +1,21 @@
package de.steamwar.bausystem.tracer;
import org.bukkit.entity.Player;
import java.util.Set;
public interface TracerUpdater {
enum DisplayMode {
Block,
Particle,
}
Set<TraceCache.Loc> updateLocations(Player player);
Set<TraceCache.Loc> updatePoints(Player player);
boolean needsUpdate(Player player);
DisplayMode getDisplayType(Player player);
String actionBar(Player player);
}

Datei anzeigen

@ -1,8 +0,0 @@
package de.steamwar.bausystem.tracer.debugcallback;
@FunctionalInterface
public interface DebugCallbackActionBar {
String run();
}

Datei anzeigen

@ -1,10 +0,0 @@
package de.steamwar.bausystem.tracer.showcallback;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface TNTCallbackCacheUpdate {
boolean run(Player p);
}

Datei anzeigen

@ -1,15 +0,0 @@
package de.steamwar.bausystem.tracer.showcallback;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface TNTCallbackShow {
public static enum ShowMode {
BLOCK,
PARTICLE
}
ShowMode run(Player p);
}

Datei anzeigen

@ -1,10 +0,0 @@
package de.steamwar.bausystem.tracer.updatecallback;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface TracerCallbackPositions {
float[] run(Player p);
}

Datei anzeigen

@ -1,10 +0,0 @@
package de.steamwar.bausystem.tracer.updatecallback;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface TracerCallbackTracing {
boolean run(Player p);
}

Datei anzeigen

@ -1,10 +0,0 @@
package de.steamwar.bausystem.tracer.updatecallback;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface TracerCallbackUpdatePoints {
float[] run(Player p);
}

Datei anzeigen

@ -1,10 +1,16 @@
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.TNTTracer15;
import de.steamwar.bausystem.tracer.trace.ShowManager;
import de.steamwar.bausystem.world.*;
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;
import de.steamwar.bausystem.world.RegionListener;
import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core;
import de.steamwar.scoreboard.SWScoreboard;
@ -97,9 +103,12 @@ public class BauSystem extends JavaPlugin implements Listener {
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
Bukkit.getPluginManager().registerEvents(new TNTListener(), this);
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
Bukkit.getPluginManager().registerEvents(new MoveEvent(), this);
new AFKStopper();
if (Core.getVersion() == 15) {
TNTTracer15.initTNTTracer_15();
TNTTracer.init15();
} else {
TNTTracer.init12();
}
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
@ -265,9 +274,11 @@ public class BauSystem extends JavaPlugin implements Listener {
attachment.setPermission("worldedit.calc", true);
attachment.setPermission("worldedit.fill", true);*/
if (Core.getVersion() == 15) {
ShowManager.add(p);
}
RecordManager.worldInit();
TNTTracer.worldInit();
TraceUtils.locationInit();
ShowManager.add(p);
}
@EventHandler
@ -276,11 +287,6 @@ public class BauSystem extends JavaPlugin implements Listener {
SWScoreboard.removeScoreboard(p);
if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) {
Bukkit.shutdown();
return;
}
if (Core.getVersion() == 15) {
ShowManager.remove(p);
}
}

Datei anzeigen

@ -2,12 +2,10 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.tracer.TNTTracer12;
import de.steamwar.bausystem.tracer.TNTTracer15;
import de.steamwar.bausystem.tracer.trace.ShowManager;
import de.steamwar.bausystem.tracer.trace.ShowStatus;
import de.steamwar.bausystem.tracer.manager.ShowManager;
import de.steamwar.bausystem.tracer.manager.TraceManager;
import de.steamwar.bausystem.tracer.recorder.RecordManager;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.core.Core;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -15,38 +13,24 @@ import org.bukkit.entity.Player;
public class CommandTrace implements CommandExecutor {
private void help12(Player player) {
player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen");
player.sendMessage("§8/§etrace show §8- §7Zeigt alle TNT-Positionen");
player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer");
}
private void help15(Player player) {
private void help(Player player) {
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 toggleauto §8- §7Automatischer Aufnahmenstart");
player.sendMessage("§8/§etrace togglewater §8- §7Tracet auch TNT im Wasser");
player.sendMessage("§8/§etrace show §8<§eblock§8|§eparticle§8|§7TNT-ID§8> §8- §7Zeigt alle TNT-Positionen");
player.sendMessage("§8/§etrace hide §8<§7TNT-ID§8> §8- §7Versteckt alle TNT-Positionen");
player.sendMessage("§8/§etrace toggleshow §8<§7TNT-ID§8> §8- §7Zeigt/Versteckt ein TNT");
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("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an");
player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) return false;
Player player = (Player) sender;
switch (Core.getVersion()) {
case 15:
return tracer15(player, args);
default:
return tracer12(player, args);
}
return tracer((Player) sender, args);
}
private boolean permissionCheck(Player player) {
@ -57,189 +41,41 @@ public class CommandTrace implements CommandExecutor {
return true;
}
private boolean tracer12(Player player, String[] args) {
private boolean tracer(Player player, String[] args) {
if(args.length == 0){
help12(player);
help(player);
return false;
}
if (!permissionCheck(player)) return false;
switch(args[0].toLowerCase()){
switch (args[0].toLowerCase()) {
case "start":
TNTTracer12.start();
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
break;
case "show":
int blocks = TNTTracer12.show();
player.sendMessage(BauSystem.PREFIX + "§a" + blocks + " TNT-Positionen angezeigt");
break;
case "stop":
TNTTracer12.stop();
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
break;
default:
help12(player);
}
return false;
}
private boolean tracer15(Player player, String[] args) {
if(args.length == 0){
help15(player);
return false;
}
if (!permissionCheck(player)) return false;
switch(args[0].toLowerCase()){
case "start":
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) {
TNTTracer15.toggleAuto();
}
TNTTracer15.start();
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
break;
case "stop":
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) {
TNTTracer15.toggleAuto();
}
TNTTracer15.stop();
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
break;
case "toggleauto":
boolean mode = TNTTracer15.toggleAuto();
if (mode) {
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
} else {
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
}
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");
}
case "auto":
RecordManager.tracer(player, args);
break;
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 des TNT mit ID " + tntID + " angezeigt");
player.sendMessage(BauSystem.PREFIX + "§eBei zu vielen zu zeigenden Positionen wird der Block Tracer aktiviert");
// player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen");
} catch (NumberFormatException e) {
help15(player);
}
return false;
}
}
ShowManager.get(player).show();
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
player.sendMessage(BauSystem.PREFIX + "§eBei zu vielen zu zeigenden Positionen wird der Block Tracer aktiviert");
// player.sendMessage(BauSystem.PREFIX + "§eBitte aktiviere animiertes Feuer in den Grafikeinstellungen");
break;
case "hide":
if (args.length == 2) {
try {
int tntID = Integer.parseInt(args[1]);
ShowManager.get(player).removeSelection(tntID);
player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " versteckt");
} catch (NumberFormatException e) {
help15(player);
}
return false;
}
ShowManager.get(player).hide();
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt");
break;
case "toggleshow":
if (args.length == 2) {
try {
int tntID = Integer.parseInt(args[1]);
mode = ShowManager.get(player).toggleShow(tntID);
if (mode) {
player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " angezeigt");
} else {
player.sendMessage(BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID " + tntID + " versteckt");
}
} catch (NumberFormatException e) {
help15(player);
}
} else {
help15(player);
}
break;
case "delete":
if (args.length == 2) {
try {
int tntID = Integer.parseInt(args[1]);
ShowManager.removeTrace(tntID);
TNTTracer15.remove(tntID);
player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + tntID + " gelöscht");
} catch (NumberFormatException e) {
help15(player);
}
return false;
}
TNTTracer15.clear();
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
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;
case "distance":
if (ShowManager.tracer(player, args)) {
help(player);
}
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":
//player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
//break;
// player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
break;
case "delete":
if (TraceManager.delete(player, args)) {
help(player);
}
break;
default:
help15(player);
help(player);
}
return false;
}

Datei anzeigen

@ -1,6 +1,6 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.tracer.TNTTracer15;
import de.steamwar.bausystem.tracer.recorder.RecordManager;
import de.steamwar.core.Core;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -16,34 +16,18 @@ 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);
}
return tracerTabComplete((Player) sender, args);
}
private List<String> tracer12TabComplete(Player player, String[] args) {
private List<String> tracerTabComplete(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) {
if (RecordManager.getStatus() == RecordManager.Status.IDLE || RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) {
tabComplete.add("start");
} else {
tabComplete.add("stop");
}
tabComplete.add("toggleauto");
tabComplete.add("togglewater");
tabComplete.add("auto");
tabComplete.add("toggleshow");
tabComplete.add("show");
if (args[0].equalsIgnoreCase("show") && args.length == 2) {
@ -55,10 +39,14 @@ public class CommandTraceTabCompleter implements TabCompleter {
if (args[0].equalsIgnoreCase("interpolate") && args.length == 2) {
return manageList(new ArrayList<>(Arrays.asList("all", "yaxis", "none")), args, 1);
}
tabComplete.add("distance");
if (args[0].equalsIgnoreCase("distance") && args.length == 2) {
return manageList(new ArrayList<>(Arrays.asList("3", "4", "5", "6", "7", "8", "9", "10", "11", "default")), args, 1);
}
//tabComplete.add("gui");
tabComplete.add("list");
//tabComplete.add("list");
if (args.length == 2) {
if (args.length >= 2) {
return new ArrayList<>();
}
return manageList(tabComplete, args, 0);

Datei anzeigen

@ -0,0 +1,17 @@
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);
}
}

Datei anzeigen

@ -1,5 +1,8 @@
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;
@ -10,16 +13,19 @@ public class TNTListener implements Listener {
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
switch (Core.getVersion()) {
case 15:
onEntityExplode15(event);
break;
default:
onEntityExplode12(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) {
/*private void onEntityExplode12(EntityExplodeEvent event) {
if(TNTTracer12.getStatus() != TNTTracer12.Status.RECORD) return;
if(!(event.getEntity() instanceof TNTPrimed)) return;
TNTPrimed entity = (TNTPrimed) event.getEntity();
@ -28,9 +34,9 @@ public class TNTListener implements Listener {
private void onEntityExplode15(EntityExplodeEvent event) {
if(!(event.getEntity() instanceof TNTPrimed)) return;
if (TNTTracer15.getStatus() == TNTTracer15.Status.IDLE_AUTO || TNTTracer15.getStatus() == TNTTracer15.Status.RECORD_AUTO) {
TNTTracer15.start();
if (TraceRecorder.getStatus() == TraceRecorder.Status.IDLE_AUTO || TraceRecorder.getStatus() == TraceRecorder.Status.RECORD_AUTO) {
TraceRecorder.start();
}
TNTTracer15.explode((TNTPrimed) event.getEntity());
}
TraceRecorder.explode((TNTPrimed) event.getEntity());
}*/
}

Datei anzeigen

@ -0,0 +1,83 @@
package de.steamwar.bausystem.tracer;
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 org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class TNTTracer {
private static TracerUpdater tracerUpdater = new TracerUpdater() {
@Override
public Set<TraceCache.Loc> updateLocations(Player player) {
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
Set<TraceCache.Loc> locSet = new HashSet<>();
while (traces.hasNext()) {
locSet.addAll(traces.next().locs());
}
double radius = ShowManager.get(player).getShowRadius();
locSet.removeIf(loc -> loc.remove(player, radius));
return locSet;
}
@Override
public Set<TraceCache.Loc> updatePoints(Player player) {
Iterator<TNTTrace> traces = ShowManager.get(player).getTraces().descendingIterator();
Set<TraceCache.Loc> locSet = new HashSet<>();
while (traces.hasNext()) {
locSet.addAll(traces.next().locsUpdate(ShowManager.get(player).getDisplayMode()));
}
double radius = ShowManager.get(player).getShowRadius();
locSet.removeIf(loc -> loc.remove(player, radius));
return locSet;
}
@Override
public boolean needsUpdate(Player player) {
return ShowManager.get(player).isDirty();
}
@Override
public DisplayMode getDisplayType(Player player) {
switch (ShowManager.get(player).getDisplayType()) {
case Block:
return DisplayMode.Block;
case Particle:
return DisplayMode.Particle;
default:
break;
}
return DisplayMode.Particle;
}
@Override
public String actionBar(Player player) {
return TraceActionbar.traceMemory() + " " + TraceActionbar.traceSize() + " " + TraceActionbar.showRadius(player);
}
};
public static void init15() {
TNTTracer_15.init(BauSystem.getPlugin(), tracerUpdater);
}
public static void init12() {
TNTTracer_12.init(BauSystem.getPlugin(), tracerUpdater);
}
public static void worldInit() {
switch (Core.getVersion()) {
case 15:
TNTTracer_15.worldInit();
break;
default:
TNTTracer_12.worldInit();
break;
}
}
}

Datei anzeigen

@ -1,82 +0,0 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitTask;
import java.util.*;
public class TNTTracer12 {
private static BukkitTask task;
private static final Set<Location> printedLocs = new HashSet<>();
private static final Map<TNTPrimed, LinkedList<Location>> locations = new HashMap<>();
private static final World world = Bukkit.getWorlds().get(0);
static Status getStatus() {
return status;
}
private static Status status = Status.IDLE;
static void remove(TNTPrimed tnt){
TNTTracer_12.remove(locations, tnt);
}
public static void start() {
if(status == Status.RECORD)
return;
stop();
locations.clear();
status = Status.RECORD;
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer12::run, 1, 1);
}
public static int show() {
if(status == Status.SHOW)
return printedLocs.size();
stop();
status = Status.SHOW;
return TNTTracer_12.show(locations, printedLocs);
}
public static void stop() {
status = Status.IDLE;
if(task != null)
task.cancel();
for(Location l : printedLocs){
Block b = world.getBlockAt(l);
if(airOrBrick(b))
b.setType(Material.AIR);
}
printedLocs.clear();
}
private static boolean airOrBrick(Block block){
return TNTTracer_12.airOrBrick(block);
}
private static void run() {
world.getEntities()
.stream()
.filter(e -> e instanceof TNTPrimed)
.map(e -> (TNTPrimed)e)
.forEach(tnt -> locations.computeIfAbsent(tnt, k -> new LinkedList<>()).add(tnt.getLocation()));
}
enum Status{
RECORD,
SHOW,
IDLE
}
}

Datei anzeigen

@ -1,486 +0,0 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.showcallback.TNTCallbackShow;
import de.steamwar.bausystem.tracer.trace.ShowManager;
import de.steamwar.bausystem.tracer.trace.ShowStatus;
import de.steamwar.bausystem.tracer.trace.TNTFrame;
import de.steamwar.bausystem.tracer.trace.TNTTrace;
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 org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitTask;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
public class TNTTracer15 {
private static BukkitTask task;
private static long current = System.currentTimeMillis();
private static boolean removeInWater = true;
private static long lastExplosion = System.currentTimeMillis();
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<>();
public static TNTTracer15.Status getStatus() {
return status;
}
private static TNTTracer15.Status status = Status.IDLE;
private static final float[] noValue = new float[0];
public static void initTNTTracer_15() {
TNTTracer_15.init(BauSystem.getPlugin(), TNTTracer15::getTracePoints, TNTTracer15::getTraceUpdatePoints, TNTTracer15::getActionBar, TNTTracer15::showMode, new TracerUpdateManager(p -> ShowManager.get(p).isDirty(), p -> {
if (System.currentTimeMillis() - lastExplosion < 4500) {
ShowManager.get(p).dirty();
}
return System.currentTimeMillis() - lastExplosion < 4500;
}));
}
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);
if (showStatus.getShow() == ShowStatus.Show.NONE) return noValue;
if (showStatus.getShow() == ShowStatus.Show.ALL) {
return getAllTraces();
}
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 accumulate(traces);
}
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 TNTCallbackShow.ShowMode showMode(Player player) {
if (ShowManager.get(player).getShowMode() == ShowStatus.ShowMode.BLOCK) {
return TNTCallbackShow.ShowMode.BLOCK;
} else {
return TNTCallbackShow.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;
if (System.currentTimeMillis() - lastExplosion > 4500) {
ShowManager.dirty();
}
lastExplosion = System.currentTimeMillis();
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() {
if (status == Status.RECORD || status == Status.RECORD_AUTO) {
stop();
}
tntFrames.clear();
ShowManager.removeAllTraces();
}
public static void remove(int tntID) {
Iterator<TNTFrame> frameIterator = tntFrames.iterator();
while (frameIterator.hasNext()) {
frameIterator.next().remove(tntID);
}
}
public static void hideBlockTraces(Player p) {
TNTTracer_15.hideBlockTraces(p);
}
public static void start() {
if (status == Status.IDLE || status == Status.IDLE_AUTO) {
if (status == Status.IDLE) {
status = Status.RECORD;
} else {
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet")));
status = Status.RECORD_AUTO;
}
tntFrames.addLast(new TNTFrame());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTTracer15::run, 1, 1);
current = System.currentTimeMillis();
run();
}
if (status == Status.RECORD_AUTO) {
current = System.currentTimeMillis();
}
}
public static void stop() {
if (status == Status.IDLE || status == Status.IDLE_AUTO) {
return;
}
if (status == Status.RECORD) {
status = Status.IDLE;
}
if (status == Status.RECORD_AUTO) {
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt")));
status = Status.IDLE_AUTO;
}
ShowManager.dirty();
if (task != null) task.cancel();
if (tntFrames.getLast().finish()) {
tntFrames.removeLast();
}
}
public static boolean toggleAuto() {
if (status == Status.IDLE) {
status = Status.IDLE_AUTO;
return true;
}
if (status == Status.RECORD) {
status = Status.RECORD_AUTO;
current = System.currentTimeMillis();
return true;
}
if (status == Status.IDLE_AUTO) {
status = Status.IDLE;
return false;
}
if (status == Status.RECORD_AUTO) {
status = Status.RECORD;
return false;
}
return false;
}
private static void run() {
if (status == Status.RECORD_AUTO && System.currentTimeMillis() - current > 4500) {
stop();
}
tntFrames.getLast().add(world.getEntities()
.stream()
.filter(e -> e instanceof TNTPrimed)
.map(e -> (TNTPrimed)e)
);
}
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()));
TextComponent textComponent = new TextComponent();
textComponent.setText(st.toString());
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Zeigt die Positionen dieses TNT's an")));
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace toggleshow " + tntTrace.getUniqueID()));
player.spigot().sendMessage(textComponent);
}
}
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{
RECORD,
RECORD_AUTO,
IDLE,
IDLE_AUTO
}
}

Datei anzeigen

@ -0,0 +1,52 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.tracer.manager.FrameManager;
import de.steamwar.bausystem.tracer.manager.ShowManager;
import de.steamwar.bausystem.tracer.manager.TraceManager;
import org.bukkit.entity.Player;
import java.util.Iterator;
import java.util.LinkedList;
public class TraceActionbar {
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;
}
}
public static String traceMemory() {
try {
long bitFrames = FrameManager.get().size() * 32L;
LinkedList<Integer> traceIDs = TraceManager.get();
long bitTraces = traceIDs.size() * 32L;
long bitTracesIntern = 0;
Iterator<Integer> iterator = traceIDs.descendingIterator();
while (iterator.hasNext()) {
bitTracesIntern += TraceManager.get(iterator.next()).realLength() * 32L;
}
double mByte = (bitFrames + bitTraces + bitTracesIntern) / 8.0 / 1024;
return "§e" + round(mByte, 4) + " §cKB";
} catch (Exception e) {
}
return "§e??? §cKB";
}
public static String traceSize() {
return "§e" + TraceManager.get().size() + " §cTraces";
}
public static String showRadius(Player p) {
return "§e" + ShowManager.get(p).getShowRadius() + " §cRadius";
}
}

Datei anzeigen

@ -0,0 +1,22 @@
package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.tracer.manager.FrameManager;
import de.steamwar.bausystem.tracer.recorder.RecordManager;
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
public class TraceSidebar {
public static long traceStart() {
return TNTRecorder.recordStart;
}
public static long traceTicks() {
return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50;
}
public static int traceSize() {
if (RecordManager.activeFrameID == null) return 0;
return FrameManager.get(RecordManager.activeFrameID).size();
}
}

Datei anzeigen

@ -0,0 +1,51 @@
package de.steamwar.bausystem.tracer.manager;
import java.util.*;
public class FrameManager {
private static Map<Integer, List<Integer>> frameMap = new HashMap<>();
public static int createFrame() {
int id = IDManager.generateID();
frameMap.put(id, new ArrayList<>());
return id;
}
static void add(int frameID, int tntID) {
if (!frameMap.containsKey(frameID)) {
return;
}
frameMap.get(frameID).add(tntID);
}
public static List<Integer> get(int frameID) {
if (!frameMap.containsKey(frameID)) {
return Arrays.asList(frameID);
}
return new ArrayList<>(frameMap.get(frameID));
}
public static List<Integer> get() {
return new LinkedList<>(frameMap.keySet());
}
static void remove(int frameID, int traceID) {
if (!frameMap.containsKey(frameID)) {
return;
}
frameMap.get(frameID).remove((Integer) traceID);
cleanUp(frameID);
}
public static void cleanUp(int frameID) {
if (!frameMap.containsKey(frameID)) {
return;
}
if (!frameMap.get(frameID).isEmpty()) {
return;
}
frameMap.remove((Integer) frameID);
}
}

Datei anzeigen

@ -0,0 +1,11 @@
package de.steamwar.bausystem.tracer.manager;
public class IDManager {
private static int currentID = 0;
public static synchronized int generateID() {
return currentID++;
}
}

Datei anzeigen

@ -0,0 +1,336 @@
package de.steamwar.bausystem.tracer.manager;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.TraceCache;
import de.steamwar.bausystem.tracer.trace.TNTTrace;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
public class ShowManager {
public enum DisplayMode {
NONE,
Y_AXIS,
ALL
}
public enum DisplayType {
Particle,
Block
}
public enum ShowSelection {
NONE,
SELECTIVE,
ALL
}
public static boolean tracer(Player player, String[] args) {
ShowStatus showStatus = showMap.get(player.getUniqueId().toString());
showStatus.dirty = true;
switch (args[0].toLowerCase()) {
case "show":
showStatus.show();
if (args.length == 2) {
return tracerShow(player, showStatus, args);
}
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
break;
case "distance":
if (args.length != 2) {
return true;
}
if (args[1].equalsIgnoreCase("default")) {
ShowManager.get(player).setSlope(7.0);
player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt");
return false;
}
try {
double radius = Double.parseDouble(args[1]);
radius = (double)(int)(radius * 10) / 10;
ShowManager.get(player).setSlope(radius);
player.sendMessage(BauSystem.PREFIX + "§aAnzeige Distanz auf " + ShowManager.get(player).slopeHeight + " gesetzt");
return false;
} catch (NumberFormatException e) {
return true;
}
case "hide":
showStatus.hide();
if (args.length == 2) {
return traceID(player, args[1], showStatus::removeSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"});
}
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen versteckt");
break;
case "toggleshow":
if (args.length == 2) {
return traceID(player, args[1], showStatus::toggleSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"}, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} versteckt"});
}
return true;
case "interpolate":
if (args.length == 2) {
return tracerInterpolate(player, showStatus, args);
}
return true;
default:
break;
}
return false;
}
private static boolean tracerShow(Player player, ShowStatus showStatus, String[] args) {
switch (args[1].toLowerCase()) {
case "block":
case "blocks":
showStatus.displayType = DisplayType.Block;
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Blöcke, angezeigt");
break;
case "particle":
case "particles":
case "default":
showStatus.displayType = DisplayType.Particle;
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Partikel, angezeigt");
break;
default:
return traceID(player, args[1], showStatus::addSelection, new String[]{BauSystem.PREFIX + "§aTNT-Positionen des TNT mit ID {} angezeigt"});
}
return false;
}
private static boolean tracerInterpolate(Player player, ShowStatus showStatus, String[] args) {
switch (args[1].toLowerCase()) {
case "none":
showStatus.displayMode = DisplayMode.NONE;
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt");
break;
case "yaxis":
case "y":
showStatus.displayMode = DisplayMode.Y_AXIS;
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt");
break;
case "all":
case "allaxis":
case "xyz":
case "default":
showStatus.displayMode = DisplayMode.ALL;
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt");
break;
default:
return true;
}
return false;
}
private interface Mode {
void run(int tntID);
}
private interface ModeChoose {
boolean run(int tntID);
}
private static boolean traceID(Player player, String number, Mode mode, String[] messages) {
try {
mode.run(Integer.parseInt(number));
for (String s : messages) {
player.sendMessage(s.replace("{}", number));
}
} catch (NumberFormatException e) {
return true;
}
return false;
}
private static boolean traceID(Player player, String number, ModeChoose mode, String[] messagesTrue, String[] messagesFalse) {
try {
boolean result = mode.run(Integer.parseInt(number));
if (result) {
for (String s : messagesTrue) {
player.sendMessage(s.replace("{}", number));
}
} else {
for (String s : messagesFalse) {
player.sendMessage(s.replace("{}", number));
}
}
} catch (NumberFormatException e) {
return true;
}
return false;
}
public static class ShowStatus {
private ShowSelection showSelection = ShowSelection.NONE;
private DisplayType displayType = DisplayType.Particle;
private DisplayMode displayMode = DisplayMode.ALL;
private boolean dirty = true;
private int count = 0;
private LinkedList<Integer> selected = new LinkedList<>();
private void clear() {
if (showSelection == ShowSelection.NONE) return;
selected.clear();
}
public void show() {
showSelection = ShowSelection.ALL;
}
public void hide() {
clear();
showSelection = ShowSelection.NONE;
}
public void addSelection(int id) {
if (showSelection == ShowSelection.ALL) return;
if (showSelection == ShowSelection.NONE) showSelection = ShowSelection.SELECTIVE;
selected.addAll(FrameManager.get(id));
if (selected.size() == TraceManager.get().size()) {
showSelection = ShowSelection.ALL;
clear();
}
}
public void removeSelection(int id) {
if (showSelection == ShowSelection.NONE) return;
if (showSelection == ShowSelection.ALL) selected = TraceManager.get();
selected.removeAll(FrameManager.get(id));
showSelection = ShowSelection.SELECTIVE;
if (selected.isEmpty()) showSelection = ShowSelection.NONE;
}
public boolean toggleSelection(int id) {
if (showSelection == ShowSelection.NONE) {
addSelection(id);
return true;
}
if (showSelection == ShowSelection.ALL) {
removeSelection(id);
return false;
}
if (selected.contains(id)) {
removeSelection(id);
return false;
} else {
addSelection(id);
return true;
}
}
public DisplayType getDisplayType() {
return displayType;
}
public DisplayMode getDisplayMode() {
return displayMode;
}
public LinkedList<TNTTrace> getTraces() {
if (showSelection == ShowSelection.NONE) return new LinkedList<>();
LinkedList<Integer> tntIDs;
if (showSelection == ShowSelection.ALL) {
tntIDs = TraceManager.get();
} else {
tntIDs = selected;
}
LinkedList<TNTTrace> traces = new LinkedList<>();
Iterator<Integer> iterator = tntIDs.descendingIterator();
while (iterator.hasNext()) {
TNTTrace trace = TraceManager.get(iterator.next());
if (trace == null) continue;
traces.add(trace);
}
return traces;
}
public boolean isDirty() {
if (displayType == DisplayType.Block) {
count++;
}
if (count >= 10) {
count = 0;
return true;
}
if (dirty) {
dirty = false;
return true;
}
return false;
}
private static double maxRadius = 80.0;
private static double minRadius = 20.0;
private static double minSlope = 3.0;
private static double maxSlope = 11.0;
private double slopeHeight = 7.0;
private int size = 0;
private TraceCache.Loc loc = null;
public double getShowRadius() {
if (showSelection == ShowSelection.NONE) return maxRadius;
if (showSelection == ShowSelection.ALL) size = TraceManager.get().size();
if (showSelection == ShowSelection.SELECTIVE) size = selected.size();
if (size == 0) return maxRadius;
if (size >= 525) return minRadius;
double slope = -(size / slopeHeight) + 85;
return Math.min(Math.max(slope, minRadius), maxRadius);
}
public void setSlope(double slope) {
slopeHeight = Math.min(Math.max(slope, minSlope), maxSlope);
}
public void move(Player player) {
if (loc != null && !loc.remove(player, 4)) {
return;
}
Location location = player.getLocation();
loc = new TraceCache.Loc((float) location.getX(), (float) location.getY(), (float) location.getZ());
dirty = true;
}
}
private static Map<String, ShowStatus> showMap = new HashMap<>();
public static void add(Player p) {
showMap.put(p.getUniqueId().toString(), new ShowStatus());
}
public static ShowStatus get(Player p) {
if (!showMap.containsKey(p.getUniqueId().toString())) add(p);
return showMap.get(p.getUniqueId().toString());
}
public static void traceAdd() {
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
if (entry.getValue().showSelection == ShowSelection.ALL) {
entry.getValue().dirty = true;
}
}
}
public static void traceRemove(int id) {
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
if (entry.getValue().showSelection == ShowSelection.ALL) {
entry.getValue().dirty = true;
}
if (entry.getValue().showSelection == ShowSelection.SELECTIVE) {
entry.getValue().dirty = true;
entry.getValue().removeSelection(id);
}
}
}
}

Datei anzeigen

@ -0,0 +1,33 @@
package de.steamwar.bausystem.tracer.manager;
import de.steamwar.bausystem.tracer.trace.TNTTrace;
import org.bukkit.entity.TNTPrimed;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public class TNTManager {
private static Map<TNTPrimed, Integer> tntMap = new HashMap<>();
public static void explode(TNTPrimed tntPrimed) {
if (!tntMap.containsKey(tntPrimed)) return;
TraceManager.get(tntMap.get(tntPrimed)).cleanUp();
}
public static void add(Stream<TNTPrimed> tntPrimedStream, int frameID) {
tntPrimedStream.forEach(tnt -> {
TNTTrace trace;
if (!tntMap.containsKey(tnt)) {
trace = new TNTTrace(frameID);
TraceManager.add(trace);
tntMap.put(tnt, trace.getTntID());
} else {
trace = TraceManager.get(tntMap.get(tnt));
}
trace.addLocation(tnt.getLocation());
});
}
}

Datei anzeigen

@ -0,0 +1,59 @@
package de.steamwar.bausystem.tracer.manager;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.trace.TNTTrace;
import org.bukkit.entity.Player;
import java.util.*;
public class TraceManager {
private static Map<Integer, TNTTrace> traceMap = new HashMap<>();
public static void add(TNTTrace tntTrace) {
int id = IDManager.generateID();
tntTrace.setTntID(id);
FrameManager.add(tntTrace.getFrameID(), id);
traceMap.put(id, tntTrace);
}
public static void remove() {
Iterator<Integer> iterator = get().descendingIterator();
while (iterator.hasNext()) {
remove(iterator.next());
}
}
public static void remove(int id) {
if (!traceMap.containsKey(id)) {
return;
}
int frameID = traceMap.remove(id).getFrameID();
ShowManager.traceRemove(id);
FrameManager.remove(frameID, id);
}
public static TNTTrace get(int id) {
return traceMap.get(id);
}
public static LinkedList<Integer> get() {
return new LinkedList<>(traceMap.keySet());
}
public static boolean delete(Player player, String[] args) {
if (args.length == 2) {
try {
remove(Integer.parseInt(args[1]));
player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht");
return false;
} catch (NumberFormatException e) {
return true;
}
}
remove();
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
return false;
}
}

Datei anzeigen

@ -0,0 +1,141 @@
package de.steamwar.bausystem.tracer.recorder;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.manager.FrameManager;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import static de.steamwar.bausystem.tracer.recorder.TNTRecorder.*;
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);
}
public static void tracer(Player player, String[] args) {
switch (args[0].toLowerCase()) {
case "start":
start();
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
break;
case "stop":
stop();
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
break;
case "auto":
case "toggleauto":
toggleAuto();
if (status == Status.IDLE || status == Status.RECORD) {
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
} else {
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
}
break;
}
}
public static void toggleAuto() {
switch (status) {
case IDLE:
status = Status.IDLE_AUTO;
break;
case RECORD:
status = Status.RECORD_AUTO;
break;
case IDLE_AUTO:
status = Status.IDLE;
break;
case RECORD_AUTO:
status = Status.RECORD;
break;
default:
break;
}
}
public static Status getStatus() {
return status;
}
public static void start() {
if (activeFrameID != null) return;
status = Status.RECORD;
generateFrameID();
startRecording();
}
public static void startAuto() {
if (activeFrameID != null) {
update();
return;
}
status = Status.RECORD_AUTO;
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet")));
generateFrameID();
startRecording();
}
public static void updateAuto() {
if (activeFrameID == null) return;
update();
}
public static void stop() {
if (activeFrameID == null) return;
status = Status.IDLE;
stopRecording();
cleanUPFrameID();
}
static void stopAuto() {
if (activeFrameID == null) return;
status = Status.IDLE_AUTO;
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt")));
stopRecording();
cleanUPFrameID();
}
private static void generateFrameID() {
if (activeFrameID != null) return;;
activeFrameID = FrameManager.createFrame();
}
private static void cleanUPFrameID() {
if (activeFrameID == null) return;
FrameManager.cleanUp(activeFrameID);
activeFrameID = null;
}
public enum Status {
RECORD("§aan", true),
RECORD_AUTO("§aan", true),
IDLE("§caus", false),
IDLE_AUTO("§eauto", false);
String value;
boolean tracing;
Status(String value, boolean tracing) {
this.value = value;
this.tracing = tracing;
}
public String getValue() {
return value;
}
public boolean isTracing() {
return tracing;
}
}
}

Datei anzeigen

@ -0,0 +1,51 @@
package de.steamwar.bausystem.tracer.recorder;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.manager.TNTManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitTask;
import java.util.stream.Stream;
import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto;
public class TNTRecorder {
private static BukkitTask task = null;
public static long recordStart = System.currentTimeMillis();
public static long lastExplosion = System.currentTimeMillis();
static void update() {
if (task == null) return;
if (RecordManager.status != RecordManager.Status.RECORD_AUTO) return;
lastExplosion = System.currentTimeMillis();
}
static void startRecording() {
if (task != null) return;
recordStart = System.currentTimeMillis();
lastExplosion = System.currentTimeMillis();
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1);
run();
}
static void stopRecording() {
if (task == null) return;
task.cancel();
task = null;
}
private static void run() {
Stream<TNTPrimed> tntPrimedStream = RecordManager.world.getEntities()
.stream()
.filter(e -> e instanceof TNTPrimed)
.map(e -> (TNTPrimed)e);
TNTManager.add(tntPrimedStream, RecordManager.activeFrameID);
if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) {
stopAuto();
}
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package de.steamwar.bausystem.tracer.trace;
import de.steamwar.bausystem.tracer.TNTTracer15;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public class ShowManager {
private static Map<Player, ShowStatus> showMap = new HashMap<>();
public static void add(Player player) {
showMap.put(player, new ShowStatus(player));
TNTTracer15.worldInit();
}
public static void dirty() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (showMap.get(player).getShow() != ShowStatus.Show.NONE) {
showMap.get(player).dirty = true;
}
}
}
public static void remove(Player player) {
showMap.remove(player);
}
public static ShowStatus get(Player player) {
return showMap.get(player);
}
public static void removeTrace(int traceID) {
for (Map.Entry<Player, ShowStatus> entry : showMap.entrySet()) {
entry.getValue().removeSelection(traceID);
TNTTracer15.hideBlockTraces(entry.getKey());
}
}
public static void removeAllTraces() {
for (Map.Entry<Player, ShowStatus> entry : showMap.entrySet()) {
entry.getValue().clear();
TNTTracer15.hideBlockTraces(entry.getKey());
}
}
}

Datei anzeigen

@ -1,149 +0,0 @@
package de.steamwar.bausystem.tracer.trace;
import de.steamwar.bausystem.tracer.TNTTracer15;
import org.bukkit.entity.Player;
import java.util.Iterator;
import java.util.LinkedList;
public class ShowStatus {
private Show show = Show.NONE;
private UpdatePoints updatePoints = UpdatePoints.ALL;
private ShowMode showMode = ShowMode.PARTICLE;
private LinkedList<Integer> selected = new LinkedList<>();
private Player p;
boolean dirty = false;
public ShowStatus(Player p) {
this.p = p;
}
public enum Show {
NONE,
ALL,
SELECTIVE
}
public enum UpdatePoints {
NONE,
Y_AXIS,
ALL
}
public enum ShowMode {
BLOCK,
PARTICLE
}
public boolean toggleShow(int tntID) {
dirty = true;
if (show == Show.ALL) {
removeSelection(tntID);
return false;
}
Iterator<Integer> selection = selected.iterator();
while (selection.hasNext()) {
if (selection.next() == tntID) {
removeSelection(tntID);
return false;
}
}
addSelection(tntID);
return true;
}
public void show() {
dirty = true;
show = Show.ALL;
}
public void hide() {
dirty = true;
selected.clear();
TNTTracer15.hideBlockTraces(p);
show = Show.NONE;
}
public void addSelection(int uniqueID) {
dirty = true;
if (show == Show.ALL) return;
if (show == Show.NONE) {
show = Show.SELECTIVE;
}
selected.add(uniqueID);
if (selected.size() == TNTTracer15.allTraces().size()) {
show = Show.ALL;
selected.clear();
}
}
public void removeSelection(int uniqueID) {
dirty = true;
if (show == Show.NONE) return;
TNTTracer15.hideBlockTraces(p);
if (show == Show.ALL) {
selected = TNTTracer15.allTraces();
show = Show.SELECTIVE;
}
selected.remove((Integer) uniqueID);
if (selected.isEmpty()) {
show = Show.NONE;
}
}
public void clear() {
dirty = true;
if (show == Show.NONE) return;
selected.clear();
TNTTracer15.hideBlockTraces(p);
}
public Show getShow() {
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() {
return selected;
}
public boolean isDirty() {
if (dirty) {
dirty = false;
return true;
}
return false;
}
public void dirty() {
dirty = true;
}
@Override
public String toString() {
return "ShowStatus{" +
"status=" + show +
", selected=" + selected +
'}';
}
}

Datei anzeigen

@ -1,98 +0,0 @@
package de.steamwar.bausystem.tracer.trace;
import de.steamwar.bausystem.tracer.TNTTracer15;
import org.bukkit.entity.TNTPrimed;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.stream.Stream;
public class TNTFrame {
private static int uniqueIdentifierFrame = 0;
private static int uniqueIdentifier = 0;
private long startTime = System.currentTimeMillis();
private Map<Integer, TNTTrace> positions = new HashMap<>();
private Map<TNTPrimed, TNTTrace> aliveTNT = new HashMap<>();
private final TNTFrame instance = this;
private final int uniqueID = uniqueIdentifierFrame++;
public int getUniqueID() {
return uniqueID;
}
public void add(Stream<TNTPrimed> tntPrimedStream) {
if (aliveTNT == null) return;
tntPrimedStream.forEach(tnt -> aliveTNT.computeIfAbsent(tnt, k -> {
synchronized (instance) {
TNTTrace trace = new TNTTrace(uniqueIdentifier);
positions.put(uniqueIdentifier, trace);
uniqueIdentifier++;
return trace;
}
}).addLocation(tnt.getLocation()));
}
public void explode(TNTPrimed tntPrimed) {
delete(tntPrimed);
}
void delete(TNTPrimed tntPrimed) {
delete(tntPrimed, true);
}
private void delete(TNTPrimed tntPrimed, boolean delete) {
if (aliveTNT == null) return;
TNTTrace tntTrace = aliveTNT.get(tntPrimed);
if (delete) {
aliveTNT.remove(tntPrimed);
}
if (TNTTracer15.isInWater(tntPrimed)) {
positions.remove(tntTrace.getUniqueID());
}
}
public void remove(int tntID) {
positions.remove(tntID);
}
public LinkedList<TNTTrace> getTraces(LinkedList<Integer> selection) {
LinkedList<TNTTrace> traces = new LinkedList<>();
Iterator<Integer> iterator = selection.iterator();
while (iterator.hasNext()) {
TNTTrace trace = positions.get(iterator.next());
if (trace != null) {
traces.add(trace);
}
}
return traces;
}
public LinkedList<TNTTrace> getTraces() {
LinkedList<TNTTrace> traces = new LinkedList<>();
for (Map.Entry<Integer, TNTTrace> entry : positions.entrySet()) {
traces.add(entry.getValue());
}
return traces;
}
public boolean finish() {
for (Map.Entry<TNTPrimed, TNTTrace> entry : aliveTNT.entrySet()) {
entry.getValue().cleanUp();
delete(entry.getKey(), false);
}
aliveTNT.clear();
aliveTNT = null;
return positions.isEmpty();
}
public long getStartTime() {
return startTime;
}
}

Datei anzeigen

@ -1,19 +1,28 @@
package de.steamwar.bausystem.tracer.trace;
import de.steamwar.bausystem.tracer.TraceCache;
import de.steamwar.bausystem.tracer.manager.ShowManager;
import org.bukkit.Location;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class TNTTrace {
private long startTime = System.currentTimeMillis();
private int uniqueID;
private final long startTime = System.currentTimeMillis();
private final int frameID;
private int tntID;
private int index = 0;
private float[] positions = new float[240];
public TNTTrace(int uniqueID) {
this.uniqueID = uniqueID;
private Set<TraceCache.Loc> posSet = new HashSet<>();
private Set<TraceCache.Loc> posYSet = new HashSet<>();
private Set<TraceCache.Loc> posXYZSet = new HashSet<>();
public TNTTrace(int frameID) {
this.frameID = frameID;
}
public void addLocation(Location location) {
@ -30,10 +39,6 @@ public class TNTTrace {
index += 3;
}
public float[] getPositions() {
return Arrays.copyOf(positions, positions.length);
}
public int size() {
return index / 3;
}
@ -50,12 +55,65 @@ public class TNTTrace {
return startTime;
}
public int getUniqueID() {
return uniqueID;
public void setTntID(int tntID) {
this.tntID = tntID;
}
void cleanUp() {
positions = Arrays.copyOf(positions, index);
public int getTntID() {
return tntID;
}
public int getFrameID() {
return frameID;
}
public void cleanUp() {
positions = Arrays.copyOf(positions, index);
ShowManager.traceAdd();
for (int i = 0; i < length(); i++) {
posSet.add(new TraceCache.Loc(positions[i * 3 + 0], positions[i * 3 + 1], positions[i * 3 + 2]));
}
for (int i = 0; i < realLength() - 3; i += 3) {
float x1 = positions[i + 0];
float y1 = positions[i + 1];
float z1 = positions[i + 2];
float x2 = positions[i + 3];
float y2 = positions[i + 4];
float z2 = positions[i + 5];
if (!isEqual(y2, y1)) {
TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1);
posYSet.add(loc);
posXYZSet.add(loc);
}
if (abs(x2 - x1) > abs(z2 - z1)) {
if (!isEqual(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1));
} else {
if (!isEqual(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2));
}
}
}
public Set<TraceCache.Loc> locs() {
return posSet;
}
public Set<TraceCache.Loc> locsUpdate(ShowManager.DisplayMode displayMode) {
if (displayMode == ShowManager.DisplayMode.NONE) return new HashSet<>();
if (displayMode == ShowManager.DisplayMode.Y_AXIS) return posYSet;
return posXYZSet;
}
private static boolean isEqual(float d1, float d2) {
return (d2 - d1) * (d2 - d1) < 0.01;
}
private static float abs(float x) {
return x < 0 ? -x : x;
}
}

Datei anzeigen

@ -3,8 +3,8 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.commands.CommandFreeze;
import de.steamwar.bausystem.commands.CommandInfo;
import de.steamwar.bausystem.commands.CommandTNT;
import de.steamwar.bausystem.tracer.TNTTracer15;
import de.steamwar.core.Core;
import de.steamwar.bausystem.tracer.TraceSidebar;
import de.steamwar.bausystem.tracer.recorder.RecordManager;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;
import org.bukkit.entity.Player;
@ -24,20 +24,7 @@ public class BauScoreboard implements Listener {
SWScoreboard.createScoreboard(player, new ScoreboardCallback() {
@Override
public HashMap<String, Integer> getData() {
HashMap<String, Integer> data = new HashMap<>();
switch (Core.getVersion()) {
case 15:
render(getSidebar_15(), data);
break;
case 12:
render(getSidebar_12(), data);
break;
default:
break;
}
return data;
return render(sidebar(player));
}
@Override
@ -47,30 +34,32 @@ public class BauScoreboard implements Listener {
});
}
private void render(List<String> strings, HashMap<String, Integer> data) {
private HashMap<String, Integer> render(List<String> strings) {
HashMap<String, Integer> data = new HashMap<>();
String[] elements = strings.toArray(new String[0]);
for (int i = elements.length - 1; i >= 0; i--) {
data.put(elements[i], elements.length - i - 1);
}
return data;
}
private List<String> getSidebar_15() {
private List<String> sidebar(Player p) {
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("§eTrace§8: " + RecordManager.getStatus().getValue());
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§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) {
if (RecordManager.getStatus().isTracing()) {
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("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TraceSidebar.traceStart())));
strings.add("§eTicks§8: §7" + TraceSidebar.traceTicks());
strings.add("§eAnzahl TNT§8: §7" + TraceSidebar.traceSize());
} else if (AutoLoader.hasLoader(p)) {
// strings.add("§3");
}
strings.add("§4");
@ -78,16 +67,4 @@ public class BauScoreboard implements Listener {
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;
}
}