Skip to content

Commit 3a6eaaa

Browse files
committed
fix: improve error handling and validation in avatar, dialogue, and entity config loading
1 parent 8b4583f commit 3a6eaaa

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/main/java/com/yardenzamir/simchat/client/AvatarManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ private static CachedTexture loadTexture(String imageId, Path imagePath, long mo
111111
NativeImage image = NativeImage.read(stream);
112112
DynamicTexture texture = new DynamicTexture(image);
113113

114-
ResourceLocation location = SimChatMod.id("avatar/" + imageId);
114+
ResourceLocation location = SimChatMod.id("avatar/" + imageId.toLowerCase());
115115
Minecraft.getInstance().getTextureManager().register(location, texture);
116116

117117
SimChatMod.LOGGER.debug("Loaded avatar texture: {}", imageId);
118118
return new CachedTexture(location, modTime, false);
119-
} catch (IOException e) {
119+
} catch (Exception e) {
120120
SimChatMod.LOGGER.error("Failed to load avatar image: {}", imagePath, e);
121121
return new CachedTexture(FALLBACK_TEXTURE, 0, true);
122122
}

src/main/java/com/yardenzamir/simchat/data/DialogueManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* Loads and manages dialogues from datapacks.
1919
* Dialogues are loaded from: data/<namespace>/simchat/<path>.json
20+
* Only files with .json extension are loaded - other files (README.md, scripts, etc.) are ignored.
2021
*/
2122
public class DialogueManager extends SimpleJsonResourceReloadListener {
2223

@@ -38,6 +39,10 @@ protected void apply(Map<ResourceLocation, JsonElement> entries, ResourceManager
3839
for (Map.Entry<ResourceLocation, JsonElement> entry : entries.entrySet()) {
3940
ResourceLocation id = entry.getKey();
4041
try {
42+
if (!entry.getValue().isJsonObject()) {
43+
SimChatMod.LOGGER.warn("Skipping non-object dialogue file: {}", id);
44+
continue;
45+
}
4146
DialogueData dialogue = DialogueData.fromJson(entry.getValue().getAsJsonObject());
4247
dialogues.put(id, dialogue);
4348
} catch (Exception e) {

src/main/java/com/yardenzamir/simchat/data/EntityConfigManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ public static EntityConfig getConfig(String entityId) {
8282
}
8383

8484
return cache.get(entityId);
85-
} catch (IOException e) {
85+
} catch (Exception e) {
8686
SimChatMod.LOGGER.error("Failed to load entity config for {}: {}", entityId, e.getMessage());
87+
cache.remove(entityId);
88+
lastModified.remove(entityId);
8789
return null;
8890
}
8991
}

0 commit comments

Comments
 (0)