Skip to content

Commit

Permalink
Fix an issue with /npc metadata and enum keys, set lookclose target t…
Browse files Browse the repository at this point in the history
…o null if not enabled
  • Loading branch information
fullwall committed Apr 27, 2023
1 parent 7db27a3 commit 6a83009
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/Settings.java
Expand Up @@ -241,7 +241,7 @@ public void loadFromKey(DataKey root) {
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",
Expand Down
10 changes: 7 additions & 3 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -1566,12 +1566,16 @@ public void metadata(CommandContext args, CommandSender sender, NPC npc,
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();
Expand All @@ -1581,7 +1585,7 @@ public void metadata(CommandContext args, CommandSender sender, NPC npc,
} 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();
}
Expand Down
Expand Up @@ -66,9 +66,9 @@ public void add(CommandContext args, CommandSender sender, NPC npc, @Flag("index
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 {
Expand Down
Expand Up @@ -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));
Expand Down
12 changes: 9 additions & 3 deletions main/src/main/java/net/citizensnpcs/trait/LookClose.java
Expand Up @@ -267,8 +267,10 @@ private void randomLook() {

@Override
public void run() {
if (!npc.isSpawned())
if (!npc.isSpawned()) {
lookingAt = null;
return;
}

if (enableRandomLook) {
if (!npc.getNavigator().isNavigating() && lookingAt == null && t <= 0) {
Expand All @@ -278,11 +280,15 @@ public void run() {
}
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();
Expand Down

0 comments on commit 6a83009

Please sign in to comment.