Properly validate shulker color in command

This commit is contained in:
fullwall 2018-03-26 12:06:20 +08:00
parent 6c9ba07737
commit 4b95ebb427
4 changed files with 11 additions and 0 deletions

View File

@ -1514,6 +1514,10 @@ public class NPCCommands {
}
if (args.hasValueFlag("color")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
if (color == null) {
Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values()));
return;
}
trait.setColor(color);
Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color));
hasArg = true;

View File

@ -26,6 +26,9 @@ public class ShulkerTrait extends Trait {
@Override
public void run() {
if (color == null) {
color = DyeColor.PURPLE;
}
if (npc.getEntity() instanceof Shulker) {
NMS.setShulkerPeek((Shulker) npc.getEntity(), peek);
NMS.setShulkerColor((Shulker) npc.getEntity(), color);

View File

@ -114,6 +114,7 @@ public class Messages {
public static final String INVALID_RABBIT_TYPE = "citizens.commands.npc.rabbittype.invalid-type";
public static final String INVALID_SCRIPT_FILE = "citizens.commands.npc.script.invalid-file";
public static final String INVALID_SHEEP_COLOR = "citizens.commands.npc.sheep.invalid-color";
public static final String INVALID_SHULKER_COLOR = "citizens.commands.npc.shulker.invalid-color";
public static final String INVALID_SKELETON_TYPE = "citizens.commands.npc.skeletontype.invalid-type";
public static final String INVALID_SOUND = "citizens.commands.npc.sound.invalid-sound";
public static final String INVALID_SPAWN_LOCATION = "citizens.commands.npc.create.invalid-location";

View File

@ -112,9 +112,12 @@ citizens.commands.npc.respawn.delay-set=Respawn delay set to [[{0}]].
citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]].
citizens.commands.npc.select.already-selected=You already have that NPC selected.
citizens.commands.npc.script.invalid-file=Unknown or unavailable script ''[[{0}]]''.
citizens.commands.npc.sheep.color-set=The sheep''s color was set to [[{0}]].
citizens.commands.npc.sheep.invalid-color=Invalid sheep color given. Valid colors are: [[{0}]].
citizens.commands.npc.script.current-scripts=[[{0}]]''s current scripts are [[{1}]].
citizens.commands.npc.shulker.peek-set=[[{0}]]''s peek amount set to [[{1}]].
citizens.commands.npc.shulker.color-set=[[{0}]]''s color set to [[{1}]].
citizens.commands.npc.shulker.invalid-color=Invalid shulker color given. Valid colors are: [[{0}]].
citizens.commands.npc.skin.set=[[{0}]]''s skin name set to [[{1}]].
citizens.commands.npc.skin.missing-skin=A skin name is required.
citizens.commands.npc.skin.cleared=[[{0}]]''s skin name was cleared.