Change /npc wolf to be toggle-based instead of clearing the command and make /npc ocelot throw an exception instead of doing nothing silently

This commit is contained in:
fullwall 2018-03-09 17:28:20 +08:00
parent 5a1eadb64a
commit 01f00960d7
3 changed files with 31 additions and 13 deletions

View File

@ -1038,6 +1038,7 @@ public class NPCCommands {
modifiers = { "ocelot" }, modifiers = { "ocelot" },
min = 1, min = 1,
max = 1, max = 1,
requiresFlags = true,
flags = "sn", flags = "sn",
permission = "citizens.npc.ocelot") permission = "citizens.npc.ocelot")
@Requirements(selected = true, ownership = true, types = { EntityType.OCELOT }) @Requirements(selected = true, ownership = true, types = { EntityType.OCELOT })
@ -1941,36 +1942,39 @@ public class NPCCommands {
desc = "Sets wither modifiers", desc = "Sets wither modifiers",
modifiers = { "wither" }, modifiers = { "wither" },
min = 1, min = 1,
requiresFlags = true,
max = 1, max = 1,
permission = "citizens.npc.wither") permission = "citizens.npc.wither")
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER }) @Requirements(selected = true, ownership = true, types = { EntityType.WITHER })
public void wither(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void wither(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
WitherTrait trait = npc.getTrait(WitherTrait.class); WitherTrait trait = npc.getTrait(WitherTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("charged")) { if (args.hasValueFlag("charged")) {
trait.setCharged(Boolean.valueOf(args.getFlag("charged"))); trait.setCharged(Boolean.valueOf(args.getFlag("charged")));
hasArg = true;
}
if (!hasArg) {
throw new CommandException();
} }
} }
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "wolf (-s(itting) a(ngry) t(amed)) --collar [hex rgb color|name]", usage = "wolf (-s(itting) a(ngry) t(amed) i(nfo)) --collar [hex rgb color|name]",
desc = "Sets wolf modifiers", desc = "Sets wolf modifiers",
modifiers = { "wolf" }, modifiers = { "wolf" },
min = 1, min = 1,
max = 1, max = 1,
requiresFlags = true,
flags = "sat", flags = "sat",
permission = "citizens.npc.wolf") permission = "citizens.npc.wolf")
@Requirements(selected = true, ownership = true, types = EntityType.WOLF) @Requirements(selected = true, ownership = true, types = EntityType.WOLF)
public void wolf(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void wolf(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
WolfModifiers trait = npc.getTrait(WolfModifiers.class); WolfModifiers trait = npc.getTrait(WolfModifiers.class);
trait.setAngry(args.hasFlag('a')); if (args.hasFlag('a')) {
trait.setSitting(args.hasFlag('s')); trait.setAngry(!trait.isAngry());
trait.setTamed(args.hasFlag('t')); }
if (args.hasFlag('s')) {
trait.setSitting(!trait.isSitting());
}
if (args.hasFlag('t')) {
trait.setTamed(!trait.isTamed());
}
if (args.hasValueFlag("collar")) { if (args.hasValueFlag("collar")) {
String unparsed = args.getFlag("collar"); String unparsed = args.getFlag("collar");
DyeColor color = null; DyeColor color = null;
@ -1988,7 +1992,9 @@ public class NPCCommands {
throw new CommandException(Messages.COLLAR_COLOUR_NOT_SUPPORTED, unparsed); throw new CommandException(Messages.COLLAR_COLOUR_NOT_SUPPORTED, unparsed);
trait.setCollarColor(color); trait.setCollarColor(color);
} }
Messaging.sendTr(sender, Messages.WOLF_TRAIT_UPDATED, npc.getName(), args.hasFlag('a'), args.hasFlag('s'), if (args.hasFlag('i')) {
args.hasFlag('t'), trait.getCollarColor().name()); Messaging.sendTr(sender, Messages.WOLF_TRAIT_UPDATED, npc.getName(), args.hasFlag('a'), args.hasFlag('s'),
args.hasFlag('t'), trait.getCollarColor().name());
}
} }
} }

View File

@ -26,6 +26,18 @@ public class WolfModifiers extends Trait {
return collarColor; return collarColor;
} }
public boolean isAngry() {
return angry;
}
public boolean isSitting() {
return sitting;
}
public boolean isTamed() {
return tamed;
}
@Override @Override
public void onSpawn() { public void onSpawn() {
updateModifiers(); updateModifiers();

View File

@ -113,7 +113,7 @@ public class Util {
} }
public static String listValuesPretty(Enum<?>[] values) { public static String listValuesPretty(Enum<?>[] values) {
return "<e>" + Joiner.on("<a>, <e>").join(values).toLowerCase().replace('_', ' '); return "<e>" + Joiner.on("<a>, <e>").join(values).toLowerCase();
} }
public static boolean locationWithinRange(Location current, Location target, double range) { public static boolean locationWithinRange(Location current, Location target, double range) {