Skip to content

Commit

Permalink
Add stuck action setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 25, 2023
1 parent 19b917e commit 7db27a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions main/src/main/java/net/citizensnpcs/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ 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(
"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",
"npc.tablist.remove-packet-delay", "1t"),
TALK_CLOSE_TO_NPCS("Whether to talk to NPCs (and therefore bystanders) as well as players",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.ai.TeleportStuckAction;
import net.citizensnpcs.api.astar.pathfinder.ChunkBlockSource;
import net.citizensnpcs.api.command.Command;
Expand Down Expand Up @@ -64,9 +65,10 @@ public void add(CommandContext args, CommandSender sender, NPC npc, @Flag("index
max = 1,
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, false));
if (npc.data().get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, false)) {
npc.data().setPersistent(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, !npc.data()
.get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, !Setting.STUCK_ACTION.asString().contains("teleport")));
if (npc.data().get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION,
!Setting.STUCK_ACTION.asString().contains("teleport"))) {
npc.getNavigator().getDefaultParameters().stuckAction(null);
Messaging.sendTr(sender, Messages.WAYPOINT_TELEPORTING_DISABLED, npc.getName());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public class CitizensNavigator implements Navigator, Runnable {

public CitizensNavigator(NPC npc) {
this.npc = npc;
if (npc.data().get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION, false)) {
if (npc.data().get(NPC.Metadata.DISABLE_DEFAULT_STUCK_ACTION,
!Setting.STUCK_ACTION.asString().contains("teleport"))) {
defaultParams.stuckAction(null);
}
defaultParams.examiner(new SwimmingExaminer(npc));
Expand Down

0 comments on commit 7db27a3

Please sign in to comment.