fancynpcs: Fix placeholder skins not refreshing (#89)

* fancynpcs: fix placeholder skins not refreshing

* fancynpcs: fix comment not being generated for `npc_update_interval` option

* fancynpcs: apply requested changes
This commit is contained in:
Michał
2025-07-26 13:15:48 +02:00
committed by GitHub
parent c2d40a76aa
commit bef476a6ea
2 changed files with 29 additions and 17 deletions

View File

@@ -298,25 +298,37 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
int npcUpdateInterval = config.getNpcUpdateInterval(); int npcUpdateInterval = config.getNpcUpdateInterval();
npcThread.scheduleAtFixedRate(() -> { npcThread.scheduleAtFixedRate(() -> {
List<Npc> npcs = new ArrayList<>(npcManager.getAllNpcs()); final List<Npc> npcs = new ArrayList<>(npcManager.getAllNpcs());
for (Npc npc : npcs) { for (final Npc npc : npcs) {
String skinID = npc.getData().getSkinData().getIdentifier(); try {
boolean skinUpdated = npc.getData().getSkinData() != null && boolean shouldUpdate = false;
!skinID.isEmpty() &&
SkinUtils.isPlaceholder(skinID);
boolean displayNameUpdated = npc.getData().getDisplayName() != null && if (npc.getData().getDisplayName() != null && !npc.getData().getDisplayName().isBlank() && SkinUtils.isPlaceholder(npc.getData().getDisplayName())) {
!npc.getData().getDisplayName().isEmpty() && shouldUpdate = true;
SkinUtils.isPlaceholder(npc.getData().getDisplayName()); }
if (skinUpdated || displayNameUpdated) { if (npc.getData().getSkinData() != null) {
SkinData skinData = skinManager.getByIdentifier(skinID, npc.getData().getSkinData().getVariant()); final String skinID = npc.getData().getSkinData().getIdentifier();
skinData.setIdentifier(skinID); if (!skinID.isEmpty() && SkinUtils.isPlaceholder(skinID)) {
npc.getData().setSkinData(skinData); final SkinData skinData = skinManager.getByIdentifier(skinID, npc.getData().getSkinData().getVariant());
skinData.setIdentifier(skinID);
npc.getData().setSkinData(skinData);
shouldUpdate = true;
}
}
npc.removeForAll(); if (shouldUpdate) {
npc.create(); npc.removeForAll();
npc.spawnForAll(); npc.create();
npc.spawnForAll();
}
} catch (final Throwable thr) {
fancyLogger.error(
"An error occurred while updating '" + npc.getData().getName() + "' NPC."
+ System.lineSeparator() + " (1) " + thr.getClass().getName() + ": " + thr.getMessage()
+ (thr.getCause() != null ? System.lineSeparator() + " (2) " + thr.getCause().getClass().getName() + ": " + thr.getCause().getMessage() : "")
);
fancyLogger.error(thr);
} }
} }
}, 30, npcUpdateInterval, TimeUnit.SECONDS); }, 30, npcUpdateInterval, TimeUnit.SECONDS);

View File

@@ -116,7 +116,7 @@ public class FancyNpcsConfigImpl implements FancyNpcsConfig {
config.setInlineComments("autosave_interval", List.of("The interval at which autosave is performed in minutes.")); config.setInlineComments("autosave_interval", List.of("The interval at which autosave is performed in minutes."));
npcUpdateInterval = (int) ConfigHelper.getOrDefault(config, "npc_update_interval", 60); npcUpdateInterval = (int) ConfigHelper.getOrDefault(config, "npc_update_interval", 60);
config.setInlineComments("npc_update_skin_interval", List.of("The interval at which the NPC is updated (in seconds). Only if the skin or displayName is a placeholder.")); config.setInlineComments("npc_update_interval", List.of("The interval at which the NPC is updated (in seconds). Only if the skin or displayName is a placeholder."));
npcUpdateVisibilityInterval = (int) ConfigHelper.getOrDefault(config, "npc_update_visibility_interval", 20); 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).")); config.setInlineComments("npc_update_visibility_interval", List.of("The interval at which the NPC visibility is updated (in ticks)."));