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); String name = args.getString(1);
List<NPC> possible = Lists.newArrayList(); List<NPC> possible = Lists.newArrayList();
double range = -1; double range = -1;
if (args.hasValueFlag("r")) { if (args.hasValueFlag("range")) {
range = Math.abs(args.getFlagDouble("r")); range = Math.abs(args.getFlagDouble("range"));
} }
for (NPC test : npcRegistry) { for (NPC test : npcRegistry) {
if (test.getName().equalsIgnoreCase(name)) { if (test.getName().equalsIgnoreCase(name)) {

View File

@ -455,6 +455,9 @@ public class NPCCommands {
if (permissions != null) { if (permissions != null) {
perms.addAll(Arrays.asList(permissions.split(","))); 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 { try {
int id = commands.addCommand(new NPCCommandBuilder(command, hand).addPerms(perms) int id = commands.addCommand(new NPCCommandBuilder(command, hand).addPerms(perms)
.player(args.hasFlag('p') || args.hasFlag('o')).op(args.hasFlag('o')).cooldown(cooldown) .player(args.hasFlag('p') || args.hasFlag('o')).op(args.hasFlag('o')).cooldown(cooldown)
@ -2270,7 +2273,7 @@ public class NPCCommands {
@Command( @Command(
aliases = { "npc" }, 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", desc = "Select a NPC with the given ID or name",
modifiers = { "select", "sel" }, modifiers = { "select", "sel" },
min = 1, min = 1,

View File

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