Minor fix for player tab list

This commit is contained in:
fullwall 2014-11-06 23:07:23 +08:00
parent 9048d0738a
commit 651fbac979
5 changed files with 20 additions and 9 deletions

View File

@ -25,7 +25,6 @@ import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.trait.Owner; import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.editor.Editor; import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.trait.Controllable; import net.citizensnpcs.trait.Controllable;
import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
@ -129,7 +128,7 @@ public class EventListen implements Listener {
toRespawn.put(coord, npc); toRespawn.put(coord, npc);
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging 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) @EventHandler(ignoreCancelled = true)
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
if (!(event.getPlayer() instanceof NPCHolder)) if (npcRegistry.getNPC(event.getPlayer()) == null)
return; return;
NMS.removeFromServerPlayerList(event.getPlayer()); NMS.removeFromServerPlayerList(event.getPlayer());
// on teleport, player NPCs are added to the server player list. this is // on teleport, player NPCs are added to the server player list. this is

View File

@ -89,9 +89,9 @@ public class BlockBreaker extends BehaviorGoalAdapter {
startDigTick = currentTick; startDigTick = currentTick;
if (entity instanceof NPCHolder) { if (entity instanceof NPCHolder) {
NPC npc = ((NPCHolder) entity).getNPC(); NPC npc = ((NPCHolder) entity).getNPC();
if (!npc.getNavigator().isNavigating()) { if (npc != null && !npc.getNavigator().isNavigating()) {
npc.getNavigator() 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; return BehaviorStatus.RUNNING;
@ -108,7 +108,7 @@ public class BlockBreaker extends BehaviorGoalAdapter {
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier(); float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
if (damage >= 1F) { if (damage >= 1F) {
entity.world.getWorld().getBlockAt(x, y, z) entity.world.getWorld().getBlockAt(x, y, z)
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem())); .breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
return BehaviorStatus.SUCCESS; return BehaviorStatus.SUCCESS;
} }
int modifiedDamage = (int) (damage * 10.0F); int modifiedDamage = (int) (damage * 10.0F);

View File

@ -230,7 +230,7 @@ public class CitizensNavigator implements Navigator, Runnable {
NavigationStuckEvent event = new NavigationStuckEvent(this, action); NavigationStuckEvent event = new NavigationStuckEvent(this, action);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
action = event.getAction(); action = event.getAction();
boolean shouldContinue = action != null ? action.run(npc, this): false; boolean shouldContinue = action != null ? action.run(npc, this) : false;
if (shouldContinue) { if (shouldContinue) {
stationaryTicks = 0; stationaryTicks = 0;
executing.clearCancelReason(); executing.clearCancelReason();

View File

@ -42,6 +42,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer; import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -293,7 +294,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
if (useListName != this.useListName || this.useListName == -1) { if (useListName != this.useListName || this.useListName == -1) {
this.useListName = useListName; 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); NMS.sendPacketsNearby(getBukkitEntity(), current, packets);
} }
} }

View File

@ -176,7 +176,7 @@ public class NMS {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityType type) throws SecurityException, private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityType type) throws SecurityException,
NoSuchMethodException { NoSuchMethodException {
Constructor<?> constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz); Constructor<?> constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz);
if (constructor == null) { if (constructor == null) {
constructor = clazz.getConstructor(World.class); constructor = clazz.getConstructor(World.class);
@ -295,6 +295,8 @@ public class NMS {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void minecartItemLogic(EntityMinecartAbstract minecart) { public static void minecartItemLogic(EntityMinecartAbstract minecart) {
NPC npc = ((NPCHolder) minecart).getNPC(); NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, "")); Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""));
int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0); int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0);
int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0); int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);