fix remove all bug

This commit is contained in:
aPunch 2012-03-02 09:58:09 -06:00
parent db2847ebab
commit d0b0815a18
3 changed files with 6 additions and 27 deletions

View File

@ -112,7 +112,6 @@ public class EventListen implements Listener {
return;
}
}
player.openInventory(npc.getInventory());
if (npc.getCharacter() != null)
npc.getCharacter().onRightClick(npc, player);
}

View File

@ -240,6 +240,7 @@ public class NPCCommands {
modifiers = { "remove" },
min = 1,
max = 2)
@Requirements
public void remove(CommandContext args, Player player, NPC npc) throws CommandException {
if (args.argsLength() == 2) {
if (!args.getString(1).equals("all"))

View File

@ -98,42 +98,21 @@ public class CitizensNPCManager implements NPCManager {
}
public void remove(NPC npc) {
if (npc.isSpawned())
npc.getBukkitEntity().remove();
npcs.remove(npc.getId());
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
// Remove metadata from selectors
if (npc.hasMetadata("selectors"))
if (npc.hasMetadata("selectors")) {
for (MetadataValue value : npc.getMetadata("selectors"))
if (Bukkit.getPlayer(value.asString()) != null)
Bukkit.getPlayer(value.asString()).removeMetadata("selected", plugin);
npc.removeMetadata("selectors", plugin);
// TODO: merge this and removeAll();
npc.removeMetadata("selectors", plugin);
}
}
public void removeAll() {
Iterator<NPC> itr = iterator();
while (itr.hasNext()) {
NPC npc = itr.next();
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
// Remove metadata from selectors
if (npc.hasMetadata("selectors")) {
for (MetadataValue value : npc.getMetadata("selectors")) {
if (Bukkit.getPlayer(value.asString()) != null) {
Bukkit.getPlayer(value.asString()).removeMetadata("selected", plugin);
}
}
npc.removeMetadata("selectors", plugin);
}
if (npc.isSpawned()) {
npc.getBukkitEntity().remove();
}
itr.remove();
}
while (iterator().hasNext())
iterator().next().remove();
}
public void selectNPC(Player player, NPC npc) {