mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-26 09:11:30 +01:00
Cache workaround no longer applicable
This commit is contained in:
parent
8c0ebdc65d
commit
2688ae902f
@ -27,7 +27,6 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
|||||||
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
|
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
|
||||||
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
|
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
|
||||||
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
|
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
|
||||||
handle.removeFromPlayerMap(getFullName());
|
|
||||||
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@ -37,8 +36,9 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
|||||||
ItemStack hand = equipper.getItemInHand();
|
ItemStack hand = equipper.getItemInHand();
|
||||||
Equipment trait = getTrait(Equipment.class);
|
Equipment trait = getTrait(Equipment.class);
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
|
Material type = hand == null ? Material.AIR : hand.getType();
|
||||||
// First, determine the slot to edit
|
// First, determine the slot to edit
|
||||||
switch (hand.getType()) {
|
switch (type) {
|
||||||
case PUMPKIN:
|
case PUMPKIN:
|
||||||
case JACK_O_LANTERN:
|
case JACK_O_LANTERN:
|
||||||
case LEATHER_HELMET:
|
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)
|
if (trait.get(slot) != null && trait.get(slot).getType() != Material.AIR)
|
||||||
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
|
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), trait.get(slot));
|
||||||
|
|
||||||
ItemStack set = hand;
|
if (type != Material.AIR) {
|
||||||
if (set != null && set.getType() != Material.AIR) {
|
|
||||||
if (hand.getAmount() > 1)
|
if (hand.getAmount() > 1)
|
||||||
hand.setAmount(hand.getAmount() - 1);
|
hand.setAmount(hand.getAmount() - 1);
|
||||||
else
|
else
|
||||||
hand = null;
|
hand = null;
|
||||||
equipper.setItemInHand(hand);
|
equipper.setItemInHand(hand);
|
||||||
set.setAmount(1);
|
hand.setAmount(1);
|
||||||
}
|
}
|
||||||
trait.set(slot, set);
|
trait.set(slot, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
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.NPCNetHandler;
|
||||||
import net.citizensnpcs.npc.network.NPCNetworkManager;
|
import net.citizensnpcs.npc.network.NPCNetworkManager;
|
||||||
import net.citizensnpcs.npc.network.NPCSocket;
|
import net.citizensnpcs.npc.network.NPCSocket;
|
||||||
import net.citizensnpcs.util.Messaging;
|
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.ItemInWorldManager;
|
import net.minecraft.server.ItemInWorldManager;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
@ -18,10 +15,6 @@ import net.minecraft.server.NetHandler;
|
|||||||
import net.minecraft.server.NetworkManager;
|
import net.minecraft.server.NetworkManager;
|
||||||
import net.minecraft.server.World;
|
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 {
|
public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
|
||||||
private CitizensNPC npc;
|
private CitizensNPC npc;
|
||||||
|
|
||||||
@ -54,18 +47,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
|
|||||||
npc.update();
|
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() {
|
public void moveOnCurrentHeading() {
|
||||||
if (this.aZ) {
|
if (this.aZ) {
|
||||||
if (aT()) {
|
if (aT()) {
|
||||||
@ -85,24 +66,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
|
|||||||
X = yaw; // TODO: this looks jerky
|
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
|
@Override
|
||||||
public NPC getNPC() {
|
public NPC getNPC() {
|
||||||
return this.npc;
|
return this.npc;
|
||||||
|
Loading…
Reference in New Issue
Block a user