mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-15 23:26:16 +01:00
Add default poses
This commit is contained in:
parent
c7ab1a8407
commit
0293ac17df
@ -1337,9 +1337,9 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "pose (--save [name]|--assume [name]|--remove [name]) (-a)",
|
||||
usage = "pose (--save [name] (-d)|--assume [name]|--remove [name]|--default [name]) (-a)",
|
||||
desc = "Changes/Saves/Lists NPC's head pose(s)",
|
||||
flags = "a",
|
||||
flags = "ad",
|
||||
modifiers = { "pose" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
@ -1353,10 +1353,16 @@ public class NPCCommands {
|
||||
if (args.getSenderLocation() == null)
|
||||
throw new ServerCommandException();
|
||||
|
||||
if (trait.addPose(args.getFlag("save"), args.getSenderLocation())) {
|
||||
if (trait.addPose(args.getFlag("save"), args.getSenderLocation(), args.hasFlag('d'))) {
|
||||
Messaging.sendTr(sender, Messages.POSE_ADDED);
|
||||
} else
|
||||
throw new CommandException(Messages.POSE_ALREADY_EXISTS, args.getFlag("save"));
|
||||
} else if (args.hasValueFlag("default")) {
|
||||
String pose = args.getFlag("default");
|
||||
if (!trait.hasPose(pose))
|
||||
throw new CommandException(Messages.POSE_MISSING, pose);
|
||||
trait.setDefaultPose(pose);
|
||||
Messaging.sendTr(sender, Messages.DEFAULT_POSE_SET, pose);
|
||||
} else if (args.hasValueFlag("assume")) {
|
||||
String pose = args.getFlag("assume");
|
||||
if (pose.isEmpty())
|
||||
@ -1376,7 +1382,6 @@ public class NPCCommands {
|
||||
trait.describe(sender, args.getInteger(1, 1));
|
||||
}
|
||||
|
||||
// Assume Player's pose
|
||||
if (!args.hasFlag('a'))
|
||||
return;
|
||||
if (args.getSenderLocation() == null)
|
||||
|
@ -153,13 +153,6 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
if (npc.getNavigator().isNavigating() && Setting.DISABLE_LOOKCLOSE_WHILE_NAVIGATING.asBoolean()) {
|
||||
return;
|
||||
}
|
||||
// TODO: remove in a later version, defaults weren't saving properly
|
||||
if (randomPitchRange == null || randomPitchRange.length != 2) {
|
||||
randomPitchRange = new float[] { -10, 0 };
|
||||
}
|
||||
if (randomYawRange == null || randomYawRange.length != 2) {
|
||||
randomYawRange = new float[] { 0, 360 };
|
||||
}
|
||||
npc.getEntity().getLocation(NPC_LOCATION);
|
||||
if (hasInvalidTarget()) {
|
||||
findNewTarget();
|
||||
|
@ -11,6 +11,7 @@ import com.google.common.collect.Maps;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.event.SpawnReason;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
@ -25,6 +26,8 @@ import net.citizensnpcs.util.Util;
|
||||
*/
|
||||
@TraitName("poses")
|
||||
public class Poses extends Trait {
|
||||
@Persist
|
||||
private String defaultPose;
|
||||
private final Map<String, Pose> poses = Maps.newHashMap();
|
||||
|
||||
public Poses() {
|
||||
@ -37,11 +40,23 @@ public class Poses extends Trait {
|
||||
* @return whether the pose has already been added
|
||||
*/
|
||||
public boolean addPose(String name, Location location) {
|
||||
return addPose(name, location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link Pose}
|
||||
*
|
||||
* @return whether the pose has already been added
|
||||
*/
|
||||
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))
|
||||
return false;
|
||||
poses.put(name, newPose);
|
||||
if (isDefault) {
|
||||
defaultPose = name;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,12 +97,7 @@ public class Poses extends Trait {
|
||||
}
|
||||
|
||||
public Pose getPose(String name) {
|
||||
for (Pose pose : poses.values()) {
|
||||
if (pose.getName().equalsIgnoreCase(name)) {
|
||||
return pose;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return poses.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean hasPose(String pose) {
|
||||
@ -100,7 +110,7 @@ public class Poses extends Trait {
|
||||
for (DataKey sub : key.getRelative("list").getIntegerSubKeys())
|
||||
try {
|
||||
String[] parts = sub.getString("").split(";");
|
||||
poses.put(parts[0], new Pose(parts[0], Float.valueOf(parts[1]), Float.valueOf(parts[2])));
|
||||
poses.put(parts[0].toLowerCase(), new Pose(parts[0], Float.valueOf(parts[1]), Float.valueOf(parts[2])));
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.logTr(Messages.SKIPPING_INVALID_POSE, sub.name(), e.getMessage());
|
||||
}
|
||||
@ -110,6 +120,16 @@ public class Poses extends Trait {
|
||||
return poses.remove(pose.toLowerCase()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!hasPose(defaultPose))
|
||||
return;
|
||||
if (!npc.getNavigator().isNavigating()
|
||||
&& (!npc.hasTrait(LookClose.class) || npc.getTrait(LookClose.class).canSeeTarget())) {
|
||||
assumePose(defaultPose);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.removeKey("list");
|
||||
@ -119,4 +139,8 @@ public class Poses extends Trait {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultPose(String pose) {
|
||||
this.defaultPose = pose;
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ public class Messages {
|
||||
public static final String CURRENT_SCRIPTS = "citizens.commands.npc.script.current-scripts";
|
||||
public static final String CURRENT_WAYPOINT_PROVIDER = "citizens.waypoints.current-provider";
|
||||
public static final String DATABASE_CONNECTION_FAILED = "citizens.notifications.database-connection-failed";
|
||||
public static final String DEFAULT_POSE_SET = "citizens.commands.npc.pose.default-pose-set";
|
||||
public static final String DELAY_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.delay.prompt";
|
||||
public static final String ELDER_SET = "citizens.commands.npc.guardian.elder-set";
|
||||
public static final String ELDER_UNSET = "citizens.commands.npc.guardian.elder-unset";
|
||||
|
@ -149,6 +149,7 @@ citizens.commands.npc.pose.added=Pose added.
|
||||
citizens.commands.npc.pose.already-exists=The pose [[{0}]] already exists.
|
||||
citizens.commands.npc.pose.invalid-name=Invalid pose name.
|
||||
citizens.commands.npc.pose.missing=The pose [[{0}]] does not exist.
|
||||
citizens.commands.npc.pose.default-pose-set=Default pose set to [[{0}]].
|
||||
citizens.commands.npc.pose.removed=Pose removed.
|
||||
citizens.commands.npc.powered.set=[[{0}]] will now be powered.
|
||||
citizens.commands.npc.powered.stopped=[[{0}]] will no longer be powered.
|
||||
|
Loading…
Reference in New Issue
Block a user