Add /trc options to the base /npc lookclose command

This commit is contained in:
fullwall 2022-04-16 22:49:20 +08:00
parent b0f1290b58
commit 166aa3d739
4 changed files with 27 additions and 9 deletions

View File

@ -1147,26 +1147,39 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "lookclose --(random|r)look [true|false] --(random|r)pitchrange [min,max] --(random|r)yawrange [min,max]",
usage = "lookclose --range [range] (-r[ealistic looking]) --(random|r)look [true|false] --(random|r)pitchrange [min,max] --(random|r)yawrange [min,max]",
desc = "Toggle whether a NPC will look when a player is near",
modifiers = { "lookclose", "look", "rotate" },
min = 1,
max = 1,
flags = "r",
permission = "citizens.npc.lookclose")
public void lookClose(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean toggle = true;
LookClose trait = npc.getOrAddTrait(LookClose.class);
if (args.hasAnyValueFlag("randomlook", "rlook")) {
boolean enableRandomLook = Boolean.parseBoolean(args.getFlag("randomlook", args.getFlag("rlook")));
npc.getOrAddTrait(LookClose.class).setRandomLook(enableRandomLook);
trait.setRandomLook(enableRandomLook);
Messaging.sendTr(sender,
enableRandomLook ? Messages.LOOKCLOSE_RANDOM_SET : Messages.LOOKCLOSE_RANDOM_STOPPED,
npc.getName());
toggle = false;
}
if (args.hasValueFlag("range")) {
trait.setRange(args.getFlagDouble("range"));
Messaging.sendTr(sender, Messages.LOOKCLOSE_RANGE_SET, args.getFlagDouble("range"));
toggle = false;
}
if (args.hasFlag('r')) {
trait.setRealisticLooking(!trait.useRealisticLooking());
Messaging.sendTr(sender, trait.useRealisticLooking() ? Messages.LOOKCLOSE_REALISTIC_LOOK_SET
: Messages.LOOKCLOSE_REALISTIC_LOOK_UNSET, npc.getName());
toggle = false;
}
if (args.hasAnyValueFlag("randomlookdelay", "rlookdelay")) {
int delay = Integer.parseInt(args.getFlag("randomlookdelay", args.getFlag("rlookdelay")));
delay = Math.max(1, delay);
npc.getOrAddTrait(LookClose.class).setRandomLookDelay(delay);
trait.setRandomLookDelay(delay);
Messaging.sendTr(sender, Messages.LOOKCLOSE_RANDOM_DELAY_SET, npc.getName(), delay);
toggle = false;
}
@ -1177,7 +1190,7 @@ public class NPCCommands {
float min = Float.parseFloat(parts[0]), max = Float.parseFloat(parts[1]);
if (min > max)
throw new IllegalArgumentException();
npc.getOrAddTrait(LookClose.class).setRandomLookPitchRange(min, max);
trait.setRandomLookPitchRange(min, max);
} catch (Exception e) {
throw new CommandException(Messaging.tr(Messages.ERROR_SETTING_LOOKCLOSE_RANGE, flag));
}
@ -1191,7 +1204,7 @@ public class NPCCommands {
float min = Float.parseFloat(parts[0]), max = Float.parseFloat(parts[1]);
if (min > max)
throw new IllegalArgumentException();
npc.getOrAddTrait(LookClose.class).setRandomLookYawRange(min, max);
trait.setRandomLookYawRange(min, max);
} catch (Exception e) {
throw new CommandException(Messaging.tr(Messages.ERROR_SETTING_LOOKCLOSE_RANGE, flag));
}
@ -1199,8 +1212,7 @@ public class NPCCommands {
toggle = false;
}
if (toggle) {
Messaging.sendTr(sender,
npc.getOrAddTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET : Messages.LOOKCLOSE_STOPPED,
Messaging.sendTr(sender, trait.toggle() ? Messages.LOOKCLOSE_SET : Messages.LOOKCLOSE_STOPPED,
npc.getName());
}
}

View File

@ -257,8 +257,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
/**
* Sets the maximum range in blocks to look at other Entities
*/
public void setRange(int range) {
this.range = range;
public void setRange(double d) {
this.range = d;
}
/**

View File

@ -221,6 +221,9 @@ public class Messages {
public static final String LOOKCLOSE_RANDOM_SET = "citizens.commands.npc.lookclose.random-set";
public static final String LOOKCLOSE_RANDOM_STOPPED = "citizens.commands.npc.lookclose.random-stopped";
public static final String LOOKCLOSE_RANDOM_YAW_RANGE_SET = "citizens.commands.npc.lookclose.random-yaw-range-set";
public static final String LOOKCLOSE_RANGE_SET = "citizens.commands.npc.lookclose.range-set";
public static final String LOOKCLOSE_REALISTIC_LOOK_SET = "citizens.commands.npc.lookclose.rl-set";
public static final String LOOKCLOSE_REALISTIC_LOOK_UNSET = "citizens.commands.npc.lookclose.rl-unset";
public static final String LOOKCLOSE_SET = "citizens.commands.npc.lookclose.set";
public static final String LOOKCLOSE_STOPPED = "citizens.commands.npc.lookclose.stopped";
public static final String METADATA_SET = "citizens.commands.npc.metadata.set";

View File

@ -128,6 +128,9 @@ citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable.
citizens.commands.npc.llama.strength-set=Llama strength set to [[{0}]].
citizens.commands.npc.llama.color-set=Llama color set to [[{0}]].
citizens.commands.npc.llama.invalid-color=Invalid llama color given. Valid colors are: [[{0}]].
citizens.commands.npc.lookclose.range-set=[[{0}]]''s lookclose range set to [[{1}]] blocks.
citizens.commands.npc.lookclose.rl-set=[[{0}]] will no longer look through blocks at players.
citizens.commands.npc.lookclose.rl-unset=[[{0}]] will now always look at players, even through blocks.
citizens.commands.npc.lookclose.random-look-delay-set=[[{0}]] will now randomly look every [[{1}]] ticks.
citizens.commands.npc.lookclose.random-pitch-range-set=[[{0}]] will now randomly choose a pitch in the range [{1}].
citizens.commands.npc.lookclose.random-yaw-range-set=[[{0}]] will now randomly choose a yaw in the range [{1}].