From bce7baced992a7650a6ee29b4e888d91009c0584 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 25 Aug 2024 19:07:04 +0800 Subject: [PATCH] Fix impossible cast in old versions of minecraft --- .../nms/v1_10_R1/util/NMSImpl.java | 2 +- .../nms/v1_11_R1/util/NMSImpl.java | 2 +- .../nms/v1_12_R1/util/NMSImpl.java | 2 +- .../nms/v1_13_R2/util/NMSImpl.java | 2 +- .../nms/v1_14_R1/util/NMSImpl.java | 2 +- .../nms/v1_15_R1/util/NMSImpl.java | 2 +- .../nms/v1_16_R3/util/NMSImpl.java | 6 ++-- .../nms/v1_21_R1/util/NMSImpl.java | 2 +- .../nms/v1_8_R3/util/NMSImpl.java | 35 ++++++++++--------- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index cf11924b4..b75593a2e 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -1145,7 +1145,7 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { EntityLiving handle = (EntityLiving) getHandle(entity); handle.aP = yaw; if (!(handle instanceof EntityHuman)) { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index 415ca776f..d0185baa7 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -1198,7 +1198,7 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { EntityLiving handle = (EntityLiving) getHandle(entity); handle.aO = yaw; if (!(handle instanceof EntityHuman)) { diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index 3459bcffa..a2edb0409 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -1206,7 +1206,7 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { EntityLiving handle = (EntityLiving) getHandle(entity); handle.aO = yaw; if (!(handle instanceof EntityHuman)) { diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index dda9952ae..3c46f05aa 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -1242,7 +1242,7 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { EntityLiving handle = (EntityLiving) getHandle(entity); handle.aR = yaw; if (!(handle instanceof EntityHuman)) { diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index decdb1257..135415842 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -1278,7 +1278,7 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { EntityLiving handle = (EntityLiving) getHandle(entity); handle.aL = yaw; if (!(handle instanceof EntityHuman)) { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 7f02b8fa6..c6f1dfb48 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -1295,7 +1295,7 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { EntityLiving handle = (EntityLiving) getHandle(entity); handle.aJ = yaw; if (!(handle instanceof EntityHuman)) { diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index 3718c7c51..6698cf401 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -1332,9 +1332,11 @@ public class NMSImpl implements NMSBridge { public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { Entity handle = getHandle(entity); handle.yaw = yaw; - if (handle instanceof EntityLiving) { + if (getHandle(entity) instanceof EntityLiving) { ((EntityLiving) handle).aB = yaw; - ((EntityLiving) handle).aA = yaw; // TODO: why this + if (!(handle instanceof EntityHuman)) { + ((EntityLiving) handle).aA = yaw; // TODO: why this + } } } diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java index d452ae232..790703c03 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java @@ -455,7 +455,7 @@ public class NMSImpl implements NMSBridge { MobAI ai = MobAI.from(getHandle(entity)); if (ai == null) return; - MoveControl control = ai != null ? ai.getMoveControl() : null; + MoveControl control = ai.getMoveControl(); if (control instanceof EntityMoveControl) { ((EntityMoveControl) control).moving = false; } else { diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index 2d20172de..2567e8ed1 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -1063,12 +1063,13 @@ public class NMSImpl implements NMSBridge { @Override public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { - getHandle(entity).yaw = yaw; - if (entity instanceof EntityLiving) { - EntityLiving handle = (EntityLiving) getHandle(entity); - handle.aJ = yaw; + Entity handle = getHandle(entity); + handle.yaw = yaw; + if (handle instanceof EntityLiving) { + EntityLiving living = (EntityLiving) handle; + living.aJ = yaw; if (!(handle instanceof EntityHuman)) { - handle.aI = yaw; // TODO: why this + living.aI = yaw; // TODO: why this } } } @@ -1759,30 +1760,30 @@ public class NMSImpl implements NMSBridge { EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST); private static final float DEFAULT_SPEED = 1F; - public static MethodHandle ENDERDRAGON_CHECK_WALLS = NMS.getFirstMethodHandleWithReturnType(EntityEnderDragon.class, - true, boolean.class, AxisAlignedBB.class); - private static Method ENTITY_ATTACK_A = NMS.getMethod(Entity.class, "a", true, EntityLiving.class, Entity.class); + public static final MethodHandle ENDERDRAGON_CHECK_WALLS = NMS + .getFirstMethodHandleWithReturnType(EntityEnderDragon.class, true, boolean.class, AxisAlignedBB.class); + private static final Method ENTITY_ATTACK_A = NMS.getMethod(Entity.class, "a", true, EntityLiving.class, + Entity.class); private static Map, Integer> ENTITY_CLASS_TO_INT; private static Map, String> ENTITY_CLASS_TO_NAME; - private static MethodHandle ENTITY_NAVIGATION = NMS.getFirstSetter(EntityInsentient.class, Navigation.class); + private static final MethodHandle ENTITY_NAVIGATION = NMS.getFirstSetter(EntityInsentient.class, Navigation.class); private static final Location FROM_LOCATION = new Location(null, 0, 0, 0); - private static Method GET_NMS_BLOCK = NMS.getMethod(CraftBlock.class, "getNMSBlock", false); - private static Field GOAL_FIELD = NMS.getField(PathfinderGoalSelector.class, "b"); + private static final Method GET_NMS_BLOCK = NMS.getMethod(CraftBlock.class, "getNMSBlock", false); + private static final Field GOAL_FIELD = NMS.getField(PathfinderGoalSelector.class, "b"); private static final Field JUMP_FIELD = NMS.getField(EntityLiving.class, "aY"); private static final MethodHandle LOOK_CONTROL_SETTER = NMS.getFirstSetter(EntityInsentient.class, ControllerLook.class); private static Method MAKE_REQUEST; - private static Field MOVE_CONTROLLER_MOVING = NMS.getField(ControllerMove.class, "f"); - private static Field NAVIGATION_WORLD_FIELD = NMS.getField(NavigationAbstract.class, "c"); - private static Field NETWORK_ADDRESS = NMS.getField(NetworkManager.class, "l"); - private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); - private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "a"); + private static final Field MOVE_CONTROLLER_MOVING = NMS.getField(ControllerMove.class, "f"); + private static final Field NAVIGATION_WORLD_FIELD = NMS.getField(NavigationAbstract.class, "c"); + private static final Field NETWORK_ADDRESS = NMS.getField(NetworkManager.class, "l"); + private static final Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "a"); private static final Random RANDOM = Util.getFastRandom(); private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "h"); private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "g"); private static Field SKULL_PROFILE_FIELD; private static Field TEAM_FIELD; - private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); + private static final Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); static { try { Field field = NMS.getField(EntityTypes.class, "f");