Skip to content

Commit

Permalink
Add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yuesha-yc committed Jan 18, 2025
1 parent d75fa25 commit 9f31e35
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/teammoeg/chorda/team/CTeamDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID, UUID> dataByFTBId = new HashMap<>();
private Map<UUID, TeamDataHolder> dataByChordaId = new HashMap<>();
Expand Down Expand Up @@ -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...");
Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/teammoeg/chorda/team/TeamDataHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@
* Main Research System.
*/
public class FHResearch {
/**
* Registry holder for all defined Research in config.
*/
public static FHRegistry<Research> researches = new FHRegistry<>();
/*public static FHRegistry<Clue> clues = new FHRegistry<>();
public static FHRegistry<Effect> effects = new FHRegistry<>();*/
/**
* Cache for all Researches.
*/
private static OptionalLazy<List<Research>> allResearches = OptionalLazy.of(() -> researches.all());
/**
* Editing mode.
*/
public static boolean editor = false;

public static void clearAll() {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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 {
Expand All @@ -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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public BaseData(String name, List<String> tooltip, Optional<FHIcon> icon, String
registerEffectType(EffectExperience.class, "experience", EffectExperience.CODEC);
}
public static <T extends Effect> void registerEffectType(Class<T> cls, String type, MapCodec<T> json) {
registry.register(cls, type, CodecUtil.debugCodec(json));
registry.register(cls, type, json);
}

String name = "";
Expand Down

0 comments on commit 9f31e35

Please sign in to comment.