mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-26 19:18:37 +01:00
added remove all command
This commit is contained in:
parent
1d67c6ffcf
commit
0e3849ca63
23
plugin.yml
23
plugin.yml
@ -8,3 +8,26 @@ commands:
|
|||||||
description: Administration commands
|
description: Administration commands
|
||||||
npc:
|
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
|
@ -106,10 +106,38 @@ public class NPCCommands {
|
|||||||
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
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) {
|
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();
|
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(
|
@Command(
|
||||||
@ -249,7 +277,7 @@ public class NPCCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = {
|
@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) {
|
public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) {
|
||||||
LookClose trait = npc.getTrait(LookClose.class);
|
LookClose trait = npc.getTrait(LookClose.class);
|
||||||
trait.toggle();
|
trait.toggle();
|
||||||
|
@ -115,12 +115,23 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
|
|
||||||
public void remove(NPC npc) {
|
public void remove(NPC npc) {
|
||||||
if (npc.isSpawned())
|
if (npc.isSpawned())
|
||||||
despawn(npc, true);
|
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()));
|
||||||
selected.removeAll(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
|
@Override
|
||||||
public void selectNPC(Player player, NPC npc) {
|
public void selectNPC(Player player, NPC npc) {
|
||||||
// Remove existing selection if any
|
// Remove existing selection if any
|
||||||
|
@ -14,7 +14,6 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
private int lowest = Integer.MAX_VALUE;
|
private int lowest = Integer.MAX_VALUE;
|
||||||
|
|
||||||
public ByIdArray() {
|
public ByIdArray() {
|
||||||
// Probably a better way to do this, but setting the capacity to 50 was bad.
|
|
||||||
this(65535);
|
this(65535);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user