diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index 72d7136..e69ef24 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -8,11 +8,8 @@ import org.bukkit.entity.Player; public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { - private TNTPosition position; - public TNTEntity_12(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); - this.position = position; this.setNoGravity(true); this.ticksLived = -12000; @@ -35,6 +32,9 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index c5a4d2a..f421f5c 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -8,11 +8,8 @@ import org.bukkit.entity.Player; public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { - private TNTPosition position; - public TNTEntity_15(World world, TNTPosition position, Player player) { super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); - this.position = position; this.setNoGravity(true); this.ticksLived = -12000; @@ -29,12 +26,17 @@ public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { + System.out.println("SHOW: " + player + " " + locX() + " " + locY() + " " + locZ()); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index e6c9e96..983f726 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.StoredRecords; +import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -83,8 +84,10 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": + TraceShowManager.show(player); break; case "hide": + TraceShowManager.hide(player); break; case "toggleshow": case "interpolate": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java index 5086697..7a1e25e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStateMachine.java @@ -20,7 +20,8 @@ package de.steamwar.bausystem.tracer.record; public class RecordStateMachine { - private RecordStateMachine(){} + private RecordStateMachine() { + } private static final TraceAutoHandler autoHandler = new TraceAutoHandler(); @@ -28,15 +29,15 @@ public class RecordStateMachine { private static Recorder recorder = null; public static void commandStart() { - recordStatus = RecordStatus.RECORD; autoHandler.disable(); recordStart(); + recordStatus = RecordStatus.RECORD; } public static void commandStop() { - recordStatus = RecordStatus.IDLE; autoHandler.disable(); recordStop(); + recordStatus = RecordStatus.IDLE; } public static void commandAuto() { @@ -52,27 +53,23 @@ public class RecordStateMachine { } } - static void autoRecord(){ - recordStatus = RecordStatus.RECORD_AUTO; + static void autoRecord() { recordStart(); + recordStatus = RecordStatus.RECORD_AUTO; } - static void autoIdle(){ - recordStatus = RecordStatus.IDLE_AUTO; + static void autoIdle() { recordStop(); + recordStatus = RecordStatus.IDLE_AUTO; } private static void recordStart() { - if(recordStatus.isTracing()) - return; - + if (recordStatus.isTracing()) return; recorder = new Recorder(); } private static void recordStop() { - if(!recordStatus.isTracing()) - return; - + if (!recordStatus.isTracing()) return; recorder.stopRecording(); } @@ -80,11 +77,13 @@ public class RecordStateMachine { return recordStatus; } - public static int size(){ + public static int size() { + if (recorder == null) return 0; return recorder.size(); } - public static long getStartTime(){ + public static long getStartTime() { + if (recorder == null) return 0; return recorder.getStartTime(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java index c161253..8aeaa43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -41,13 +41,13 @@ public class Recorder implements Listener { private final BukkitTask task; private final Record record; - Recorder(){ + Recorder() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); record = new Record(); } - void stopRecording(){ + void stopRecording() { HandlerList.unregisterAll(this); task.cancel(); } @@ -76,7 +76,7 @@ public class Recorder implements Listener { private Record.TNTRecord get(TNTPrimed tntPrimed) { Record.TNTRecord tntRecord = recordMap.get(tntPrimed); - if(tntRecord != null) + if (tntRecord != null) return tntRecord; tntRecord = this.record.spawn(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java index 531927e..b829d50 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -30,26 +30,26 @@ public class Record { private final long startTime; private final List tnt = new ArrayList<>(); - public int size(){ + public int size() { return tnt.size(); } - public long getStartTime(){ + public long getStartTime() { return startTime; } public void showAll(ShowMode mode) { - for(TNTRecord record : tnt) + for (TNTRecord record : tnt) record.showAll(mode); } /* The following methods should only be called by a recorder */ - public Record(){ + public Record() { startTime = System.currentTimeMillis(); StoredRecords.add(this); } - public TNTRecord spawn(){ + public TNTRecord spawn() { TNTRecord record = new TNTRecord(); tnt.add(record); return record; @@ -59,8 +59,8 @@ public class Record { private final List positions = new ArrayList<>(41); private boolean exploded = false; - public void showAll(ShowMode mode){ - for(TNTPosition position : positions) + public void showAll(ShowMode mode) { + for (TNTPosition position : positions) mode.show(position); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java index 259bbab..a7ce3c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/StoredRecords.java @@ -23,18 +23,20 @@ import java.util.ArrayList; import java.util.List; public class StoredRecords { + private static final List records = new ArrayList<>(); - public static void add(Record record){ + public static void add(Record record) { records.add(record); } - public static void showAll(ShowMode mode){ - for(Record record : records) record.showAll(mode); + public static void showAll(ShowMode mode) { + for (Record record : records) record.showAll(mode); } - public static void clear(){ + public static void clear() { records.clear(); TraceShowManager.clear(); } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index f8ec581..c931eed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -13,42 +13,42 @@ import java.util.HashMap; import java.util.Map; public class TraceShowManager implements Listener { - private TraceShowManager(){} + private TraceShowManager() {} private static final Map showModes = new HashMap<>(); - public static void show(Player player){ + public static void show(Player player) { hide(player); ShowMode showMode = new BasicShowMode(player); StoredRecords.showAll(showMode); } - public static void hide(Player player){ + public static void hide(Player player) { ShowMode showMode = showModes.remove(player); - if(showMode == null) + if (showMode == null) return; showMode.hide(); } /* Only to be called by record */ - static void show(TNTPosition tnt){ - for(ShowMode mode : showModes.values()) + static void show(TNTPosition tnt) { + for (ShowMode mode : showModes.values()) mode.show(tnt); } /* Only to be called by StoredRecords */ - static void clear(){ - for(ShowMode mode : showModes.values()) + static void clear() { + for (ShowMode mode : showModes.values()) mode.hide(); } /* Internal if player leaves*/ - static{ + static { Bukkit.getPluginManager().registerEvents(new TraceShowManager(), BauSystem.getPlugin()); } @EventHandler - public void onLeave(PlayerQuitEvent event){ + public void onLeave(PlayerQuitEvent event) { showModes.remove(event.getPlayer()); } }