Add /npc pose [yaw] [pitch] --save [name]

This commit is contained in:
fullwall 2023-04-25 22:23:41 +08:00
parent 0b82ee214e
commit c1ae7aa0d3
3 changed files with 14 additions and 30 deletions

View File

@ -432,7 +432,7 @@ public class NPCCommands {
permission = "citizens.npc.collidable")
@Requirements(ownership = true, selected = true)
public void collidable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
npc.data().setPersistent(NPC.Metadata.COLLIDABLE, !npc.data().get(NPC.Metadata.COLLIDABLE, false));
npc.data().setPersistent(NPC.Metadata.COLLIDABLE, !npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected()));
Messaging.sendTr(sender,
npc.data().<Boolean> get(NPC.Metadata.COLLIDABLE) ? Messages.COLLIDABLE_SET : Messages.COLLIDABLE_UNSET,
npc.getName());
@ -2156,7 +2156,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "pose (--save [name] (-d) | --mirror [name] (-d) | --assume [name] | --remove [name] | --default [name]) (-a)",
usage = "pose (--save [name] (-d) | --mirror [name] (-d) | --assume [name] | --remove [name] | --default [name]) (yaw) (pitch) (-a)",
desc = "Manage NPC poses",
flags = "ad",
modifiers = { "pose" },
@ -2165,14 +2165,18 @@ public class NPCCommands {
permission = "citizens.npc.pose")
public void pose(CommandContext args, CommandSender sender, NPC npc, @Flag("save") String save,
@Flag("mirror") String mirror, @Flag("assume") String assume, @Flag("remove") String remove,
@Flag("default") String defaultPose) throws CommandException {
@Flag("default") String defaultPose, @Arg(1) Float yaw, @Arg(2) Float pitch) throws CommandException {
Poses trait = npc.getOrAddTrait(Poses.class);
if (save != null) {
if (save.isEmpty())
throw new CommandException(Messages.INVALID_POSE_NAME);
if (args.getSenderLocation() == null)
throw new ServerCommandException();
Location loc = npc.getStoredLocation();
if (yaw != null) {
loc.setYaw(yaw);
}
if (pitch != null) {
loc.setPitch(pitch);
}
if (trait.addPose(save, npc.getStoredLocation(), args.hasFlag('d'))) {
Messaging.sendTr(sender, Messages.POSE_ADDED);

View File

@ -51,7 +51,7 @@ public class Poses extends Trait {
public boolean addPose(String name, Location location, boolean isDefault) {
name = name.toLowerCase();
Pose newPose = new Pose(name, location.getPitch(), location.getYaw());
if (poses.containsValue(newPose) || poses.containsKey(name))
if (poses.containsKey(name))
return false;
poses.put(name, newPose);
if (isDefault) {
@ -86,10 +86,11 @@ public class Poses extends Trait {
public void describe(CommandSender sender, int page) throws CommandException {
Paginator paginator = new Paginator().header("Pose").console(sender instanceof ConsoleCommandSender);
paginator.addLine("<e>Key: <a>ID <b>Name <c>Pitch/Yaw");
paginator.addLine("<green>ID <yellow>Name <red>Pitch/Yaw");
int i = 0;
for (Pose pose : poses.values()) {
String line = "<a>" + i + "<b> " + pose.getName() + "<c> " + pose.getPitch() + "/" + pose.getYaw();
String line = "<green>" + i + "<yellow> " + pose.getName() + "<red> " + pose.getPitch() + " "
+ pose.getYaw();
paginator.addLine(line);
i++;
}

View File

@ -1,8 +1,5 @@
package net.citizensnpcs.util;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* A named head yaw/pitch
*/
@ -17,19 +14,6 @@ public class Pose {
this.name = name;
}
@Override
public boolean equals(Object object) {
if (object == null)
return false;
if (object == this)
return true;
if (object.getClass() != getClass())
return false;
Pose op = (Pose) object;
return new EqualsBuilder().append(name, op.getName()).isEquals();
}
public String getName() {
return name;
}
@ -42,11 +26,6 @@ public class Pose {
return yaw;
}
@Override
public int hashCode() {
return new HashCodeBuilder(13, 21).append(name).toHashCode();
}
public String stringValue() {
return name + ';' + pitch + ';' + yaw;
}