diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index d54edbb01..db44d1fcb 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -41,7 +41,6 @@ import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.npc.ai.AStarNavigationStrategy.AStarPlanner; -import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator; import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.RotationTrait.PacketRotationSession; import net.citizensnpcs.util.NMS; @@ -104,8 +103,7 @@ public class CitizensNavigator implements Navigator, Runnable { planner.tick(Setting.MAXIMUM_ASTAR_ITERATIONS.asInt(), Setting.MAXIMUM_ASTAR_ITERATIONS.asInt()); return planner.plan != null; } else { - MCNavigator nav = NMS.getTargetNavigator(npc.getEntity(), dest, params); - return nav.getCancelReason() == null; + return NMS.canNavigateTo(npc.getEntity(), dest, params); } } diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index 6fc7382b8..f44fa80b3 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -154,6 +154,10 @@ public class NMS { BRIDGE.cancelMoveDestination(entity); } + public static boolean canNavigateTo(Entity entity, Location dest, NavigatorParameters params) { + return BRIDGE.canNavigateTo(entity, dest, params); + } + public static void clearCustomNBT(ItemMeta meta) { if (CUSTOM_NBT_TAG_MISSING) return; diff --git a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java index 10b94a3c2..36c55d102 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java +++ b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java @@ -63,6 +63,8 @@ public interface NMSBridge { public void cancelMoveDestination(Entity entity); + public boolean canNavigateTo(Entity entity, Location dest, NavigatorParameters params); + public default Iterable createBundlePacket(List packets) { return packets; } @@ -95,12 +97,12 @@ public interface NMSBridge { public Location getDestination(Entity entity); + public float getForwardBackwardMovement(Entity entity); + public GameProfileRepository getGameProfileRepository(); public float getHeadYaw(Entity entity); - public float getForwardBackwardMovement(Entity entity); - public EntityPacketTracker getPacketTracker(Entity entity); public List getPassengers(Entity entity); @@ -129,14 +131,14 @@ public interface NMSBridge { public Entity getVehicle(Entity entity); - public float getXZMovement(Entity entity); - public default Collection getViewingPlayers(Entity entity) { return entity.getTrackedBy(); } public double getWidth(Entity entity); + public float getXZMovement(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 f571003ee..456c7a7ff 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 @@ -320,6 +320,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 990ec837e..021a73254 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 @@ -341,6 +341,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 379288dc9..5b650f0bf 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 @@ -347,6 +347,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 8bffa781e..ea04d2f3b 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 @@ -366,6 +366,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 281518777..c7bd63fcc 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 @@ -411,6 +411,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ(), 1) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 7f365d2a1..ff1f62db0 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 @@ -426,6 +426,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ(), 1) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 ed756a109..3292e589f 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 @@ -439,6 +439,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ(), 1) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 ccd352710..b83a1e863 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 @@ -452,6 +452,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final PathNavigation navigation = getNavigation(entity); + return navigation.createPath(new BlockPos(dest.getX(), dest.getY(), dest.getZ()), 1) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 9841e6fdc..d465d587e 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 @@ -458,6 +458,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final PathNavigation navigation = getNavigation(entity); + return navigation.createPath(new BlockPos(dest.getX(), dest.getY(), dest.getZ()), 1) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity); 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 014780cc5..6f64ebf38 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 @@ -496,6 +496,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final PathNavigation navigation = getNavigation(entity); + return navigation.createPath(BlockPos.containing(dest.getX(), dest.getY(), dest.getZ()), 1) != null; + } + @Override @SuppressWarnings("rawtypes") public Iterable createBundlePacket(List source) { 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 b947fdca5..f4cb72719 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 @@ -507,6 +507,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final PathNavigation navigation = getNavigation(entity); + return navigation.createPath(BlockPos.containing(dest.getX(), dest.getY(), dest.getZ()), 1) != null; + } + @Override @SuppressWarnings("rawtypes") public Iterable createBundlePacket(List source) { diff --git a/v1_21_R3/src/main/java/net/citizensnpcs/nms/v1_21_R3/util/NMSImpl.java b/v1_21_R3/src/main/java/net/citizensnpcs/nms/v1_21_R3/util/NMSImpl.java index c0c76d2b7..b5aba8d69 100644 --- a/v1_21_R3/src/main/java/net/citizensnpcs/nms/v1_21_R3/util/NMSImpl.java +++ b/v1_21_R3/src/main/java/net/citizensnpcs/nms/v1_21_R3/util/NMSImpl.java @@ -494,6 +494,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final PathNavigation navigation = getNavigation(entity); + return navigation.createPath(BlockPos.containing(dest.getX(), dest.getY(), dest.getZ()), 1) != null; + } + @Override @SuppressWarnings("rawtypes") public Iterable createBundlePacket(List source) { 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 9f06a3cb3..527583cfe 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 @@ -301,6 +301,13 @@ public class NMSImpl implements NMSBridge { } } + @Override + public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + final NavigationAbstract navigation = getNavigation(entity); + return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null; + } + @Override public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { Entity handle = getHandle(entity);