Skip to content

Commit

Permalink
configurable turn_to_player direction reset (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabsky authored Jan 10, 2025
1 parent ca5bc11 commit d593e00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface FancyNpcsConfig {

int getTurnToPlayerDistance();

boolean isTurnToPlayerResetToInitialDirection();

int getVisibilityDistance();

int getRemoveNpcsFromPlayerlistDelay();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/oliver/fancynpcs/FancyNpcsConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class FancyNpcsConfigImpl implements FancyNpcsConfig {
*/
private int turnToPlayerDistance;

/**
* Indicates whether direction of NPC should be reset when leaving their range.
*/
private boolean turnToPlayerResetToInitialDirection;

/**
* The distance at which NPCs are visible.
*/
Expand Down Expand Up @@ -109,6 +114,9 @@ public void reload() {
turnToPlayerDistance = (int) ConfigHelper.getOrDefault(config, "turn_to_player_distance", 5);
config.setInlineComments("turn_to_player_distance", List.of("The distance at which NPCs turn to the player."));

turnToPlayerResetToInitialDirection = (boolean) ConfigHelper.getOrDefault(config, "turn_to_player_reset_to_initial_direction", false);
config.setInlineComments("turn_to_player_reset_to_initial_direction", List.of("Whether direction of NPC should be reset when leaving their turning range."));

visibilityDistance = (int) ConfigHelper.getOrDefault(config, "visibility_distance", 20);
config.setInlineComments("visibility_distance", List.of("The distance at which NPCs are visible."));

Expand Down Expand Up @@ -169,6 +177,10 @@ public boolean isRegisterCommands() {
return registerCommands;
}

public boolean isTurnToPlayerResetToInitialDirection() {
return turnToPlayerResetToInitialDirection;
}

public int getTurnToPlayerDistance() {
return turnToPlayerDistance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void run() {
// Updating state if changed.
} else if (npcData.isTurnToPlayer() && npc.getIsLookingAtPlayer().getOrDefault(player.getUniqueId(), false)) {
npc.getIsLookingAtPlayer().put(player.getUniqueId(), false);
// Resetting to initial direction, if configured.
if (FancyNpcs.getInstance().getFancyNpcConfig().isTurnToPlayerResetToInitialDirection()) {
npc.move(player, false);
}
// Calling NpcStopLookingEvent from the main thread.
FancyNpcs.getInstance().getScheduler().runTask(null, () -> {
Bukkit.getPluginManager().callEvent(new NpcStopLookingEvent(npc, player));
Expand Down

0 comments on commit d593e00

Please sign in to comment.