From 69acf89ff9e0f9a56ec22c55d7398bbe3769dca9 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 1 Nov 2024 20:27:16 +0800 Subject: [PATCH] Cleanup, return the navigation destination from NMS.getDestination in case external plugins miss the timing to get it --- .../java/net/citizensnpcs/EventListen.java | 34 +++------- .../main/java/net/citizensnpcs/Settings.java | 1 - .../citizensnpcs/commands/NPCCommands.java | 8 +-- .../npc/CitizensTraitFactory.java | 4 +- .../trait/TrackTargetedByTrait.java | 68 +++++++++++-------- .../trait/text/TextBasePrompt.java | 7 +- .../nms/v1_10_R1/util/NMSImpl.java | 43 +++++++----- .../nms/v1_11_R1/util/NMSImpl.java | 43 +++++++----- .../nms/v1_12_R1/util/NMSImpl.java | 43 +++++++----- .../nms/v1_13_R2/util/NMSImpl.java | 43 +++++++----- .../nms/v1_14_R1/util/NMSImpl.java | 43 +++++++----- .../nms/v1_15_R1/util/NMSImpl.java | 43 +++++++----- .../nms/v1_16_R3/util/NMSImpl.java | 45 ++++++------ .../nms/v1_17_R1/util/NMSImpl.java | 47 +++++++------ .../nms/v1_18_R2/util/NMSImpl.java | 47 +++++++------ .../nms/v1_19_R3/util/NMSImpl.java | 45 ++++++------ .../nms/v1_20_R4/util/NMSImpl.java | 39 ++++++----- .../nms/v1_21_R2/util/NMSImpl.java | 39 ++++++----- .../nms/v1_8_R3/util/NMSImpl.java | 44 +++++++----- 19 files changed, 380 insertions(+), 306 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index a445730e3..c21610549 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -4,7 +4,6 @@ import java.lang.reflect.Method; import java.util.List; import java.util.Objects; -import net.citizensnpcs.trait.TrackTargetedByTrait; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -117,6 +116,7 @@ import net.citizensnpcs.trait.Controllable; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.HologramTrait.HologramRenderer; import net.citizensnpcs.trait.ShopTrait; +import net.citizensnpcs.trait.TrackTargetedByTrait; import net.citizensnpcs.trait.versioned.SnowmanTrait; import net.citizensnpcs.util.ChunkCoord; import net.citizensnpcs.util.Messages; @@ -449,35 +449,23 @@ public class EventListen implements Listener { public void onEntityTarget(EntityTargetEvent event) { final Entity targeted = event.getTarget(); NPC npc = plugin.getNPCRegistry().getNPC(targeted); - final Entity cause = event.getEntity(); + final Entity targeter = event.getEntity(); if (npc != null) { final EntityTargetNPCEvent targetNPCEvent = new EntityTargetNPCEvent(event, npc); targetNPCEvent.setCancelled(!npc.data().get(NPC.Metadata.TARGETABLE, !npc.isProtected())); Bukkit.getPluginManager().callEvent(targetNPCEvent); if (targetNPCEvent.isCancelled()) { event.setCancelled(true); - } else { - if (event.isCancelled()) { - return; - } - if (!(cause instanceof Mob)) { - return; - } - final TrackTargetedByTrait beTargetedBy = npc.getOrAddTrait(TrackTargetedByTrait.class); - beTargetedBy.add(cause.getUniqueId()); - } - } else { - if (cause instanceof Mob) { - final LivingEntity previousTarget = ((Mob) cause).getTarget(); - if (previousTarget == null) { // normally it is impossible - return; - } - final NPC previousAsNPC = plugin.getNPCRegistry().getNPC(previousTarget); - if (previousAsNPC != null) { - final TrackTargetedByTrait beTargetedBy = previousAsNPC.getOrAddTrait(TrackTargetedByTrait.class); - beTargetedBy.remove(cause.getUniqueId()); - } + return; } + if (event.isCancelled() || !(targeter instanceof Mob)) + return; + npc.getOrAddTrait(TrackTargetedByTrait.class).add(targeter.getUniqueId()); + } else if (targeter instanceof Mob) { + final NPC prev = plugin.getNPCRegistry().getNPC(((Mob) targeter).getTarget()); + if (prev == null) + return; + prev.getOrAddTrait(TrackTargetedByTrait.class).remove(targeter.getUniqueId()); } } diff --git a/main/src/main/java/net/citizensnpcs/Settings.java b/main/src/main/java/net/citizensnpcs/Settings.java index fc9f2e1db..45a9c2009 100644 --- a/main/src/main/java/net/citizensnpcs/Settings.java +++ b/main/src/main/java/net/citizensnpcs/Settings.java @@ -219,7 +219,6 @@ public class Settings { MAX_NPC_SKIN_RETRIES( "How many times to try load NPC skins (due to Minecraft rate-limiting skin requests, should rarely be less than 5", "npc.skins.max-retries", -1), - MAX_TEXT_RANGE("The maximum range in blocks for chatting", "npc.chat.options.max-text-range", 500), MAXIMUM_ASTAR_ITERATIONS("The maximum number of blocks to check when pathfinding", "npc.pathfinding.maximum-new-pathfinder-iterations", "npc.pathfinding.new-finder.maximum-iterations", 1024), diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index b1d43cd7f..6730a62fa 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -18,7 +18,6 @@ import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; -import net.citizensnpcs.trait.TrackTargetedByTrait; import org.bukkit.Art; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -166,6 +165,7 @@ import net.citizensnpcs.trait.SkinLayers; import net.citizensnpcs.trait.SkinLayers.Layer; import net.citizensnpcs.trait.SkinTrait; import net.citizensnpcs.trait.SlimeSize; +import net.citizensnpcs.trait.TrackTargetedByTrait; import net.citizensnpcs.trait.WitherTrait; import net.citizensnpcs.trait.WolfModifiers; import net.citizensnpcs.trait.shop.StoredShops; @@ -3420,9 +3420,9 @@ public class NPCCommands { } } if (!targetable) { - final TrackTargetedByTrait trackTargetedByTrait = npc.getTraitNullable(TrackTargetedByTrait.class); - if (trackTargetedByTrait != null) { // may not be targeted by anything so prevent possible garbages - trackTargetedByTrait.clearTargets(); + final TrackTargetedByTrait trait = npc.getTraitNullable(TrackTargetedByTrait.class); + if (trait != null) { + trait.clearTargets(); } } Messaging.sendTr(sender, targetable ? Messages.TARGETABLE_SET : Messages.TARGETABLE_UNSET, npc.getName()); diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java index fb46e7b8c..9b6de29f0 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java @@ -25,7 +25,6 @@ import net.citizensnpcs.trait.Anchors; import net.citizensnpcs.trait.ArmorStandTrait; import net.citizensnpcs.trait.AttributeTrait; import net.citizensnpcs.trait.BatTrait; -import net.citizensnpcs.trait.TrackTargetedByTrait; import net.citizensnpcs.trait.BoundingBoxTrait; import net.citizensnpcs.trait.ClickRedirectTrait; import net.citizensnpcs.trait.CommandTrait; @@ -64,6 +63,7 @@ import net.citizensnpcs.trait.SkinTrait; import net.citizensnpcs.trait.SleepTrait; import net.citizensnpcs.trait.SlimeSize; import net.citizensnpcs.trait.SneakTrait; +import net.citizensnpcs.trait.TrackTargetedByTrait; import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.WitherTrait; import net.citizensnpcs.trait.WolfModifiers; @@ -104,7 +104,6 @@ public class CitizensTraitFactory implements TraitFactory { registerTrait(TraitInfo.create(ItemFrameTrait.class)); registerTrait(TraitInfo.create(LookClose.class)); registerTrait(TraitInfo.create(PaintingTrait.class)); - registerTrait(TraitInfo.create(TrackTargetedByTrait.class)); registerTrait(TraitInfo.create(MirrorTrait.class).optInToStats()); registerTrait(TraitInfo.create(MountTrait.class)); registerTrait(TraitInfo.create(MobType.class).asDefaultTrait()); @@ -141,6 +140,7 @@ public class CitizensTraitFactory implements TraitFactory { registerTrait(TraitInfo.create(SlimeSize.class)); registerTrait(TraitInfo.create(Spawned.class)); registerTrait(TraitInfo.create(Text.class)); + registerTrait(TraitInfo.create(TrackTargetedByTrait.class)); registerTrait(TraitInfo.create(Waypoints.class).optInToStats()); registerTrait(TraitInfo.create(WitherTrait.class)); registerTrait(TraitInfo.create(WoolColor.class)); diff --git a/main/src/main/java/net/citizensnpcs/trait/TrackTargetedByTrait.java b/main/src/main/java/net/citizensnpcs/trait/TrackTargetedByTrait.java index b1bab89c3..0c3a943c5 100644 --- a/main/src/main/java/net/citizensnpcs/trait/TrackTargetedByTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/TrackTargetedByTrait.java @@ -1,54 +1,64 @@ package net.citizensnpcs.trait; -import net.citizensnpcs.api.trait.Trait; -import net.citizensnpcs.api.trait.TraitName; -import org.bukkit.Bukkit; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Mob; - import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Mob; + +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; + @TraitName("tracktargetedby") public class TrackTargetedByTrait extends Trait { - private Set beTargetedBy; + private Set targetedBy; public TrackTargetedByTrait() { super("tracktargetedby"); } + public void add(UUID uuid) { + if (targetedBy == null) { + targetedBy = new HashSet<>(); + } + targetedBy.add(uuid); + } + + public void clearTargets() { + if (targetedBy == null) + return; + targetedBy = null; + if (!SUPPORTS_GET_ENTITY) + return; + for (UUID uuid : targetedBy) { + final Entity entity = Bukkit.getEntity(uuid); + if (entity instanceof Mob) { + if (entity.isValid()) { + ((Mob) entity).setTarget(null); + } + } + } + } + @Override public void onDespawn() { clearTargets(); } - // Only for internal use - public void add(UUID uuid) { - if (beTargetedBy == null) { - beTargetedBy = new HashSet<>(); - } - beTargetedBy.add(uuid); - } - - // Only for internal use public void remove(UUID uuid) { - if (beTargetedBy != null) { - beTargetedBy.remove(uuid); + if (targetedBy != null) { + targetedBy.remove(uuid); } } - public void clearTargets() { - if (beTargetedBy != null) { - for (UUID entityUUID : beTargetedBy) { - final Entity entity = Bukkit.getEntity(entityUUID); - if (entity instanceof Mob) { - if (entity.isValid()) { - ((Mob) entity).setTarget(null); - } - } - } - beTargetedBy = null; + private static boolean SUPPORTS_GET_ENTITY = true; + static { + try { + Bukkit.class.getMethod("getEntity", UUID.class); + } catch (NoSuchMethodException e) { + SUPPORTS_GET_ENTITY = false; } } } diff --git a/main/src/main/java/net/citizensnpcs/trait/text/TextBasePrompt.java b/main/src/main/java/net/citizensnpcs/trait/text/TextBasePrompt.java index f67a4907f..ff838c6cf 100644 --- a/main/src/main/java/net/citizensnpcs/trait/text/TextBasePrompt.java +++ b/main/src/main/java/net/citizensnpcs/trait/text/TextBasePrompt.java @@ -13,7 +13,6 @@ import org.bukkit.entity.Player; import com.google.common.base.Joiner; -import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.util.Messages; @@ -94,12 +93,10 @@ public class TextBasePrompt extends StringPrompt { text.toggleTalkClose(); } else if (input.equalsIgnoreCase("range")) { try { - double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble()); + double range = Math.max(0, Double.parseDouble(parts[1])); text.setRange(range); Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range); - } catch (NumberFormatException e) { - Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE); - } catch (ArrayIndexOutOfBoundsException e) { + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE); } } else if (input.equalsIgnoreCase("item")) { 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 49318c4d8..8f66b3387 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 @@ -464,9 +464,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.a()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.a()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.k().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bg; } @Override @@ -481,14 +496,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aQ; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bg; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -680,14 +687,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bf; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -700,6 +699,14 @@ public class NMSImpl implements NMSBridge { return getHandle(entity).width; } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bf; + } + @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 a485a3485..493e2b836 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 @@ -484,9 +484,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.a()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.a()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.k().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bf; } @Override @@ -501,14 +516,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aP; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bf; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -716,14 +723,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.be; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -736,6 +735,14 @@ public class NMSImpl implements NMSBridge { return getHandle(entity).width; } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.be; + } + @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 d435af188..b3b810f93 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 @@ -485,9 +485,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.b()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.b()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.l().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bg; } @Override @@ -502,14 +517,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aP; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bg; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -718,14 +725,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.be; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -738,6 +737,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.be; + } + @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 ce462aede..c8080720a 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 @@ -514,9 +514,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.b()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.b()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.m().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bj; } @Override @@ -531,14 +546,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aS; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bj; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -747,14 +754,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bh; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -767,6 +766,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bh; + } + @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 0d21b3bdf..ed1894fe1 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 @@ -556,9 +556,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.b()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.b()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.l().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bd; } @Override @@ -573,14 +588,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aM; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bd; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -798,14 +805,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bb; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -818,6 +817,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bb; + } + @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 d46521e7b..e365cd2d7 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 @@ -571,9 +571,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.b()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.b()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.k().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.bb; } @Override @@ -588,14 +603,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aK; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.bb; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -813,14 +820,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.aZ; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -833,6 +832,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.aZ; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; 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 8a049c2d9..42b6ed8f4 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 @@ -584,11 +584,24 @@ public class NMSImpl implements NMSBridge { @Override public Location getDestination(org.bukkit.entity.Entity entity) { Entity handle = getHandle(entity); - ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() - : handle instanceof MobAI ? ((MobAI) handle).getMoveControl() : null; - if (controller == null || !controller.b()) + MobAI ai = MobAI.from(handle); + if (ai == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + ControllerMove controller = ai.getMoveControl(); + if (controller.b()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (isNavigationFinished(ai.getNavigation())) + return null; + Vec3D vec = ai.getNavigation().k().a(handle); + return new Location(entity.getWorld(), vec.x, vec.y, vec.z); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.aT; } @Override @@ -603,14 +616,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).getHeadRotation(); } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.aT; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -836,14 +841,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.aR; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -856,6 +853,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.aR; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw; diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index a65063258..1e49ba17b 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -594,12 +594,25 @@ public class NMSImpl implements NMSBridge { @Override public Location getDestination(org.bukkit.entity.Entity entity) { Entity handle = getHandle(entity); - MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl() - : handle instanceof MobAI ? ((MobAI) handle).getMoveControl() : null; - if (controller == null || !controller.hasWanted()) + MobAI ai = MobAI.from(handle); + if (ai == null) return null; - return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), - controller.getWantedZ()); + MoveControl controller = ai.getMoveControl(); + if (controller.hasWanted()) + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + if (ai.getNavigation().isDone()) + return null; + Vec3 vec = ai.getNavigation().getPath().getNextEntityPos(handle); + return new Location(entity.getWorld(), vec.x(), vec.y(), vec.z()); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.zza; } @Override @@ -614,14 +627,6 @@ public class NMSImpl implements NMSBridge { return getHandle((org.bukkit.entity.LivingEntity) entity).getYHeadRot(); } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.zza; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level; @@ -838,14 +843,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.xxa; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level; @@ -858,6 +855,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.xxa; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).getYRot(); diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index c7216bff0..3287c7390 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -600,12 +600,25 @@ public class NMSImpl implements NMSBridge { @Override public Location getDestination(org.bukkit.entity.Entity entity) { Entity handle = getHandle(entity); - MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl() - : handle instanceof MobAI ? ((MobAI) handle).getMoveControl() : null; - if (controller == null || !controller.hasWanted()) + MobAI ai = MobAI.from(handle); + if (ai == null) return null; - return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), - controller.getWantedZ()); + MoveControl controller = ai.getMoveControl(); + if (controller.hasWanted()) + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + if (ai.getNavigation().isDone()) + return null; + Vec3 vec = ai.getNavigation().getPath().getNextEntityPos(handle); + return new Location(entity.getWorld(), vec.x(), vec.y(), vec.z()); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.zza; } @Override @@ -620,14 +633,6 @@ public class NMSImpl implements NMSBridge { return getHandle((org.bukkit.entity.LivingEntity) entity).getYHeadRot(); } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.zza; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level; @@ -845,14 +850,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.xxa; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level; @@ -865,6 +862,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.xxa; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).getYRot(); diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java index 2ca145d27..8fb373b27 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java @@ -645,11 +645,24 @@ public class NMSImpl implements NMSBridge { public Location getDestination(org.bukkit.entity.Entity entity) { Entity handle = getHandle(entity); MobAI ai = MobAI.from(handle); - MoveControl controller = ai != null ? ai.getMoveControl() : null; - if (controller == null || !controller.hasWanted()) + if (ai == null) return null; - return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), - controller.getWantedZ()); + MoveControl controller = ai.getMoveControl(); + if (controller.hasWanted()) + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + if (ai.getNavigation().isDone()) + return null; + Vec3 vec = ai.getNavigation().getPath().getNextEntityPos(handle); + return new Location(entity.getWorld(), vec.x(), vec.y(), vec.z()); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.zza; } @Override @@ -664,14 +677,6 @@ public class NMSImpl implements NMSBridge { return getHandle((org.bukkit.entity.LivingEntity) entity).getYHeadRot(); } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.zza; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level; @@ -894,14 +899,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.xxa; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level; @@ -914,6 +911,14 @@ public class NMSImpl implements NMSBridge { return entity.getWidth(); } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.xxa; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).getYRot(); diff --git a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java index 03a9f8365..b98e9e74e 100644 --- a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java +++ b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java @@ -673,11 +673,24 @@ public class NMSImpl implements NMSBridge { public Location getDestination(org.bukkit.entity.Entity entity) { Entity handle = getHandle(entity); MobAI ai = MobAI.from(handle); - MoveControl controller = ai != null ? ai.getMoveControl() : null; - if (controller == null || !controller.hasWanted()) + if (ai == null) return null; - return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), - controller.getWantedZ()); + MoveControl controller = ai.getMoveControl(); + if (controller.hasWanted()) + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + if (ai.getNavigation().isDone()) + return null; + Vec3 vec = ai.getNavigation().getPath().getNextEntityPos(handle); + return new Location(entity.getWorld(), vec.x(), vec.y(), vec.z()); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.zza; } @Override @@ -692,14 +705,6 @@ public class NMSImpl implements NMSBridge { return getHandle((org.bukkit.entity.LivingEntity) entity).getYHeadRot(); } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.zza; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level(); @@ -923,6 +928,11 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getXZMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -931,11 +941,6 @@ public class NMSImpl implements NMSBridge { return handle.xxa; } - @Override - public double getWidth(org.bukkit.entity.Entity entity) { - return entity.getWidth(); - } - @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).getYRot(); diff --git a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java index 293af93c8..1486d5f25 100644 --- a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java +++ b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java @@ -661,11 +661,24 @@ public class NMSImpl implements NMSBridge { public Location getDestination(org.bukkit.entity.Entity entity) { Entity handle = getHandle(entity); MobAI ai = MobAI.from(handle); - MoveControl controller = ai != null ? ai.getMoveControl() : null; - if (controller == null || !controller.hasWanted()) + if (ai == null) return null; - return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), - controller.getWantedZ()); + MoveControl controller = ai.getMoveControl(); + if (controller.hasWanted()) + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + if (ai.getNavigation().isDone()) + return null; + Vec3 vec = ai.getNavigation().getPath().getNextEntityPos(handle); + return new Location(entity.getWorld(), vec.x(), vec.y(), vec.z()); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); + return handle.zza; } @Override @@ -680,14 +693,6 @@ public class NMSImpl implements NMSBridge { return getHandle((org.bukkit.entity.LivingEntity) entity).getYHeadRot(); } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - LivingEntity handle = getHandle((org.bukkit.entity.LivingEntity) entity); - return handle.zza; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { ServerLevel server = (ServerLevel) getHandle(entity).level(); @@ -911,6 +916,11 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } + @Override + public double getWidth(org.bukkit.entity.Entity entity) { + return entity.getWidth(); + } + @Override public float getXZMovement(org.bukkit.entity.Entity entity) { if (!entity.getType().isAlive()) @@ -919,11 +929,6 @@ public class NMSImpl implements NMSBridge { return handle.xxa; } - @Override - public double getWidth(org.bukkit.entity.Entity entity) { - return entity.getWidth(); - } - @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).getYRot(); 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 bacb303a9..993e1932c 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 @@ -219,6 +219,7 @@ import net.minecraft.server.v1_8_R3.PathfinderGoalSelector; import net.minecraft.server.v1_8_R3.ReportedException; import net.minecraft.server.v1_8_R3.ScoreboardTeam; import net.minecraft.server.v1_8_R3.ScoreboardTeamBase.EnumNameTagVisibility; +import net.minecraft.server.v1_8_R3.Vec3D; import net.minecraft.server.v1_8_R3.WorldServer; @SuppressWarnings("unchecked") @@ -418,9 +419,24 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null; - if (controller == null || !controller.a()) + if (controller == null) return null; - return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + if (controller.a()) + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + NavigationAbstract nav = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + if (isNavigationFinished(nav)) + return null; + Vec3D vec = nav.j().a(handle); + return new Location(entity.getWorld(), vec.a, vec.b, vec.c); + } + + @Override + public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.ba; } @Override @@ -435,14 +451,6 @@ public class NMSImpl implements NMSBridge { return getHandle((LivingEntity) entity).aK; } - @Override - public float getForwardBackwardMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.ba; - } - @Override public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -624,14 +632,6 @@ public class NMSImpl implements NMSBridge { return e == handle || e == null ? null : e.getBukkitEntity(); } - @Override - public float getXZMovement(org.bukkit.entity.Entity entity) { - if (!entity.getType().isAlive()) - return Float.NaN; - EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); - return handle.aZ; - } - @Override public Collection getViewingPlayers(org.bukkit.entity.Entity entity) { WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld(); @@ -644,6 +644,14 @@ public class NMSImpl implements NMSBridge { return getHandle(entity).width; } + @Override + public float getXZMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.aZ; + } + @Override public float getYaw(org.bukkit.entity.Entity entity) { return getHandle(entity).yaw;