diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index c489ab4..a9218e9 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -32,6 +32,7 @@ import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_15_R1.metadata.EntityMetadataStore; import org.bukkit.entity.Player; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; @@ -112,29 +113,14 @@ public abstract class REntity { } } - private static Method setPoseMethod = null; - public void sneak(boolean sneaking) { - try { - if(setPoseMethod == null) { - setPoseMethod = Entity.class.getDeclaredMethod("setPose", EntityPose.class); - setPoseMethod.setAccessible(true); - } - setPoseMethod.invoke(entity, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - /*System.out.println("Let " + entity.getName() + " sneak " + sneaking+ " | " + entity.getClass()); - DataWatcher dataWatcher = entity.getDataWatcher(); + DataWatcher dataWatcher = new DataWatcher(null); - dataWatcher.set(new DataWatcherObject<>(6, DataWatcherRegistry.s), sneaking?EntityPose.CROUCHING:EntityPose.STANDING); - //dataWatcher.set(new DataWatcherObject<>(0, DataWatcherRegistry.a), Byte.valueOf((byte) (sneaking?2:0)));*/ + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); + dataWatcher.markDirty(dataWatcherObject); - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), false); + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); for(Player player : Bukkit.getOnlinePlayers()){ ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);