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; return;
} }
} }
player.openInventory(npc.getInventory());
if (npc.getCharacter() != null) if (npc.getCharacter() != null)
npc.getCharacter().onRightClick(npc, player); npc.getCharacter().onRightClick(npc, player);
} }

View File

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

View File

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