From d00d0ad512718944bb6d04c19efef22467e2f394 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 20:01:26 +0100 Subject: [PATCH] Add BasicShowMode --- .../de/steamwar/bausystem/tracer/TNTEntity_12.java | 6 ++++++ .../de/steamwar/bausystem/tracer/TNTEntity_15.java | 14 +++++--------- .../steamwar/bausystem/tracer/ReflectionUtils.java | 9 +++++++-- .../steamwar/bausystem/commands/CommandTrace.java | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) 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 e69ef24..edfb52f 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -8,8 +8,11 @@ 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; @@ -27,6 +30,9 @@ public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntit @Override public AbstractTNTEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); 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 2bf0278..6a49013 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -8,8 +8,12 @@ import org.bukkit.entity.Player; public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { + private static final Vec3D ZERO = new Vec3D(0, 0, 0); + 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; @@ -26,17 +30,9 @@ 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); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); ((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_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java index 88d125a..5fc0946 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/ReflectionUtils.java @@ -1,12 +1,17 @@ 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 { - object.getClass().getDeclaredField(field).set(object, value); + Field f = object.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(object, value); } catch (NoSuchFieldException | IllegalAccessException e) { - + e.printStackTrace(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 983f726..44f65d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -65,7 +65,7 @@ public class CommandTrace implements CommandExecutor { return false; } - if (!permissionCheck(player)) return false; + // if (!permissionCheck(player)) return false; switch (args[0].toLowerCase()) { case "start":