diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 3dddf5f..49730dd 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -30,8 +30,8 @@ public class TNTTracer_12 { return new TraceEntity_12(world, tntPosition, player, exploded, tnt); } - public static boolean inWater(World world, TNTPosition tntPosition) { - Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); + public static boolean inWater(World world, Vector tntPosition) { + Material material = tntPosition.toLocation(world).getBlock().getType(); return material == Material.WATER || material == Material.STATIONARY_WATER; } diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 5c0ca6a..b1f76c3 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -26,6 +26,8 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import java.lang.reflect.Field; + class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private Vector position; @@ -39,33 +41,31 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { this.dropItem = false; this.setCustomNameVisible(true); if (exploded) { - this.setCustomName("Bum"); + this.setCustomName("Bumm"); } display(player); } - @Override - public void move(EnumMoveType enummovetype, double dx, double dy, double dz) { - - } - @Override public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); - ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); - ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + // Todo: + // Reflection needed? + setValue("c", packetPlayOutSpawnEntity, position.getX()); + setValue("d", packetPlayOutSpawnEntity, position.getY()); + setValue("e", packetPlayOutSpawnEntity, position.getZ()); + setValue("f", packetPlayOutSpawnEntity, 0); + setValue("g", packetPlayOutSpawnEntity, 0); + setValue("h", packetPlayOutSpawnEntity, 0); + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); + playerConnection.sendPacket(packetPlayOutEntityTeleport); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + playerConnection.sendPacket(packetPlayOutEntityMetadata); return this; } @@ -78,9 +78,14 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { return this; } - @Override - public void remove() { - killEntity(); + private static void setValue(String field, Object object, Object value) { + try { + Field f = object.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(object, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new SecurityException(e); + } } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 2b1aa5f..4c18ae6 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -30,8 +30,8 @@ public class TNTTracer_15 { return new TraceEntity_15(world, tntPosition, player, exploded, tnt); } - public static boolean inWater(World world, TNTPosition tntPosition) { - Material material = tntPosition.getLocation().toLocation(world).getBlock().getType(); + public static boolean inWater(World world, Vector tntPosition) { + Material material = tntPosition.toLocation(world).getBlock().getType(); return material == Material.WATER; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 4d4a7f9..1087626 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -42,27 +42,20 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { this.dropItem = false; this.setCustomNameVisible(true); if (exploded) { - this.setCustomName(new ChatComponentText("Bum")); + this.setCustomName(new ChatComponentText("Bumm")); } display(player); } - @Override - public void move(EnumMoveType enummovetype, Vec3D vec3d) { - - } - @Override public AbstractTraceEntity display(Player player) { - if (!tnt) { - System.out.println("DISPLAY"); - } PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata); + playerConnection.sendPacket(packetPlayOutEntityMetadata); return this; } @@ -75,9 +68,4 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { return this; } - @Override - public void remove() { - killEntity(); - } - } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java index 1ff6886..b2825e5 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTraceEntity.java @@ -27,6 +27,6 @@ public interface AbstractTraceEntity { AbstractTraceEntity hide(Player player); - void remove(); + void killEntity(); } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java deleted file mode 100644 index a891e8b..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.tracer; - -import java.lang.reflect.Field; - -public class ReflectionUtils { - - @SuppressWarnings({"java:S3011"}) - static void setValue(String field, Object object, Object value) { - try { - Field f = object.getClass().getDeclaredField(field); - f.setAccessible(true); - f.set(object, value); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new SecurityException(e); - } - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 6d7dd7b..50bf488 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -121,7 +121,6 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); new AFKStopper(); - // TNTTracer.init(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); } @@ -166,8 +165,6 @@ public class BauSystem extends JavaPlugin implements Listener { Player p = e.getPlayer(); p.setOp(true); - // ShowManager.add(p); - if (Core.getVersion() == 15) Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 336ac2c..880df14 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -23,8 +23,13 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.record.RecordStatus; +import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; +import de.steamwar.bausystem.tracer.show.mode.Advanced; +import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater; +import de.steamwar.bausystem.tracer.show.mode.Basic; +import de.steamwar.bausystem.tracer.show.mode.BasicNoWater; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -98,7 +103,31 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": - TraceShowManager.show(player, args); + ShowMode showMode; + if (args.length < 2) { + showMode = new Basic(player); + } else { + switch (args[1].toLowerCase()) { + case "nowater": + case "basic-nowater": + case "basicnowater": + showMode = new BasicNoWater(player); + break; + case "advanced": + showMode = new Advanced(player); + break; + case "advanced-nowater": + case "advancednowater": + showMode = new AdvancedNoWater(player); + break; + case "basic": + case "default": + default: + showMode = new Basic(player); + break; + } + } + TraceShowManager.show(player, showMode); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; case "hide": diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java similarity index 100% rename from BauSystem_API/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/RoundedTNTPosition.java diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTPosition.java similarity index 100% rename from BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java rename to BauSystem_Main/src/de/steamwar/bausystem/tracer/TNTPosition.java 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 25fb60a..f682f6a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/Recorder.java @@ -43,8 +43,13 @@ public class Recorder implements Listener { Recorder() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 0, 1); + task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), this::run, 1, 1); record = new Record(); + + // To trace TNT initial positions with AutoTracer + if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) { + run(); + } } void stopRecording() { 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 0969fd9..70e8afd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -17,34 +17,8 @@ public class TraceShowManager implements Listener { private static final Map showModes = new HashMap<>(); - public static void show(Player player, String[] args) { + public static void show(Player player, ShowMode showMode) { hide(player); - - ShowMode showMode; - if (args.length < 2) { - showMode = new Basic(player); - } else { - switch (args[1].toLowerCase()) { - case "nowater": - case "basic-nowater": - case "basicnowater": - showMode = new BasicNoWater(player); - break; - case "advanced": - showMode = new Advanced(player); - break; - case "advanced-nowater": - case "advancednowater": - showMode = new AdvancedNoWater(player); - break; - case "basic": - case "default": - default: - showMode = new Basic(player); - break; - } - } - showModes.put(player, showMode); StoredRecords.showAll(showMode); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 79948db..34fa854 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -21,9 +21,9 @@ package de.steamwar.bausystem.tracer.show.mode; -import de.steamwar.bausystem.tracer.*; -import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; +import de.steamwar.bausystem.tracer.AbstractTraceEntity; +import de.steamwar.bausystem.tracer.RoundedTNTPosition; +import de.steamwar.bausystem.tracer.TNTPosition; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -32,13 +32,10 @@ import java.util.Map; public class Advanced extends Basic { - private final Player player; - private Map updateEntityMap = new HashMap<>(); public Advanced(Player player) { super(player); - this.player = player; } @Override @@ -46,11 +43,11 @@ public class Advanced extends Basic { super.show(position); if (position.getPreviousLocation() == null) return; - Vector previousLocation = position.getLocation().clone().subtract(position.getPreviousLocation()); + Vector vector = position.getLocation().clone().subtract(position.getPreviousLocation()); - Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); + Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); Vector updatePointXZ; - if (Math.abs(position.getPreviousLocation().getX()) > Math.abs(position.getPreviousLocation().getZ())) { + if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) { updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); } else { updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); @@ -61,16 +58,14 @@ public class Advanced extends Basic { if (updateEntityMap.containsKey(updatePointPosition)) { return; } - updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointY, player, false, false), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointY, player, false, false), 14))); + updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false)); } if (!position.getLocation().equals(updatePointXZ)) { RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ); if (updateEntityMap.containsKey(updatePointPosition)) { return; } - updateEntityMap.put(updatePointPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), updatePointXZ, player, false, false), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), updatePointXZ, player, false, false), 14))); + updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false)); } } @@ -80,7 +75,7 @@ public class Advanced extends Basic { updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); + abstractTraceEntity.killEntity(); }); updateEntityMap.clear(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java index 9e1a932..ce45bf0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/AdvancedNoWater.java @@ -24,7 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTTracer_12; import de.steamwar.bausystem.tracer.TNTTracer_15; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -39,18 +39,11 @@ public class AdvancedNoWater extends Advanced { @Override public void show(TNTPosition position) { - boolean b; - switch (Core.getVersion()) { - case 12: - b = TNTTracer_12.inWater(world, position); - break; - default: - b = TNTTracer_15.inWater(world, position); - break; - } - if (!b) { - super.show(position); + if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), + new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) { + return; } + super.show(position); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index 74a43d9..02131db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -4,13 +4,14 @@ import de.steamwar.bausystem.tracer.*; import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import java.util.HashMap; import java.util.Map; public class Basic implements ShowMode { - private final Player player; + protected final Player player; private Map tntEntityMap = new HashMap<>(); @@ -24,15 +25,19 @@ public class Basic implements ShowMode { if (tntEntityMap.containsKey(roundedTNTPosition)) { return; } - tntEntityMap.put(roundedTNTPosition, VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 8), - new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position.getLocation(), player, position.isExploded(), true), 14))); + tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true)); + } + + protected AbstractTraceEntity createEntity(Vector position, boolean exploded, boolean tnt) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, player, exploded, tnt), 8), + new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, player, exploded, tnt), 14)); } @Override public void hide() { tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); + abstractTraceEntity.killEntity(); }); tntEntityMap.clear(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java index 8f9e2f7..0eb94ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicNoWater.java @@ -24,7 +24,7 @@ package de.steamwar.bausystem.tracer.show.mode; import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTTracer_12; import de.steamwar.bausystem.tracer.TNTTracer_15; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -39,18 +39,11 @@ public class BasicNoWater extends Basic { @Override public void show(TNTPosition position) { - boolean b; - switch (Core.getVersion()) { - case 12: - b = TNTTracer_12.inWater(world, position); - break; - default: - b = TNTTracer_15.inWater(world, position); - break; - } - if (!b) { - super.show(position); + if (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(world, position.getLocation()), 8), + new VersionedCallable<>(() -> TNTTracer_15.inWater(world, position.getLocation()), 14))) { + return; } + super.show(position); } }