From 651fbac9797ac7b70f0d52f44f6d3549379265db Mon Sep 17 00:00:00 2001 From: fullwall Date: Thu, 6 Nov 2014 23:07:23 +0800 Subject: [PATCH] Minor fix for player tab list --- src/main/java/net/citizensnpcs/EventListen.java | 5 ++--- .../java/net/citizensnpcs/npc/ai/BlockBreaker.java | 6 +++--- .../net/citizensnpcs/npc/ai/CitizensNavigator.java | 2 +- .../net/citizensnpcs/npc/entity/EntityHumanNPC.java | 12 +++++++++++- src/main/java/net/citizensnpcs/util/NMS.java | 4 +++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index f8ea27e55..4ce3082aa 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -25,7 +25,6 @@ import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.trait.trait.Owner; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.editor.Editor; -import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.trait.Controllable; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.util.Messages; @@ -129,7 +128,7 @@ public class EventListen implements Listener { toRespawn.put(coord, npc); if (Messaging.isDebugging()) { Messaging - .debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]"); + .debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]"); } } } @@ -249,7 +248,7 @@ public class EventListen implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { - if (!(event.getPlayer() instanceof NPCHolder)) + if (npcRegistry.getNPC(event.getPlayer()) == null) return; NMS.removeFromServerPlayerList(event.getPlayer()); // on teleport, player NPCs are added to the server player list. this is diff --git a/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java b/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java index d1a8c0a0e..0387fa180 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java +++ b/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java @@ -89,9 +89,9 @@ public class BlockBreaker extends BehaviorGoalAdapter { startDigTick = currentTick; if (entity instanceof NPCHolder) { NPC npc = ((NPCHolder) entity).getNPC(); - if (!npc.getNavigator().isNavigating()) { + if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator() - .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); } } return BehaviorStatus.RUNNING; @@ -108,7 +108,7 @@ public class BlockBreaker extends BehaviorGoalAdapter { float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier(); if (damage >= 1F) { entity.world.getWorld().getBlockAt(x, y, z) - .breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem())); + .breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem())); return BehaviorStatus.SUCCESS; } int modifiedDamage = (int) (damage * 10.0F); diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index dd9e37542..d781faacf 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -230,7 +230,7 @@ public class CitizensNavigator implements Navigator, Runnable { NavigationStuckEvent event = new NavigationStuckEvent(this, action); Bukkit.getPluginManager().callEvent(event); action = event.getAction(); - boolean shouldContinue = action != null ? action.run(npc, this): false; + boolean shouldContinue = action != null ? action.run(npc, this) : false; if (shouldContinue) { stationaryTicks = 0; executing.clearCancelReason(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 762d03386..960e28da9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -42,6 +42,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_7_R4.CraftServer; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.entity.Player; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; @@ -293,7 +294,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { if (useListName != this.useListName || this.useListName == -1) { this.useListName = useListName; } - NMS.sendToOnline(getListPacket(removeFromPlayerList)); + boolean sendListPacket = true; + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.getName().equalsIgnoreCase(getName())) { + sendListPacket = false; + break; + } + } + if (sendListPacket) { + NMS.sendToOnline(getListPacket(removeFromPlayerList)); + } NMS.sendPacketsNearby(getBukkitEntity(), current, packets); } } diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index 118171cd4..496b629a6 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -176,7 +176,7 @@ public class NMS { @SuppressWarnings("deprecation") private static Constructor getCustomEntityConstructor(Class clazz, EntityType type) throws SecurityException, - NoSuchMethodException { + NoSuchMethodException { Constructor constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz); if (constructor == null) { constructor = clazz.getConstructor(World.class); @@ -295,6 +295,8 @@ public class NMS { @SuppressWarnings("deprecation") public static void minecartItemLogic(EntityMinecartAbstract minecart) { NPC npc = ((NPCHolder) minecart).getNPC(); + if (npc == null) + return; Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, "")); int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0); int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);