mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
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:
@@ -298,25 +298,37 @@ public class FancyNpcs extends JavaPlugin implements FancyNpcsPlugin {
|
||||
|
||||
int npcUpdateInterval = config.getNpcUpdateInterval();
|
||||
npcThread.scheduleAtFixedRate(() -> {
|
||||
List<Npc> npcs = new ArrayList<>(npcManager.getAllNpcs());
|
||||
for (Npc npc : npcs) {
|
||||
String skinID = npc.getData().getSkinData().getIdentifier();
|
||||
boolean skinUpdated = npc.getData().getSkinData() != null &&
|
||||
!skinID.isEmpty() &&
|
||||
SkinUtils.isPlaceholder(skinID);
|
||||
final List<Npc> npcs = new ArrayList<>(npcManager.getAllNpcs());
|
||||
for (final Npc npc : npcs) {
|
||||
try {
|
||||
boolean shouldUpdate = false;
|
||||
|
||||
boolean displayNameUpdated = npc.getData().getDisplayName() != null &&
|
||||
!npc.getData().getDisplayName().isEmpty() &&
|
||||
SkinUtils.isPlaceholder(npc.getData().getDisplayName());
|
||||
if (npc.getData().getDisplayName() != null && !npc.getData().getDisplayName().isBlank() && SkinUtils.isPlaceholder(npc.getData().getDisplayName())) {
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
if (skinUpdated || displayNameUpdated) {
|
||||
SkinData skinData = skinManager.getByIdentifier(skinID, npc.getData().getSkinData().getVariant());
|
||||
skinData.setIdentifier(skinID);
|
||||
npc.getData().setSkinData(skinData);
|
||||
if (npc.getData().getSkinData() != null) {
|
||||
final String skinID = npc.getData().getSkinData().getIdentifier();
|
||||
if (!skinID.isEmpty() && SkinUtils.isPlaceholder(skinID)) {
|
||||
final SkinData skinData = skinManager.getByIdentifier(skinID, npc.getData().getSkinData().getVariant());
|
||||
skinData.setIdentifier(skinID);
|
||||
npc.getData().setSkinData(skinData);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
npc.removeForAll();
|
||||
npc.create();
|
||||
npc.spawnForAll();
|
||||
if (shouldUpdate) {
|
||||
npc.removeForAll();
|
||||
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);
|
||||
|
||||
@@ -116,7 +116,7 @@ public class FancyNpcsConfigImpl implements FancyNpcsConfig {
|
||||
config.setInlineComments("autosave_interval", List.of("The interval at which autosave is performed in minutes."));
|
||||
|
||||
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);
|
||||
config.setInlineComments("npc_update_visibility_interval", List.of("The interval at which the NPC visibility is updated (in ticks)."));
|
||||
|
||||
Reference in New Issue
Block a user