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,26 +298,38 @@ 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();
|
||||||
|
if (!skinID.isEmpty() && SkinUtils.isPlaceholder(skinID)) {
|
||||||
|
final SkinData skinData = skinManager.getByIdentifier(skinID, npc.getData().getSkinData().getVariant());
|
||||||
skinData.setIdentifier(skinID);
|
skinData.setIdentifier(skinID);
|
||||||
npc.getData().setSkinData(skinData);
|
npc.getData().setSkinData(skinData);
|
||||||
|
shouldUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldUpdate) {
|
||||||
npc.removeForAll();
|
npc.removeForAll();
|
||||||
npc.create();
|
npc.create();
|
||||||
npc.spawnForAll();
|
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);
|
||||||
|
|
||||||
|
|||||||
@@ -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)."));
|
||||||
|
|||||||
Reference in New Issue
Block a user