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