Add warning for npc select within commands

This commit is contained in:
fullwall 2022-12-27 19:57:48 +08:00
parent 027e4d27a9
commit cdb75dbc96
3 changed files with 17 additions and 12 deletions

View File

@ -107,8 +107,8 @@ public class NPCCommandSelector extends NumericPrompt {
String name = args.getString(1);
List<NPC> possible = Lists.newArrayList();
double range = -1;
if (args.hasValueFlag("r")) {
range = Math.abs(args.getFlagDouble("r"));
if (args.hasValueFlag("range")) {
range = Math.abs(args.getFlagDouble("range"));
}
for (NPC test : npcRegistry) {
if (test.getName().equalsIgnoreCase(name)) {

View File

@ -455,6 +455,9 @@ public class NPCCommands {
if (permissions != null) {
perms.addAll(Arrays.asList(permissions.split(",")));
}
if (command.startsWith("npc select")) {
throw new CommandException("npc select not currently supported within commands. Use --id <id> instead");
}
try {
int id = commands.addCommand(new NPCCommandBuilder(command, hand).addPerms(perms)
.player(args.hasFlag('p') || args.hasFlag('o')).op(args.hasFlag('o')).cooldown(cooldown)
@ -2270,7 +2273,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "select|sel [id|name] (--r range) (--registry [name])",
usage = "select|sel [id|name] (--range range) (--registry [name])",
desc = "Select a NPC with the given ID or name",
modifiers = { "select", "sel" },
min = 1,

View File

@ -355,15 +355,18 @@ public class Util {
Messaging.debug("Running command " + interpolatedCommand + " on NPC " + (npc == null ? -1 : npc.getId())
+ " clicker " + clicker);
}
if (!player) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), interpolatedCommand);
return;
}
boolean wasOp = clicker.isOp();
if (op) {
clicker.setOp(true);
}
try {
if (bungeeServer != null) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
@ -371,12 +374,11 @@ public class Util {
clicker.sendPluginMessage(CitizensAPI.getPlugin(), "BungeeCord", out.toByteArray());
} else {
try {
clicker.chat("/" + interpolatedCommand);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
if (op) {
clicker.setOp(wasOp);