Cleanup, return the navigation destination from NMS.getDestination in case external plugins miss the timing to get it

This commit is contained in:
fullwall 2024-11-01 20:27:16 +08:00
parent 81d54bba57
commit 69acf89ff9
19 changed files with 380 additions and 306 deletions

View File

@ -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)) {
if (event.isCancelled() || !(targeter 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
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;
}
final NPC previousAsNPC = plugin.getNPCRegistry().getNPC(previousTarget);
if (previousAsNPC != null) {
final TrackTargetedByTrait beTargetedBy = previousAsNPC.getOrAddTrait(TrackTargetedByTrait.class);
beTargetedBy.remove(cause.getUniqueId());
}
}
prev.getOrAddTrait(TrackTargetedByTrait.class).remove(targeter.getUniqueId());
}
}

View File

@ -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),

View File

@ -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());

View File

@ -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));

View File

@ -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<UUID> beTargetedBy;
private Set<UUID> 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;
}
}
}

View File

@ -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")) {

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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;

View File

@ -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;
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<org.bukkit.entity.Player> 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();

View File

@ -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;
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<org.bukkit.entity.Player> 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();

View File

@ -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;
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<org.bukkit.entity.Player> 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();

View File

@ -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;
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();

View File

@ -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;
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();

View File

@ -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;
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<org.bukkit.entity.Player> 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;