Add /npc command hideerrors

This commit is contained in:
fullwall 2021-11-19 23:32:28 +08:00
parent 78824a341e
commit 968f3fd68b
4 changed files with 26 additions and 0 deletions

View File

@ -394,6 +394,10 @@ public class NPCCommands {
} else if (args.getString(1).equalsIgnoreCase("expcost")) {
commands.setExperienceCost((float) args.getDouble(2));
Messaging.sendTr(sender, Messages.COMMAND_EXPERIENCE_COST_SET, args.getDouble(2));
} else if (args.getString(1).equalsIgnoreCase("hideerrors")) {
commands.setHideErrorMessages(!commands.isHideErrorMessages());
Messaging.sendTr(sender, commands.isHideErrorMessages() ? Messages.COMMAND_HIDE_ERROR_MESSAGES_SET
: Messages.COMMAND_HIDE_ERROR_MESSAGES_UNSET);
} else if (args.getString(1).equalsIgnoreCase("random")) {
commands.setExecutionMode(
commands.getExecutionMode() == ExecutionMode.RANDOM ? ExecutionMode.LINEAR : ExecutionMode.RANDOM);

View File

@ -68,6 +68,8 @@ public class CommandTrait extends Trait {
@Persist
private final Map<String, Long> globalCooldowns = Maps.newHashMap();
@Persist
private boolean hideErrorMessages;
@Persist
private List<ItemStack> itemRequirements = Lists.newArrayList();
@Persist
private final List<String> temporaryPermissions = Lists.newArrayList();
@ -296,12 +298,19 @@ public class CommandTrait extends Trait {
return commands.containsKey(String.valueOf(id));
}
public boolean isHideErrorMessages() {
return hideErrorMessages;
}
public void removeCommandById(int id) {
commands.remove(String.valueOf(id));
}
private void sendErrorMessage(Player player, CommandTraitMessages msg, Function<String, String> transform,
Object... objects) {
if (hideErrorMessages) {
return;
}
Set<CommandTraitMessages> sent = executionErrors.get(player.getUniqueId().toString());
if (sent != null) {
if (sent.contains(msg))
@ -329,6 +338,10 @@ public class CommandTrait extends Trait {
this.experienceCost = experienceCost;
}
public void setHideErrorMessages(boolean hide) {
this.hideErrorMessages = hide;
}
public void setTemporaryPermissions(List<String> permissions) {
temporaryPermissions.clear();
temporaryPermissions.addAll(permissions);
@ -350,6 +363,11 @@ public class CommandTrait extends Trait {
}
}
public enum ErrorHandling {
ERROR_MESSAGE,
RUN_ANYWAY;
}
public enum ExecutionMode {
LINEAR,
RANDOM,

View File

@ -59,6 +59,8 @@ public class Messages {
public static final String COMMAND_COST_SET = "citizens.commands.npc.command.cost-set";
public static final String COMMAND_EXPERIENCE_COST_SET = "citizens.commands.npc.command.experience-cost-set";
public static final String COMMAND_HELP_HEADER = "citizens.commands.help.header";
public static final String COMMAND_HIDE_ERROR_MESSAGES_SET = "citizens.commands.npc.command.hide-error-messages-set";
public static final String COMMAND_HIDE_ERROR_MESSAGES_UNSET = "citizens.commands.npc.command.hide-error-messages-unset";
public static final String COMMAND_INVALID_MOBTYPE = "citizens.commands.invalid-mobtype";
public static final String COMMAND_LEFT_HAND_HEADER = "citizens.commands.npc.command.left-hand-header";
public static final String COMMAND_MISSING = "citizens.commands.help.command-missing";

View File

@ -51,6 +51,8 @@ citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities.
citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities.
citizens.commands.npc.command.none-added=No commands have been added.
citizens.commands.npc.command.cost-set=Set cost per click to [[{0}]].
citizens.commands.npc.command.hide-error-messages-set=Now hiding error messages.
citizens.commands.npc.command.hide-error-messages-unset=No longer hiding error messages.
citizens.commands.npc.command.experience-cost-set=Set experience cost per click to [[{0}]].
citizens.commands.npc.command.left-hand-header=Commands to run on [[left click]]:
citizens.commands.npc.command.right-hand-header=Commands to run on [[right click]]: