From 9f31e3503ba1c7f96899547b8cf290bd30d480f3 Mon Sep 17 00:00:00 2001 From: yuesha-yc Date: Fri, 17 Jan 2025 21:56:29 -0800 Subject: [PATCH] Add some logging --- .../chorda/team/CTeamDataManager.java | 7 +-- .../teammoeg/chorda/team/TeamDataHolder.java | 1 - .../content/research/FHResearch.java | 50 +++++++++++++++---- .../research/research/effects/Effect.java | 2 +- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/teammoeg/chorda/team/CTeamDataManager.java b/src/main/java/com/teammoeg/chorda/team/CTeamDataManager.java index dfe070883..344bb9ffb 100644 --- a/src/main/java/com/teammoeg/chorda/team/CTeamDataManager.java +++ b/src/main/java/com/teammoeg/chorda/team/CTeamDataManager.java @@ -65,7 +65,7 @@ public class CTeamDataManager { public static CTeamDataManager INSTANCE; private final MinecraftServer server; - static final LevelResource dataFolder = new LevelResource("fhdata"); + public static final LevelResource dataFolder = new LevelResource("fhdata"); static final LevelResource oldDataFolder = new LevelResource("fhresearch"); private Map dataByFTBId = new HashMap<>(); private Map dataByChordaId = new HashMap<>(); @@ -227,6 +227,7 @@ public void load() { trd.deserialize(nbt, false); dataByFTBId.put(ftbid, trd.getId()); dataByChordaId.put(trd.getId(), trd); + Chorda.LOGGER.debug("Data file for team " + trd.getId().toString() + " loaded."); } catch (IllegalArgumentException ex) { ex.printStackTrace(); Chorda.LOGGER.error("Unexpected data file " + f.getName() + ", ignoring..."); @@ -250,10 +251,10 @@ public void save() { try { NbtIo.writeCompressed(entry.getValue().serialize(false), f); files.remove(fn); + Chorda.LOGGER.debug("Data file for team " + entry.getKey().toString() + " saved."); } catch (IOException e) { - - e.printStackTrace(); Chorda.LOGGER.error("Unable to save data file for team " + entry.getKey().toString() + ", ignoring..."); + e.printStackTrace(); } } for (String todel : files) { diff --git a/src/main/java/com/teammoeg/chorda/team/TeamDataHolder.java b/src/main/java/com/teammoeg/chorda/team/TeamDataHolder.java index 9cf9b3687..9a08ccb4c 100644 --- a/src/main/java/com/teammoeg/chorda/team/TeamDataHolder.java +++ b/src/main/java/com/teammoeg/chorda/team/TeamDataHolder.java @@ -22,7 +22,6 @@ */ package com.teammoeg.chorda.team; -import com.teammoeg.chorda.ChordaNetwork; import com.teammoeg.chorda.util.utility.OptionalLazy; import com.teammoeg.chorda.network.CMessage; import com.teammoeg.frostedheart.FHNetwork; diff --git a/src/main/java/com/teammoeg/frostedheart/content/research/FHResearch.java b/src/main/java/com/teammoeg/frostedheart/content/research/FHResearch.java index faf3925e8..9d5ee2150 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/research/FHResearch.java +++ b/src/main/java/com/teammoeg/frostedheart/content/research/FHResearch.java @@ -64,10 +64,17 @@ * Main Research System. */ public class FHResearch { + /** + * Registry holder for all defined Research in config. + */ public static FHRegistry researches = new FHRegistry<>(); - /*public static FHRegistry clues = new FHRegistry<>(); - public static FHRegistry effects = new FHRegistry<>();*/ + /** + * Cache for all Researches. + */ private static OptionalLazy> allResearches = OptionalLazy.of(() -> researches.all()); + /** + * Editing mode. + */ public static boolean editor = false; public static void clearAll() { @@ -82,6 +89,10 @@ public static void clearCache() { allResearches = OptionalLazy.of(() -> researches.all()); } + /** + * Delete a Research from config JSON + * @param r Research to delete + */ public static void delete(Research r) { researches.remove(r); clearCache(); @@ -176,6 +187,9 @@ else if (r.isShowable()) return available; } + /** + * Initialization steps after Research data is loaded. + */ public static void init() { ClientResearchData.last = null; ResearchListeners.reload(); @@ -238,6 +252,11 @@ public static void load(CompoundTag cnbt) { //effects.deserialize(cnbt.getList("effects", Tag.TAG_STRING)); } + /** + * Load Research from config JSON + * @param r Research to load + * @return Loaded Research + */ public static Research load(Research r) { File folder = FMLPaths.CONFIGDIR.get().toFile(); File rf = new File(folder, "fhresearches"); @@ -264,6 +283,9 @@ public static Research load(Research r) { return researches.getById(iid); } + /** + * Load all Research from config JSON + */ public static void loadAll() { File folder = FMLPaths.CONFIGDIR.get().toFile(); File rf = new File(folder, "fhresearches"); @@ -415,37 +437,44 @@ public static void sendSyncPacket(PacketTarget target) { FHNetwork.send(target, new FHResearchSyncEndPacket()); } - private static final LevelResource dataFolder = new LevelResource("fhdata"); - + /** + * Load Research data from disk. + */ public static void load() { FHResearch.editor = false; - Path local = CTeamDataManager.getServer().getWorldPath(dataFolder); + Path local = CTeamDataManager.getServer().getWorldPath(CTeamDataManager.dataFolder); File regfile = new File(local.toFile().getParentFile(), "fhregistries.dat"); FHResearch.clearAll(); if (regfile.exists()) { try { FHResearch.load(NbtIo.readCompressed(regfile)); + FHMain.LOGGER.info("Research registries loaded."); } catch (IOException e) { e.printStackTrace(); FHMain.LOGGER.fatal("CANNOT READ RESEARCH REGISTRIES, MAY CAUSE UNSYNC!"); } - } else - FHMain.LOGGER.error("NO REGISTRY FOUND"); + } else { + FHMain.LOGGER.error("No registry file found when loading research data."); + } FHResearch.init(); + FHMain.LOGGER.info("RESEARCH DATA INITIALIZED"); local.toFile().mkdirs(); try { File dbg = new File(local.toFile().getParentFile(), "fheditor.dat"); if (dbg.exists() && FileUtil.readString(dbg).equals("true")) FHResearch.editor = true; } catch (IOException e2) { - // TODO Auto-generated catch block + FHMain.LOGGER.error("Cannot read editor status"); e2.printStackTrace(); } } + /** + * Save Research data to disk. + */ public static void save() { - Path local = CTeamDataManager.getServer().getWorldPath(dataFolder); + Path local = CTeamDataManager.getServer().getWorldPath(CTeamDataManager.dataFolder); File regfile = new File(local.toFile().getParentFile(), "fhregistries.dat"); File dbg = new File(local.toFile().getParentFile(), "fheditor.dat"); try { @@ -454,11 +483,12 @@ public static void save() { else if (dbg.exists()) FileUtil.transfer("false", dbg); } catch (IOException e2) { - // TODO Auto-generated catch block + FHMain.LOGGER.error("Cannot save editor status"); e2.printStackTrace(); } try { NbtIo.writeCompressed(FHResearch.save(new CompoundTag()), regfile); + FHMain.LOGGER.info("Research Registries saved."); } catch (IOException e1) { e1.printStackTrace(); FHMain.LOGGER.fatal("CANNOT SAVE RESEARCH REGISTRIES, MAY CAUSE UNSYNC!"); diff --git a/src/main/java/com/teammoeg/frostedheart/content/research/research/effects/Effect.java b/src/main/java/com/teammoeg/frostedheart/content/research/research/effects/Effect.java index a75981f37..21748e3a8 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/research/research/effects/Effect.java +++ b/src/main/java/com/teammoeg/frostedheart/content/research/research/effects/Effect.java @@ -85,7 +85,7 @@ public BaseData(String name, List tooltip, Optional icon, String registerEffectType(EffectExperience.class, "experience", EffectExperience.CODEC); } public static void registerEffectType(Class cls, String type, MapCodec json) { - registry.register(cls, type, CodecUtil.debugCodec(json)); + registry.register(cls, type, json); } String name = "";