mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-27 11:37:42 +01:00
Command features
This commit is contained in:
parent
1e3d3e5754
commit
f467e54124
@ -19,15 +19,18 @@
|
||||
package net.citizensnpcs.command;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class CommandContext {
|
||||
protected String[] args;
|
||||
protected Set<Character> flags = new HashSet<Character>();
|
||||
protected final Map<String, String> valueFlags = Maps.newHashMap();
|
||||
protected final Set<Character> flags = new HashSet<Character>();
|
||||
|
||||
public CommandContext(String args) {
|
||||
this(args.split(" "));
|
||||
@ -38,6 +41,31 @@ public class CommandContext {
|
||||
for (; i < args.length; i++) {
|
||||
if (args[i].length() == 0) {
|
||||
// Ignore this
|
||||
} else if (args[i].charAt(0) == '\'' || args[i].charAt(0) == '"') {
|
||||
char quote = args[i].charAt(0);
|
||||
for (int inner = i + 1; inner < args.length; inner++) {
|
||||
if (args[inner].isEmpty())
|
||||
continue;
|
||||
String test = args[inner].trim();
|
||||
args[i] += " " + test;
|
||||
args[inner] = "";
|
||||
if (test.charAt(test.length() - 1) == quote) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (i + 1 < args.length && args[i].length() > 2 && args[i].matches("^--[a-zA-Z]+$")) {
|
||||
int inner = i;
|
||||
while (args[inner++].isEmpty()) {
|
||||
if (inner == args.length) {
|
||||
inner = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (inner != -1) {
|
||||
valueFlags.put(args[i].replaceFirst("--", ""), args[inner]);
|
||||
args[i] = "";
|
||||
args[inner] = "";
|
||||
}
|
||||
} else if (args[i].charAt(0) == '-' && args[i].matches("^-[a-zA-Z]+$")) {
|
||||
for (int k = 1; k < args[i].length(); k++)
|
||||
flags.add(args[i].charAt(k));
|
||||
|
@ -32,13 +32,8 @@ public class NPCCommands {
|
||||
this.characterManager = characterManager;
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "create [name] [type] (character)",
|
||||
desc = "Create a new NPC",
|
||||
modifiers = { "create" },
|
||||
min = 3,
|
||||
max = 4)
|
||||
@Command(aliases = { "npc" }, usage = "create [name] [type] (character)", desc = "Create a new NPC",
|
||||
modifiers = { "create" }, min = 3, max = 4)
|
||||
@Permission("npc.create")
|
||||
@Requirements
|
||||
public void createNPC(CommandContext args, Player player, NPC npc) {
|
||||
@ -77,13 +72,8 @@ public class NPCCommands {
|
||||
Messaging.send(player, successMsg);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "despawn",
|
||||
desc = "Despawn an NPC",
|
||||
modifiers = { "despawn" },
|
||||
min = 1,
|
||||
max = 1)
|
||||
@Command(aliases = { "npc" }, usage = "despawn", desc = "Despawn an NPC", modifiers = { "despawn" }, min = 1,
|
||||
max = 1)
|
||||
@Permission("npc.despawn")
|
||||
public void despawnNPC(CommandContext args, Player player, NPC npc) {
|
||||
npc.getTrait(Spawned.class).setSpawned(false);
|
||||
@ -91,13 +81,8 @@ public class NPCCommands {
|
||||
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "select [id]",
|
||||
desc = "Select an NPC",
|
||||
modifiers = { "select" },
|
||||
min = 2,
|
||||
max = 2)
|
||||
@Command(aliases = { "npc" }, usage = "select [id]", desc = "Select an NPC", modifiers = { "select" }, min = 2,
|
||||
max = 2)
|
||||
@Permission("npc.select")
|
||||
@Requirements(ownership = true)
|
||||
public void selectNPC(CommandContext args, Player player, NPC npc) {
|
||||
@ -114,13 +99,8 @@ public class NPCCommands {
|
||||
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "spawn [id]",
|
||||
desc = "Spawn an existing NPC",
|
||||
modifiers = { "spawn" },
|
||||
min = 2,
|
||||
max = 2)
|
||||
@Command(aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" },
|
||||
min = 2, max = 2)
|
||||
@Permission("npc.spawn")
|
||||
@Requirements
|
||||
public void spawnNPC(CommandContext args, Player player, NPC npc) {
|
||||
@ -147,39 +127,24 @@ public class NPCCommands {
|
||||
+ " is already spawned at another location. Use '/npc tphere' to teleport the NPC to your location.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "tphere",
|
||||
desc = "Teleport an NPC to your location",
|
||||
modifiers = { "tphere" },
|
||||
min = 1,
|
||||
max = 1)
|
||||
@Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport an NPC to your location",
|
||||
modifiers = { "tphere" }, min = 1, max = 1)
|
||||
@Permission("npc.tphere")
|
||||
public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) {
|
||||
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
||||
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "tp",
|
||||
desc = "Teleport to an NPC",
|
||||
modifiers = { "tp", "teleport" },
|
||||
min = 1,
|
||||
max = 1)
|
||||
@Command(aliases = { "npc" }, usage = "tp", desc = "Teleport to an NPC", modifiers = { "tp", "teleport" }, min = 1,
|
||||
max = 1)
|
||||
@Permission("npc.tp")
|
||||
public void teleportToNPC(CommandContext args, Player player, NPC npc) {
|
||||
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
||||
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "lookclose",
|
||||
desc = "Toggle an NPC's look-close state",
|
||||
modifiers = { "lookclose", "look", "rotate" },
|
||||
min = 1,
|
||||
max = 1)
|
||||
@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")
|
||||
public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) {
|
||||
npc.getTrait(LookClose.class).setLookClose(!npc.getTrait(LookClose.class).shouldLookClose());
|
||||
|
Loading…
Reference in New Issue
Block a user