Merge pull request 'Simplify Tracer' (#91) from simplify-tracer into master
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
b800c3f197
@ -1,95 +1,11 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.material.Step;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static de.steamwar.bausystem.tracer.TraceUtils.actionBar;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class TNTTracer_12 {
|
||||
|
||||
private TNTTracer_12(){}
|
||||
|
||||
private static TracerUpdater tracerUpdater;
|
||||
private static TraceCache traceCache = new TraceCache();
|
||||
|
||||
private static class Synchronizer {}
|
||||
private static final Synchronizer synchronizer = new Synchronizer();
|
||||
|
||||
private static World world;
|
||||
static void worldInit() {
|
||||
if (world != null) return;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
static Material getMaterial(){
|
||||
return Material.STAINED_GLASS;
|
||||
}
|
||||
|
||||
static void init(Plugin plugin, TracerUpdater tracerUpdater) {
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
synchronized (synchronizer) {
|
||||
synchronizer.notifyAll();
|
||||
}
|
||||
}, 1, 20);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
while (true) {
|
||||
synchronized (synchronizer) {
|
||||
try {
|
||||
synchronizer.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
TNTTracer_12.tracerUpdater = tracerUpdater;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (actionBar) {
|
||||
String actionBar = tracerUpdater.actionBar(p);
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||
}
|
||||
|
||||
boolean dirty = tracerUpdater.needsUpdate(p);
|
||||
if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, tracerUpdater, dirty);
|
||||
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
||||
|
||||
hideBlockTraces(toHide, p);
|
||||
showTraces(toShow, tracerUpdater.getDisplayType(p), p);
|
||||
}
|
||||
}
|
||||
|
||||
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
TraceUtils.hideBlock(player, l.x, l.y - 0.49F, l.z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showTraces(Set<TraceCache.Loc> locs, TracerUpdater.DisplayMode displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == TracerUpdater.DisplayMode.Block) {
|
||||
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, Material.STAINED_GLASS, (l.updatePoint ? (byte) 5 : (byte) 14));
|
||||
} else {
|
||||
TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,94 +1,11 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static de.steamwar.bausystem.tracer.TraceUtils.actionBar;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class TNTTracer_15 {
|
||||
|
||||
private TNTTracer_15(){}
|
||||
|
||||
private static TracerUpdater tracerUpdater;
|
||||
private static TraceCache traceCache = new TraceCache();
|
||||
|
||||
private static class Synchronizer {}
|
||||
private static final Synchronizer synchronizer = new Synchronizer();
|
||||
|
||||
private static World world;
|
||||
static void worldInit() {
|
||||
if (world != null) return;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
static Material getMaterial(boolean updatePoint){
|
||||
return updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS;
|
||||
}
|
||||
|
||||
static void init(Plugin plugin, TracerUpdater tracerUpdater) {
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
synchronized (synchronizer) {
|
||||
synchronizer.notifyAll();
|
||||
}
|
||||
}, 1, 20);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
while (true) {
|
||||
synchronized (synchronizer) {
|
||||
try {
|
||||
synchronizer.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
run();
|
||||
}
|
||||
});
|
||||
|
||||
TNTTracer_15.tracerUpdater = tracerUpdater;
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (actionBar) {
|
||||
String actionBar = tracerUpdater.actionBar(p);
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||
}
|
||||
|
||||
boolean dirty = tracerUpdater.needsUpdate(p);
|
||||
if (tracerUpdater.getDisplayType(p) == TracerUpdater.DisplayMode.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, tracerUpdater, dirty);
|
||||
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
||||
|
||||
hideBlockTraces(toHide, p);
|
||||
showTraces(toShow, tracerUpdater.getDisplayType(p), p);
|
||||
}
|
||||
}
|
||||
|
||||
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
TraceUtils.hideBlock(player, l.x, l.y - 0.49F, l.z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showTraces(Set<TraceCache.Loc> locs, TracerUpdater.DisplayMode displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == TracerUpdater.DisplayMode.Block) {
|
||||
TraceUtils.showBlock(player, l.x, l.y - 0.49F, l.z, (l.updatePoint ? Material.LIME_STAINED_GLASS : Material.RED_STAINED_GLASS), (l.updatePoint ? (byte) 5 : (byte) 14));
|
||||
} else {
|
||||
TraceUtils.showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
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 boolean actionBar = false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
public class TracerGuiUpdater {
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
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);
|
||||
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
package de.steamwar.bausystem;
|
||||
|
||||
import de.steamwar.bausystem.commands.*;
|
||||
import de.steamwar.bausystem.tracer.MoveEvent;
|
||||
import de.steamwar.bausystem.tracer.TNTListener;
|
||||
import de.steamwar.bausystem.tracer.TraceListener;
|
||||
import de.steamwar.bausystem.tracer.TNTTracer;
|
||||
import de.steamwar.bausystem.tracer.TraceUtils;
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.ShowManager;
|
||||
import de.steamwar.bausystem.world.AFKStopper;
|
||||
import de.steamwar.bausystem.world.ArenaSection;
|
||||
import de.steamwar.bausystem.world.BauScoreboard;
|
||||
@ -104,15 +101,10 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TNTListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new MoveEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TraceListener(), this);
|
||||
new AFKStopper();
|
||||
if (Core.getVersion() == 15) {
|
||||
TNTTracer.init15();
|
||||
} else {
|
||||
TNTTracer.init12();
|
||||
}
|
||||
TNTTracer.init();
|
||||
|
||||
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
||||
}
|
||||
@ -277,16 +269,10 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
attachment.setPermission("worldedit.calc", true);
|
||||
attachment.setPermission("worldedit.fill", true);*/
|
||||
|
||||
RecordManager.worldInit();
|
||||
TNTTracer.worldInit();
|
||||
TraceUtils.locationInit();
|
||||
|
||||
ShowManager.add(p);
|
||||
|
||||
if (Core.getVersion() == 15){
|
||||
ShowManager.add(p);
|
||||
if (Core.getVersion() == 15)
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -301,8 +287,9 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
ItemStack stack = e.getCursor();
|
||||
if (stack == null) return;
|
||||
if (!stack.hasItemMeta()) return;
|
||||
if (stack == null || !stack.hasItemMeta())
|
||||
return;
|
||||
assert stack.getItemMeta() != null;
|
||||
if (stack.getItemMeta().hasEnchants()) {
|
||||
for (Enchantment en : Enchantment.values()) {
|
||||
if (stack.getEnchantmentLevel(en) > en.getMaxLevel())
|
||||
|
@ -2,8 +2,8 @@ package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.manager.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.ShowManager;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import org.bukkit.command.Command;
|
||||
@ -28,12 +28,6 @@ public class CommandTrace implements CommandExecutor {
|
||||
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;
|
||||
return tracer((Player) sender, args);
|
||||
}
|
||||
|
||||
private boolean permissionCheck(Player player) {
|
||||
if(Welt.noPermission(player, Permission.world)){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TNT-Tracer nutzen");
|
||||
@ -42,7 +36,11 @@ public class CommandTrace implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean tracer(Player player, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(args.length == 0){
|
||||
help(player);
|
||||
return false;
|
||||
@ -62,7 +60,7 @@ public class CommandTrace implements CommandExecutor {
|
||||
case "toggleshow":
|
||||
case "interpolate":
|
||||
case "distance":
|
||||
if (ShowManager.tracer(player, args)) {
|
||||
if (tracer(player, args)) {
|
||||
help(player);
|
||||
}
|
||||
break;
|
||||
@ -71,7 +69,7 @@ public class CommandTrace implements CommandExecutor {
|
||||
// player.sendMessage(BauSystem.PREFIX + "§cNoch in Bau");
|
||||
break;
|
||||
case "delete":
|
||||
if (TraceManager.delete(player, args)) {
|
||||
if (delete(player, args)) {
|
||||
help(player);
|
||||
}
|
||||
break;
|
||||
@ -81,4 +79,147 @@ public class CommandTrace implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean delete(Player player, String[] args) {
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
TraceManager.delete(Integer.parseInt(args[1]));
|
||||
player.sendMessage(BauSystem.PREFIX + "§cTNT-Positionen mit ID " + args[1] + " gelöscht");
|
||||
ShowManager.globalDirty();
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TraceManager.deleteAll();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
||||
ShowManager.globalDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean tracer(Player player, String[] args) {
|
||||
ShowManager.ShowStatus showStatus = ShowManager.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 boolean tracerShow(Player player, ShowManager.ShowStatus showStatus, String[] args) {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "block":
|
||||
case "blocks":
|
||||
showStatus.displayType = ShowManager.DisplayType.Block;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen, als Blöcke, angezeigt");
|
||||
break;
|
||||
case "particle":
|
||||
case "particles":
|
||||
case "default":
|
||||
showStatus.displayType = ShowManager.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 boolean tracerInterpolate(Player player, ShowManager.ShowStatus showStatus, String[] args) {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "none":
|
||||
showStatus.displayMode = ShowManager.DisplayMode.NONE;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §enone §agesetzt");
|
||||
break;
|
||||
case "yaxis":
|
||||
case "y":
|
||||
showStatus.displayMode = ShowManager.DisplayMode.Y_AXIS;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eyaxis §agesetzt");
|
||||
break;
|
||||
case "all":
|
||||
case "allaxis":
|
||||
case "xyz":
|
||||
case "default":
|
||||
showStatus.displayMode = ShowManager.DisplayMode.ALL;
|
||||
player.sendMessage(BauSystem.PREFIX + "§aInterpolation auf §eall §agesetzt");
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean traceID(Player player, String number, ShowManager.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 boolean traceID(Player player, String number, ShowManager.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;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.manager.ShowManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class MoveEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
ShowManager.get(p).move(p);
|
||||
}
|
||||
|
||||
}
|
206
BauSystem_Main/src/de/steamwar/bausystem/tracer/ShowManager.java
Normale Datei
206
BauSystem_Main/src/de/steamwar/bausystem/tracer/ShowManager.java
Normale Datei
@ -0,0 +1,206 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ShowManager {
|
||||
|
||||
public enum DisplayMode {
|
||||
NONE,
|
||||
Y_AXIS,
|
||||
ALL
|
||||
}
|
||||
|
||||
public enum DisplayType {
|
||||
Particle,
|
||||
Block
|
||||
}
|
||||
|
||||
public enum ShowSelection {
|
||||
NONE,
|
||||
SELECTIVE,
|
||||
ALL
|
||||
}
|
||||
|
||||
|
||||
public interface Mode {
|
||||
void run(int tntID);
|
||||
}
|
||||
|
||||
public interface ModeChoose {
|
||||
boolean run(int tntID);
|
||||
}
|
||||
|
||||
|
||||
public static class ShowStatus {
|
||||
|
||||
private ShowSelection showSelection = ShowSelection.NONE;
|
||||
public DisplayType displayType = DisplayType.Particle;
|
||||
public DisplayMode displayMode = DisplayMode.ALL;
|
||||
|
||||
public boolean dirty = true;
|
||||
private int count = 0;
|
||||
|
||||
private Set<Integer> selected = new HashSet<>();
|
||||
|
||||
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(TraceManager.getFrame(id));
|
||||
if (selected.size() == TraceManager.getAllTraces().size()) {
|
||||
showSelection = ShowSelection.ALL;
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSelection(int id) {
|
||||
if (showSelection == ShowSelection.NONE) return;
|
||||
if (showSelection == ShowSelection.ALL) selected = TraceManager.getAllTraces();
|
||||
selected.removeAll(TraceManager.getFrame(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<>();
|
||||
Set<Integer> tntIDs;
|
||||
if (showSelection == ShowSelection.ALL) {
|
||||
tntIDs = TraceManager.getAllTraces();
|
||||
} else {
|
||||
tntIDs = selected;
|
||||
}
|
||||
|
||||
LinkedList<TNTTrace> traces = new LinkedList<>();
|
||||
for (int traceId : tntIDs) {
|
||||
TNTTrace trace = TraceManager.getTrace(traceId);
|
||||
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;
|
||||
}
|
||||
|
||||
public double slopeHeight = 7.0;
|
||||
|
||||
private int size = 0;
|
||||
|
||||
private TraceCache.Loc loc = null;
|
||||
|
||||
public double getShowRadius() {
|
||||
double maxRadius = 80.0;
|
||||
if (showSelection == ShowSelection.NONE) return maxRadius;
|
||||
if (showSelection == ShowSelection.ALL) size = TraceManager.getAllTraces().size();
|
||||
if (showSelection == ShowSelection.SELECTIVE) size = selected.size();
|
||||
if (size == 0) return maxRadius;
|
||||
double minRadius = 20.0;
|
||||
if (size >= 950) return minRadius;
|
||||
|
||||
double slope = -(size / slopeHeight) + 85;
|
||||
return Math.min(Math.max(slope, minRadius), maxRadius);
|
||||
}
|
||||
|
||||
public void setSlope(double slope) {
|
||||
double minSlope = 3.0;
|
||||
double maxSlope = 11.0;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public 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()) {
|
||||
entry.getValue().removeSelection(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void globalDirty() {
|
||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||
entry.getValue().dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.manager.TNTManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class TNTListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
|
||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO) {
|
||||
RecordManager.startAuto();
|
||||
}
|
||||
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO) {
|
||||
RecordManager.updateAuto();
|
||||
}
|
||||
|
||||
TNTManager.explode((TNTPrimed) event.getEntity());
|
||||
}
|
||||
|
||||
/*private void onEntityExplode12(EntityExplodeEvent event) {
|
||||
if(TNTTracer12.getStatus() != TNTTracer12.Status.RECORD) return;
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
TNTPrimed entity = (TNTPrimed) event.getEntity();
|
||||
TNTTracer12.remove(entity);
|
||||
}
|
||||
|
||||
private void onEntityExplode15(EntityExplodeEvent event) {
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
if (TraceRecorder.getStatus() == TraceRecorder.Status.IDLE_AUTO || TraceRecorder.getStatus() == TraceRecorder.Status.RECORD_AUTO) {
|
||||
TraceRecorder.start();
|
||||
}
|
||||
TraceRecorder.explode((TNTPrimed) event.getEntity());
|
||||
}*/
|
||||
}
|
93
BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTrace.java
Normale Datei
93
BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTTrace.java
Normale Datei
@ -0,0 +1,93 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TNTTrace {
|
||||
|
||||
private final int frameID;
|
||||
|
||||
private int index = 0;
|
||||
private float[] positions = new float[240];
|
||||
|
||||
private Set<TraceCache.Loc> posSet = new HashSet<>();
|
||||
private Set<TraceCache.Loc> posYSet = new HashSet<>();
|
||||
private Set<TraceCache.Loc> posXYZSet = new HashSet<>();
|
||||
|
||||
TNTTrace(int frameID) {
|
||||
this.frameID = frameID;
|
||||
}
|
||||
|
||||
void addLocation(Location location) {
|
||||
if (index >= positions.length) {
|
||||
positions = Arrays.copyOf(positions, positions.length + 3);
|
||||
}
|
||||
positions[index] = (float)location.getX();
|
||||
positions[index + 1] = (float)location.getY();
|
||||
positions[index + 2] = (float)location.getZ();
|
||||
index += 3;
|
||||
}
|
||||
|
||||
private int size() {
|
||||
return index / 3;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return size();
|
||||
}
|
||||
|
||||
private int realLength() {
|
||||
return positions.length;
|
||||
}
|
||||
|
||||
int getFrameID() {
|
||||
return frameID;
|
||||
}
|
||||
|
||||
void cleanUp() {
|
||||
positions = Arrays.copyOf(positions, index);
|
||||
ShowManager.traceAdd();
|
||||
|
||||
for (int i = 0; i < length(); i++) {
|
||||
posSet.add(new TraceCache.Loc(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < realLength() - 3; i += 3) {
|
||||
float x1 = positions[i];
|
||||
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 (isDifferent(y2, y1)) {
|
||||
TraceCache.Loc loc = new TraceCache.Loc(x1, y2, z1);
|
||||
posYSet.add(loc);
|
||||
posXYZSet.add(loc);
|
||||
}
|
||||
if (Math.abs(x2 - x1) > Math.abs(z2 - z1)) {
|
||||
if (isDifferent(x2, x1)) posXYZSet.add(new TraceCache.Loc(x2, y2, z1));
|
||||
} else {
|
||||
if (isDifferent(z2, z1)) posXYZSet.add(new TraceCache.Loc(x1, y2, z2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<TraceCache.Loc> locs() {
|
||||
return posSet;
|
||||
}
|
||||
|
||||
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 isDifferent(float d1, float d2) {
|
||||
return (d2 - d1) * (d2 - d1) >= 0.01;
|
||||
}
|
||||
}
|
@ -1,83 +1,122 @@
|
||||
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 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.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class TNTTracer {
|
||||
private 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());
|
||||
static final boolean DEBUG = false;
|
||||
|
||||
private static final Object synchronizer = new Object();
|
||||
private static final TraceCache traceCache = new TraceCache();
|
||||
|
||||
public static void init(){
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||
synchronized (synchronizer) {
|
||||
synchronizer.notifyAll();
|
||||
}
|
||||
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()));
|
||||
}, 1, 20);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(BauSystem.getPlugin(), () -> {
|
||||
while (true) {
|
||||
synchronized (synchronizer) {
|
||||
try {
|
||||
synchronizer.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
run();
|
||||
}
|
||||
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);
|
||||
private static void run(){
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (DEBUG) {
|
||||
String actionBar = "§e" + TraceManager.getAllTraces().size() + " §cTraces §e" + ShowManager.get(p).getShowRadius() + " §cRadius";
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBar));
|
||||
}
|
||||
|
||||
boolean dirty = ShowManager.get(p).isDirty();
|
||||
if (ShowManager.get(p).getDisplayType() == ShowManager.DisplayType.Block && !dirty) {
|
||||
continue;
|
||||
}
|
||||
Set<TraceCache.Loc> toHide = traceCache.update(p, dirty);
|
||||
Set<TraceCache.Loc> toShow = traceCache.get(p);
|
||||
|
||||
hideBlockTraces(toHide, p);
|
||||
showTraces(toShow, ShowManager.get(p).getDisplayType(), p);
|
||||
}
|
||||
}
|
||||
|
||||
public static void worldInit() {
|
||||
switch (Core.getVersion()) {
|
||||
private static void hideBlockTraces(Set<TraceCache.Loc> locs, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
hideBlock(player, l.x, l.y - 0.49F, l.z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showTraces(Set<TraceCache.Loc> locs, ShowManager.DisplayType displayMode, Player player) {
|
||||
if (locs.isEmpty()) return;
|
||||
|
||||
for (TraceCache.Loc l : locs) {
|
||||
if (displayMode == ShowManager.DisplayType.Block) {
|
||||
showBlock(player, l.x, l.y - 0.49F, l.z, getMaterial(l), (l.updatePoint ? (byte) 5 : (byte) 14));
|
||||
} else {
|
||||
showCorner(player, l.x - 0.49F, l.y, l.z - 0.49F, (l.updatePoint ? Particle.FLAME : Particle.VILLAGER_HAPPY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Material getMaterial(TraceCache.Loc l){
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
TNTTracer_15.worldInit();
|
||||
break;
|
||||
return TNTTracer_15.getMaterial(l.updatePoint);
|
||||
default:
|
||||
TNTTracer_12.worldInit();
|
||||
break;
|
||||
return TNTTracer_12.getMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
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 final Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
private static Location makeLocation(float x, float y, float z) {
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
public class TNTTracerGUI_15 {
|
||||
public class TNTTracerGUI {
|
||||
|
||||
/*private static GuiCallbackTNTFrame guiCallbackTNTFrame;
|
||||
private static GuiCallbackTNTTrace guiCallbackTNTTrace;
|
@ -1,52 +0,0 @@
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
@ -6,56 +6,56 @@ import java.util.*;
|
||||
|
||||
public class TraceCache {
|
||||
|
||||
private static final Set<Loc> empty = new HashSet();
|
||||
private static final Set<Loc> empty = new HashSet<>();
|
||||
private Map<String, Set<Loc>> playerMap = new HashMap<>();
|
||||
private Map<String, TracerUpdater.DisplayMode> playerDisplayMap = new HashMap<>();
|
||||
private Map<String, ShowManager.DisplayType> 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) {
|
||||
Set<Loc> update(Player player, boolean dirty) {
|
||||
if (!dirty) return empty;
|
||||
String key = player.getUniqueId().toString();
|
||||
Set<Loc> locOld;
|
||||
TracerUpdater.DisplayMode displayMode;
|
||||
ShowManager.DisplayType displayMode;
|
||||
if (!playerMap.containsKey(key)) {
|
||||
locOld = new HashSet<>();
|
||||
displayMode = tracerUpdater.getDisplayType(player);
|
||||
displayMode = getDisplayType(player);
|
||||
} else {
|
||||
locOld = playerMap.get(key);
|
||||
displayMode = playerDisplayMap.get(key);
|
||||
}
|
||||
|
||||
Set<Loc> locSet = new HashSet<>();
|
||||
tracerUpdater.updatePoints(player).forEach(loc -> {
|
||||
updatePoints(player).forEach(loc -> {
|
||||
loc.updatePoint = true;
|
||||
locSet.add(loc);
|
||||
});
|
||||
tracerUpdater.updateLocations(player).forEach(loc -> {
|
||||
updateLocations(player).forEach(loc -> {
|
||||
loc.updatePoint = false;
|
||||
locSet.add(loc);
|
||||
});
|
||||
|
||||
playerMap.put(key, locSet);
|
||||
TracerUpdater.DisplayMode currentMode = tracerUpdater.getDisplayType(player);
|
||||
ShowManager.DisplayType currentMode = 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);
|
||||
if (currentMode == ShowManager.DisplayType.Particle && displayMode == ShowManager.DisplayType.Block) return locOld;
|
||||
if (currentMode == ShowManager.DisplayType.Block) return diff(locOld, locSet);
|
||||
return empty;
|
||||
}
|
||||
|
||||
public static class Loc {
|
||||
public final float x;
|
||||
public final float y;
|
||||
public final float z;
|
||||
final float x;
|
||||
final float y;
|
||||
final float z;
|
||||
|
||||
private final float dx;
|
||||
private final float dy;
|
||||
private final float dz;
|
||||
|
||||
public boolean updatePoint = false;
|
||||
boolean updatePoint = false;
|
||||
|
||||
public Loc(float x, float y, float z) {
|
||||
this.x = x;
|
||||
@ -66,8 +66,8 @@ public class TraceCache {
|
||||
this.dz = round(z);
|
||||
}
|
||||
|
||||
private static int roundNumber = 10;
|
||||
private static float round(float toRound) {
|
||||
final int roundNumber = 10;
|
||||
float r = (toRound * roundNumber);
|
||||
float t = r - (int) r;
|
||||
if (t >= 0.5) {
|
||||
@ -123,4 +123,29 @@ public class TraceCache {
|
||||
return locOld;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private ShowManager.DisplayType getDisplayType(Player player) {
|
||||
return ShowManager.get(player).getDisplayType();
|
||||
}
|
||||
}
|
53
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java
Normale Datei
53
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceListener.java
Normale Datei
@ -0,0 +1,53 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TraceListener implements Listener {
|
||||
|
||||
private static final Map<TNTPrimed, TNTTrace> tntMap = new HashMap<>();
|
||||
|
||||
public static void onTick(Stream<TNTPrimed> tntPrimedStream) {
|
||||
tntPrimedStream.forEach(tnt -> {
|
||||
TNTTrace trace;
|
||||
if (!tntMap.containsKey(tnt)) {
|
||||
trace = TraceManager.createTrace();
|
||||
tntMap.put(tnt, trace);
|
||||
} else {
|
||||
trace = tntMap.get(tnt);
|
||||
}
|
||||
trace.addLocation(tnt.getLocation());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed))
|
||||
return;
|
||||
|
||||
if (RecordManager.getStatus() == RecordManager.Status.IDLE_AUTO)
|
||||
RecordManager.startAuto();
|
||||
if (RecordManager.getStatus() == RecordManager.Status.RECORD_AUTO)
|
||||
RecordManager.updateAuto();
|
||||
|
||||
TNTTrace trace = tntMap.remove((TNTPrimed) event.getEntity());
|
||||
if (trace != null)
|
||||
trace.cleanUp();
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
ShowManager.get(p).move(p);
|
||||
}
|
||||
}
|
80
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java
Normale Datei
80
BauSystem_Main/src/de/steamwar/bausystem/tracer/TraceManager.java
Normale Datei
@ -0,0 +1,80 @@
|
||||
package de.steamwar.bausystem.tracer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TraceManager {
|
||||
private TraceManager(){}
|
||||
|
||||
private static Map<Integer, List<Integer>> frameMap = new HashMap<>();
|
||||
private static Map<Integer, TNTTrace> traceMap = new HashMap<>();
|
||||
|
||||
private static int currentFrame;
|
||||
|
||||
private static int currentID = 0;
|
||||
private static synchronized int generateID() {
|
||||
return currentID++;
|
||||
}
|
||||
|
||||
public static void startFrame() {
|
||||
currentFrame = generateID();
|
||||
frameMap.put(currentFrame, new ArrayList<>());
|
||||
}
|
||||
|
||||
public static TNTTrace createTrace() {
|
||||
TNTTrace trace = new TNTTrace(currentFrame);
|
||||
int id = generateID();
|
||||
traceMap.put(id, trace);
|
||||
frameMap.get(currentFrame).add(id);
|
||||
return trace;
|
||||
}
|
||||
|
||||
public static TNTTrace getTrace(int id) {
|
||||
return traceMap.get(id);
|
||||
}
|
||||
|
||||
public static Set<Integer> getAllTraces() {
|
||||
return traceMap.keySet();
|
||||
}
|
||||
|
||||
public static List<Integer> getFrame(int frameID) {
|
||||
return new ArrayList<>(frameMap.getOrDefault(frameID, new ArrayList<>()));
|
||||
}
|
||||
|
||||
public static int currentFrameSize(){
|
||||
return frameMap.get(currentFrame).size();
|
||||
}
|
||||
|
||||
public static void stopFrame() {
|
||||
testRemoveFrame(currentFrame);
|
||||
}
|
||||
|
||||
private static void testRemoveFrame(int frame){
|
||||
if (!frameMap.containsKey(frame) || !frameMap.get(frame).isEmpty())
|
||||
return;
|
||||
frameMap.remove(frame);
|
||||
}
|
||||
|
||||
public static void deleteAll() {
|
||||
for (Integer integer : new HashSet<>(traceMap.keySet())) {
|
||||
delete(integer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void delete(int id) {
|
||||
TNTTrace trace = traceMap.remove(id);
|
||||
if(trace == null){
|
||||
List<Integer> frame = frameMap.get(id);
|
||||
if(frame == null)
|
||||
return;
|
||||
|
||||
for(int t : new HashSet<>(frame)){
|
||||
delete(t);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int frameID = trace.getFrameID();
|
||||
ShowManager.traceRemove(id);
|
||||
frameMap.get(frameID).remove((Integer) id);
|
||||
testRemoveFrame(frameID);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package de.steamwar.bausystem.tracer.manager;
|
||||
|
||||
public class IDManager {
|
||||
|
||||
private static int currentID = 0;
|
||||
|
||||
public static synchronized int generateID() {
|
||||
return currentID++;
|
||||
}
|
||||
|
||||
}
|
@ -1,336 +0,0 @@
|
||||
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 >= 950) 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()) {
|
||||
entry.getValue().removeSelection(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void globalDirty() {
|
||||
for (Map.Entry<String, ShowStatus> entry : showMap.entrySet()) {
|
||||
entry.getValue().dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
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());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
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");
|
||||
ShowManager.globalDirty();
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
remove();
|
||||
player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
|
||||
ShowManager.globalDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package de.steamwar.bausystem.tracer.recorder;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.manager.FrameManager;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -13,13 +13,8 @@ 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);
|
||||
}
|
||||
static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public static void tracer(Player player, String[] args) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
@ -43,7 +38,7 @@ public class RecordManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleAuto() {
|
||||
private static void toggleAuto() {
|
||||
switch (status) {
|
||||
case IDLE:
|
||||
status = Status.IDLE_AUTO;
|
||||
@ -66,53 +61,34 @@ public class RecordManager {
|
||||
return status;
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
if (activeFrameID != null) return;
|
||||
private static void start() {
|
||||
status = Status.RECORD;
|
||||
generateFrameID();
|
||||
TraceManager.startFrame();
|
||||
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();
|
||||
TraceManager.startFrame();
|
||||
startRecording();
|
||||
}
|
||||
|
||||
public static void updateAuto() {
|
||||
if (activeFrameID == null) return;
|
||||
update();
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
if (activeFrameID == null) return;
|
||||
private static void stop() {
|
||||
status = Status.IDLE;
|
||||
stopRecording();
|
||||
cleanUPFrameID();
|
||||
TraceManager.stopFrame();
|
||||
}
|
||||
|
||||
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;
|
||||
TraceManager.stopFrame();
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package de.steamwar.bausystem.tracer.recorder;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.manager.TNTManager;
|
||||
import de.steamwar.bausystem.tracer.TraceListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -41,7 +41,7 @@ public class TNTRecorder {
|
||||
.stream()
|
||||
.filter(e -> e instanceof TNTPrimed)
|
||||
.map(e -> (TNTPrimed)e);
|
||||
TNTManager.add(tntPrimedStream, RecordManager.activeFrameID);
|
||||
TraceListener.onTick(tntPrimedStream);
|
||||
|
||||
if (RecordManager.status == RecordManager.Status.RECORD_AUTO && System.currentTimeMillis() - lastExplosion > 4500) {
|
||||
stopAuto();
|
||||
|
@ -1,119 +0,0 @@
|
||||
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 final long startTime = System.currentTimeMillis();
|
||||
private final int frameID;
|
||||
private int tntID;
|
||||
|
||||
private int index = 0;
|
||||
private float[] positions = new float[240];
|
||||
|
||||
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) {
|
||||
addLocation(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public void addLocation(double x, double y, double z) {
|
||||
if (index >= positions.length) {
|
||||
positions = Arrays.copyOf(positions, positions.length + 240);
|
||||
}
|
||||
positions[index + 0] = (float)x;
|
||||
positions[index + 1] = (float)y;
|
||||
positions[index + 2] = (float)z;
|
||||
index += 3;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return index / 3;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return size();
|
||||
}
|
||||
|
||||
public int realLength() {
|
||||
return positions.length;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setTntID(int tntID) {
|
||||
this.tntID = tntID;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,8 +3,9 @@ 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.TraceSidebar;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -55,11 +56,9 @@ public class BauScoreboard implements Listener {
|
||||
|
||||
if (RecordManager.getStatus().isTracing()) {
|
||||
strings.add("§3");
|
||||
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("§eTrace-Start§8: §7" + new SimpleDateFormat("HH:mm:ss").format(new Date(TNTRecorder.recordStart)));
|
||||
strings.add("§eTicks§8: §7" + traceTicks());
|
||||
strings.add("§eAnzahl TNT§8: §7" + TraceManager.currentFrameSize());
|
||||
}
|
||||
|
||||
strings.add("§4");
|
||||
@ -67,4 +66,7 @@ public class BauScoreboard implements Listener {
|
||||
return strings;
|
||||
}
|
||||
|
||||
private long traceTicks() {
|
||||
return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren