From 0e3849ca6376b01a40279c4383c2e35a75460054 Mon Sep 17 00:00:00 2001 From: aPunch Date: Tue, 21 Feb 2012 20:41:09 -0600 Subject: [PATCH] added remove all command --- plugin.yml | 25 +++++++++++++- .../command/command/NPCCommands.java | 34 +++++++++++++++++-- .../citizensnpcs/npc/CitizensNPCManager.java | 13 ++++++- src/net/citizensnpcs/util/ByIdArray.java | 1 - 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/plugin.yml b/plugin.yml index 310b62454..87a3833c9 100644 --- a/plugin.yml +++ b/plugin.yml @@ -7,4 +7,27 @@ commands: citizens: description: Administration commands npc: - description: Basic commands for all NPC-related things \ No newline at end of file + description: Basic commands for all NPC-related things +permissions: + citizens.*: + default: op + children: + citizens.admin: true + citizens.help: true + citizens.npc.*: + children: + citizens.npc.character.*: true + citizens.npc.create: true + citizens.npc.despawn: true + citizens.npc.equip: true + citizens.npc.help: true + citizens.npc.path: true + citizens.npc.remove: true + citizens.npc.remove.all: true + citizens.npc.rename: true + citizens.npc.select: true + citizens.npc.spawn: true + citizens.npc.text: true + citizens.npc.tp: true + citizens.npc.tphere: true + citizens.npc.lookclose: true \ No newline at end of file diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index b618b27ec..145923ee8 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -106,10 +106,38 @@ public class NPCCommands { Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + "."); } - @Command(aliases = { "npc" }, usage = "remove", desc = "Remove an NPC", modifiers = { "remove" }, min = 1, max = 1) + @Command( + aliases = { "npc" }, + usage = "remove (all)", + desc = "Remove an NPC", + modifiers = { "remove" }, + min = 1, + max = 2) + @Requirements public void removeNPC(CommandContext args, Player player, NPC npc) { + if (args.argsLength() == 2) { + if (!player.hasPermission("citizens.npc.remove.all")) { + Messaging.sendError(player, "You don't have permission to execute that command."); + return; + } + npcManager.removeAll(); + Messaging.send(player, "You permanently removed all NPCs."); + return; + } + if (npc == null) { + Messaging.sendError(player, "You must have an NPC selected to execute that command."); + return; + } + if (!npc.getTrait(Owner.class).getOwner().equals(player.getName()) && !player.hasPermission("citizens.admin")) { + Messaging.sendError(player, "You must be the owner of this NPC to execute that command."); + return; + } + if (!player.hasPermission("citizens.npc.remove")) { + Messaging.sendError(player, "You don't have permission to execute that command."); + return; + } npc.remove(); - Messaging.send(player, ChatColor.GREEN + "You permanently removed " + StringHelper.wrap(npc.getName()) + "."); + Messaging.send(player, "You permanently removed " + StringHelper.wrap(npc.getName()) + "."); } @Command( @@ -249,7 +277,7 @@ public class NPCCommands { } @Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = { - "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.look-close") + "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.lookclose") public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) { LookClose trait = npc.getTrait(LookClose.class); trait.toggle(); diff --git a/src/net/citizensnpcs/npc/CitizensNPCManager.java b/src/net/citizensnpcs/npc/CitizensNPCManager.java index 74d23d322..f736f211b 100644 --- a/src/net/citizensnpcs/npc/CitizensNPCManager.java +++ b/src/net/citizensnpcs/npc/CitizensNPCManager.java @@ -115,12 +115,23 @@ public class CitizensNPCManager implements NPCManager { public void remove(NPC npc) { if (npc.isSpawned()) - despawn(npc, true); + npc.getBukkitEntity().remove(); npcs.remove(npc.getId()); saves.getKey("npc").removeKey(String.valueOf(npc.getId())); selected.removeAll(npc.getId()); } + public void removeAll() { + while (iterator().hasNext()) { + NPC npc = iterator().next(); + saves.getKey("npc").removeKey(String.valueOf(npc.getId())); + selected.removeAll(npc.getId()); + if (npc.isSpawned()) + npc.getBukkitEntity().remove(); + iterator().remove(); + } + } + @Override public void selectNPC(Player player, NPC npc) { // Remove existing selection if any diff --git a/src/net/citizensnpcs/util/ByIdArray.java b/src/net/citizensnpcs/util/ByIdArray.java index f9288cfea..56c0623ef 100644 --- a/src/net/citizensnpcs/util/ByIdArray.java +++ b/src/net/citizensnpcs/util/ByIdArray.java @@ -14,7 +14,6 @@ public class ByIdArray implements Iterable { private int lowest = Integer.MAX_VALUE; public ByIdArray() { - // Probably a better way to do this, but setting the capacity to 50 was bad. this(65535); }