added remove all command

This commit is contained in:
aPunch 2012-02-21 20:41:09 -06:00
parent b280e918ec
commit 185b2a05b0
4 changed files with 67 additions and 6 deletions

View File

@ -7,4 +7,27 @@ commands:
citizens:
description: Administration commands
npc:
description: Basic commands for all NPC-related things
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

View File

@ -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, "<a>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, "<a>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();

View File

@ -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

View File

@ -14,7 +14,6 @@ public class ByIdArray<T> implements Iterable<T> {
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);
}