diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/BoundingBoxExaminer.java b/main/src/main/java/net/citizensnpcs/npc/ai/BoundingBoxExaminer.java index db22ff166..6e5de3f25 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/BoundingBoxExaminer.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/BoundingBoxExaminer.java @@ -9,6 +9,7 @@ import net.citizensnpcs.api.astar.pathfinder.BlockSource; import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer; import net.citizensnpcs.api.astar.pathfinder.PathPoint; import net.citizensnpcs.api.util.BoundingBox; +import net.citizensnpcs.util.NMS; public class BoundingBoxExaminer implements BlockExaminer { private double height; @@ -16,8 +17,8 @@ public class BoundingBoxExaminer implements BlockExaminer { public BoundingBoxExaminer(Entity entity) { if (entity != null) { - this.height = entity.getHeight(); - this.width = entity.getWidth(); + this.height = NMS.getHeight(entity); + this.width = NMS.getWidth(entity); } } diff --git a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java index ef4fbf74c..cd43f2a90 100644 --- a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java @@ -18,6 +18,7 @@ import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; import net.citizensnpcs.api.util.Placeholders; +import net.citizensnpcs.util.NMS; /** * Persists a hologram attached to the NPC. @@ -42,6 +43,17 @@ public class HologramTrait extends Trait { load(); } + private double getEntityHeight() { + if (SUPPORT_GET_HEIGHT) { + try { + return npc.getEntity().getHeight(); + } catch (NoSuchMethodError err) { + SUPPORT_GET_HEIGHT = false; + } + } + return NMS.getHeight(npc.getEntity()); + } + private double getHeight(int lineNumber) { return (lineHeight == -1 ? Setting.DEFAULT_NPC_HOLOGRAM_LINE_HEIGHT.asDouble() : lineHeight) * (lineNumber + 1); } @@ -62,7 +74,7 @@ public class HologramTrait extends Trait { trait.setGravity(false); trait.setHasArms(false); trait.setHasBaseplate(false); - hologramNPC.spawn(currentLoc.clone().add(0, npc.getEntity().getHeight() + getHeight(i), 0)); + hologramNPC.spawn(currentLoc.clone().add(0, getEntityHeight() + getHeight(i), 0)); hologramNPC.getEntity().setInvulnerable(true); hologramNPCs.add(hologramNPC); i++; @@ -106,7 +118,7 @@ public class HologramTrait extends Trait { if (hologram == null) continue; if (update) { - hologramNPC.teleport(currentLoc.clone().add(0, npc.getEntity().getHeight() + getHeight(i), 0), + hologramNPC.teleport(currentLoc.clone().add(0, getEntityHeight() + getHeight(i), 0), TeleportCause.PLUGIN); } String text = lines.get(i); @@ -133,4 +145,6 @@ public class HologramTrait extends Trait { } hologramNPCs.clear(); } + + private static boolean SUPPORT_GET_HEIGHT = true; } diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index 0a5d06b62..296c1112f 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -187,6 +187,10 @@ public class NMS { return BRIDGE.getHeadYaw(entity); } + public static double getHeight(Entity entity) { + return BRIDGE.getHeight(entity); + } + public static float getHorizontalMovement(org.bukkit.entity.Entity bukkitEntity) { return BRIDGE.getHorizontalMovement(bukkitEntity); } @@ -279,6 +283,10 @@ public class NMS { return BRIDGE.getVerticalMovement(bukkitEntity); } + public static double getWidth(Entity entity) { + return BRIDGE.getWidth(entity); + } + public static float getYaw(Entity entity) { return BRIDGE.getYaw(entity); } diff --git a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java index ea229cb89..f39c65d7c 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java +++ b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java @@ -55,6 +55,8 @@ public interface NMSBridge { public float getHeadYaw(Entity entity); + public double getHeight(Entity entity); + public float getHorizontalMovement(Entity entity); public NPC getNPC(Entity entity); @@ -79,6 +81,8 @@ public interface NMSBridge { public float getVerticalMovement(Entity entity); + public double getWidth(Entity entity); + public float getYaw(Entity entity); public boolean isOnGround(Entity entity); 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 aef74c2c8..5d127e14a 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 @@ -369,6 +369,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aQ; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return getHandle(entity).length; + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -564,6 +569,11 @@ public class NMSImpl implements NMSBridge { return handle.bf; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return getHandle(entity).width; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 8cdf715c1..fafd2674d 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 @@ -388,6 +388,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aP; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return getHandle(entity).length; + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -602,6 +607,11 @@ public class NMSImpl implements NMSBridge { return handle.be; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return getHandle(entity).width; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 49bb92b6f..8c243e991 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 @@ -392,6 +392,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aP; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return entity.getHeight(); + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -606,6 +611,11 @@ public class NMSImpl implements NMSBridge { return handle.be; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 143f400a7..b74018a63 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 @@ -415,6 +415,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aS; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return entity.getHeight(); + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -629,6 +634,11 @@ public class NMSImpl implements NMSBridge { return handle.bh; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 13eeba251..bdb36b459 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 @@ -451,6 +451,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aM; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return entity.getHeight(); + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -678,6 +683,11 @@ public class NMSImpl implements NMSBridge { return handle.bb; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 1bf3bc8b1..d2bc56686 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 @@ -458,6 +458,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aK; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return entity.getHeight(); + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -686,6 +691,11 @@ public class NMSImpl implements NMSBridge { return handle.aZ; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; diff --git a/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/util/NMSImpl.java b/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/util/NMSImpl.java index 03de9bfa7..3e036f144 100644 --- a/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/util/NMSImpl.java +++ b/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/util/NMSImpl.java @@ -464,6 +464,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).getHeadRotation(); } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return entity.getHeight(); + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -692,6 +697,11 @@ public class NMSImpl implements NMSBridge { return handle.aY; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 3b29c4a60..ebdc8eb37 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 @@ -320,6 +320,11 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aK; } + @Override + public double getHeight(org.bukkit.entity.Entity entity) { + return getHandle(entity).length; + } + @Override public float getHorizontalMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -501,6 +506,11 @@ public class NMSImpl implements NMSBridge { return handle.aZ; } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return getHandle(entity).width; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw;