Fix an issue with /npc metadata and enum keys, set lookclose target to null if not enabled

This commit is contained in:
fullwall 2023-04-27 18:55:42 +08:00
parent 7db27a3eee
commit 6a8300980d
5 changed files with 20 additions and 10 deletions

View File

@ -241,7 +241,7 @@ public class Settings {
STORAGE_FILE("storage.file", "saves.yml"),
STORAGE_TYPE("Although technically Citizens can use NBT storage, it is not well tested and YAML is recommended",
"storage.type", "yaml"),
STUCK_ACTION(
DEFAULT_STUCK_ACTION(
"The default action to perform when NPCs are unable to find a path or are stuck in the same block for too long. Supported options are: 'teleport to destination' or 'none'",
"npc.pathfinding.default-stuck-action", "teleport to destination"),
TABLIST_REMOVE_PACKET_DELAY("How long to wait before sending the tablist remove packet",

View File

@ -1566,12 +1566,16 @@ public class NPCCommands {
npc.data().setPersistent(key, metadata);
}
}
Messaging.sendTr(sender, Messages.METADATA_SET, key, args.getString(3));
Messaging.sendTr(sender, Messages.METADATA_SET, enumKey != null ? enumKey : key, args.getString(3));
} else if (command.equals("get")) {
if (args.argsLength() != 3) {
throw new CommandException();
}
sender.sendMessage(enumKey != null ? npc.data().get(enumKey, "null") : npc.data().get(key, "null"));
Object data = enumKey != null ? npc.data().get(enumKey) : npc.data().get(key);
if (data == null) {
data = "null";
}
sender.sendMessage(data.toString());
} else if (command.equals("remove")) {
if (args.argsLength() != 3) {
throw new CommandException();
@ -1581,7 +1585,7 @@ public class NPCCommands {
} else {
npc.data().remove(key);
}
Messaging.sendTr(sender, Messages.METADATA_UNSET, key, npc.getName());
Messaging.sendTr(sender, Messages.METADATA_UNSET, enumKey != null ? enumKey : key, npc.getName());
} else {
throw new CommandUsageException();
}

View File

@ -66,9 +66,9 @@ public class WaypointCommands {
permission = "citizens.waypoints.disableteleport")
public void disableTeleporting(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
npc.data().setPersistent(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, !npc.data()
.get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, !Setting.STUCK_ACTION.asString().contains("teleport")));
.get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, !Setting.DEFAULT_STUCK_ACTION.asString().contains("teleport")));
if (npc.data().get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION,
!Setting.STUCK_ACTION.asString().contains("teleport"))) {
!Setting.DEFAULT_STUCK_ACTION.asString().contains("teleport"))) {
npc.getNavigator().getDefaultParameters().stuckAction(null);
Messaging.sendTr(sender, Messages.WAYPOINT_TELEPORTING_DISABLED, npc.getName());
} else {

View File

@ -68,7 +68,7 @@ public class CitizensNavigator implements Navigator, Runnable {
public CitizensNavigator(NPC npc) {
this.npc = npc;
if (npc.data().get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION,
!Setting.STUCK_ACTION.asString().contains("teleport"))) {
!Setting.DEFAULT_STUCK_ACTION.asString().contains("teleport"))) {
defaultParams.stuckAction(null);
}
defaultParams.examiner(new SwimmingExaminer(npc));

View File

@ -267,8 +267,10 @@ public class LookClose extends Trait implements Toggleable {
@Override
public void run() {
if (!npc.isSpawned())
if (!npc.isSpawned()) {
lookingAt = null;
return;
}
if (enableRandomLook) {
if (!npc.getNavigator().isNavigating() && lookingAt == null && t <= 0) {
@ -278,11 +280,15 @@ public class LookClose extends Trait implements Toggleable {
}
t--;
if (!enabled)
if (!enabled) {
lookingAt = null;
return;
}
if (npc.getNavigator().isNavigating() && disableWhileNavigating())
if (npc.getNavigator().isNavigating() && disableWhileNavigating()) {
lookingAt = null;
return;
}
npc.getEntity().getLocation(NPC_LOCATION);
findNewTarget();