Skip to content

Commit

Permalink
configurable visibility tracker interval (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabsky authored Jan 10, 2025
1 parent 9bde299 commit 0b0cd59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface FancyNpcsConfig {

int getNpcUpdateInterval();

int getNpcUpdateVisibilityInterval();

int getTurnToPlayerDistance();

boolean isTurnToPlayerResetToInitialDirection();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/oliver/fancynpcs/FancyNpcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Please update to the newest version (%s).
visibilityTracker = new VisibilityTracker();

npcThread.scheduleAtFixedRate(new TurnToPlayerTracker(), 0, 50, TimeUnit.MILLISECONDS);
npcThread.scheduleAtFixedRate(visibilityTracker, 0, 1, TimeUnit.SECONDS);
npcThread.scheduleAtFixedRate(visibilityTracker, 0, (config.getNpcUpdateVisibilityInterval() * 50L), TimeUnit.MILLISECONDS);

int autosaveInterval = config.getAutoSaveInterval();
if (config.isEnableAutoSave() && config.getAutoSaveInterval() > 0) {
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 @@ -45,6 +45,11 @@ public class FancyNpcsConfigImpl implements FancyNpcsConfig {
*/
private int npcUpdateInterval;

/**
* The interval at which NPC visibility is updated. In ticks.
*/
private int npcUpdateVisibilityInterval;

/**
* Indicates whether commands should be registered.
* <p>
Expand Down Expand Up @@ -108,6 +113,9 @@ public void reload() {
npcUpdateInterval = (int) ConfigHelper.getOrDefault(config, "npc_update_interval", 30);
config.setInlineComments("npc_update_skin_interval", List.of("The interval at which the NPC is updated (in minutes). Only if the skin or displayName is a placeholder."));

npcUpdateVisibilityInterval = (int) ConfigHelper.getOrDefault(config, "npc_update_visibility_interval", 20);
config.setInlineComments("npc_update_visibility_interval", List.of("The interval at which the NPC visibility is updated (in ticks)."));

registerCommands = (boolean) ConfigHelper.getOrDefault(config, "register_commands", true);
config.setInlineComments("register_commands", List.of("Whether the plugin should register its commands."));

Expand Down Expand Up @@ -173,6 +181,10 @@ public int getNpcUpdateInterval() {
return npcUpdateInterval;
}

public int getNpcUpdateVisibilityInterval() {
return npcUpdateVisibilityInterval;
}

public boolean isRegisterCommands() {
return registerCommands;
}
Expand Down

0 comments on commit 0b0cd59

Please sign in to comment.