Add some error messages for invalid /npc hologram commands

This commit is contained in:
fullwall 2020-07-21 11:15:05 +08:00
parent ac9d7035e1
commit 7081002f1f
3 changed files with 14 additions and 0 deletions

View File

@ -732,16 +732,28 @@ public class NPCCommands {
}
Messaging.send(sender, output);
} else if (args.getString(1).equalsIgnoreCase("set")) {
if (args.argsLength() == 2) {
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);
}
int idx = Math.max(0, args.getInteger(2));
if (idx > trait.getLines().size()) {
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);
}
if (args.argsLength() == 3) {
throw new CommandException(Messages.HOLOGRAM_TEXT_MISSING);
}
trait.setLine(idx, args.getJoinedStrings(3));
Messaging.sendTr(sender, Messages.HOLOGRAM_LINE_SET, idx, args.getJoinedStrings(3));
} else if (args.getString(1).equalsIgnoreCase("add")) {
if (args.argsLength() == 2) {
throw new CommandException(Messages.HOLOGRAM_TEXT_MISSING);
}
trait.addLine(args.getJoinedStrings(2));
Messaging.sendTr(sender, Messages.HOLOGRAM_LINE_ADD, args.getJoinedStrings(2));
} else if (args.getString(1).equalsIgnoreCase("remove")) {
if (args.argsLength() == 2) {
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);
}
int idx = Math.max(0, args.getInteger(2));
if (idx > trait.getLines().size()) {
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);

View File

@ -143,6 +143,7 @@ public class Messages {
public static final String HOLOGRAM_LINE_HEIGHT_SET = "citizens.commands.npc.hologram.line-height-set";
public static final String HOLOGRAM_LINE_REMOVED = "citizens.commands.npc.hologram.line-removed";
public static final String HOLOGRAM_LINE_SET = "citizens.commands.npc.hologram.text-set";
public static final String HOLOGRAM_TEXT_MISSING = "citizens.commands.npc.hologram.text-missing";
public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed";
public static final String HORSE_CHEST_SET = "citizens.commands.npc.horse.chest-set";
public static final String HORSE_CHEST_UNSET = "citizens.commands.npc.horse.chest-unset";

View File

@ -91,6 +91,7 @@ citizens.commands.npc.guardian.elder-unset=[[{0}]] is no longer an elder guardia
citizens.commands.npc.guardian.elder-set=[[{0}]] is now an elder guardian.
citizens.commands.npc.hologram.text-set=Set hologram text line [[{0}]] to [[{1}]].
citizens.commands.npc.hologram.text-removed=Removed hologram text.
citizens.commands.npc.hologram.text-missing=Missing text to add.
citizens.commands.npc.hologram.text-describe-header=[[{0}]]''s hologram text (in bottom-up order):
citizens.commands.npc.hologram.invalid-text-id=Invalid line number.
citizens.commands.npc.hologram.line-height-set=Line height set to [[{0}]].