Skip to content

Commit

Permalink
Minor fix for player tab list
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 6, 2014
1 parent 69c1cb0 commit 0dea6ed
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/main/java/net/citizensnpcs/EventListen.java
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -129,7 +128,7 @@ public void onChunkUnload(ChunkUnloadEvent event) {
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 + "]");
}
}
}
Expand Down Expand Up @@ -249,7 +248,7 @@ public void onNPCDespawn(NPCDespawnEvent event) {

@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
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java
Expand Up @@ -89,9 +89,9 @@ public BehaviorStatus run() {
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;
Expand All @@ -108,7 +108,7 @@ public BehaviorStatus run() {
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);
Expand Down
Expand Up @@ -230,7 +230,7 @@ private void stopNavigating(CancelReason reason) {
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();
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java
Expand Up @@ -42,6 +42,7 @@
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;
Expand Down Expand Up @@ -293,7 +294,16 @@ private void updatePackets(boolean navigating) {
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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/citizensnpcs/util/NMS.java
Expand Up @@ -176,7 +176,7 @@ public static void flyingMoveLogic(EntityLiving entity, float f, float f1) {

@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);
Expand Down Expand Up @@ -295,6 +295,8 @@ public static void look(org.bukkit.entity.Entity entity, float yaw, float pitch)
@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);
Expand Down

0 comments on commit 0dea6ed

Please sign in to comment.