Cache workaround no longer applicable

This commit is contained in:
fullwall 2012-04-29 17:03:10 +08:00
parent 8c0ebdc65d
commit 2688ae902f
2 changed files with 5 additions and 43 deletions

View File

@ -27,7 +27,6 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
handle.removeFromPlayerMap(getFullName());
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
return handle;
}
@ -37,8 +36,9 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
ItemStack hand = equipper.getItemInHand();
Equipment trait = getTrait(Equipment.class);
int slot = 0;
Material type = hand == null ? Material.AIR : hand.getType();
// First, determine the slot to edit
switch (hand.getType()) {
switch (type) {
case PUMPKIN:
case JACK_O_LANTERN:
case LEATHER_HELMET:
@ -86,16 +86,15 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
if (trait.get(slot) != null && trait.get(slot).getType() != Material.AIR)
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
ItemStack set = hand;
if (set != null && set.getType() != Material.AIR) {
if (type != Material.AIR) {
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
set.setAmount(1);
hand.setAmount(1);
}
trait.set(slot, set);
trait.set(slot, hand);
}
@Override

View File

@ -1,8 +1,6 @@
package net.citizensnpcs.npc.entity;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
@ -10,7 +8,6 @@ import net.citizensnpcs.npc.ai.NPCHandle;
import net.citizensnpcs.npc.network.NPCNetHandler;
import net.citizensnpcs.npc.network.NPCNetworkManager;
import net.citizensnpcs.npc.network.NPCSocket;
import net.citizensnpcs.util.Messaging;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.MinecraftServer;
@ -18,10 +15,6 @@ import net.minecraft.server.NetHandler;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.World;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
@SuppressWarnings("unchecked")
public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
private CitizensNPC npc;
@ -54,18 +47,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
npc.update();
}
@Override
public CraftPlayer getBukkitEntity() {
if (bukkitEntity == null) {
super.getBukkitEntity();
removeFromPlayerMap(name);
// Bukkit uses a map of player names to CraftPlayer instances to
// solve a reconnect issue, so NPC names will conflict with ordinary
// player names. Workaround.
}
return super.getBukkitEntity();
}
public void moveOnCurrentHeading() {
if (this.aZ) {
if (aT()) {
@ -85,24 +66,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
X = yaw; // TODO: this looks jerky
}
public void removeFromPlayerMap(String name) {
if (players != null) {
players.remove(name);
}
}
private static Map<String, CraftPlayer> players;
static {
try {
Field f = CraftEntity.class.getDeclaredField("players");
f.setAccessible(true);
players = (Map<String, CraftPlayer>) f.get(null);
} catch (Exception ex) {
Messaging.log("Unable to fetch player map from CraftEntity: " + ex.getMessage());
}
}
@Override
public NPC getNPC() {
return this.npc;