Finished file handling (all that is needed to fix it is to fix line 80 in core/config/file/ConfigFileHandling.java)

This commit is contained in:
coolGi2007
2022-02-26 04:48:43 +00:00
parent ffa6bb5653
commit 711658fe38
3 changed files with 43 additions and 4 deletions
@@ -43,8 +43,8 @@ public class ConfigBase {
} catch (IllegalAccessException exception) {
exception.printStackTrace();
}
entries.get(entries.size() - 1).category = (category.isEmpty() ? "" : category + ".");
entries.get(entries.size() - 1).category = field.getName();
entries.get(entries.size() - 1).category = category;
entries.get(entries.size() - 1).name = field.getName();
}
if (field.isAnnotationPresent(ConfigAnnotations.Category.class)) { // If it's a category then init the stuff inside it and put it in the category list
@@ -35,6 +35,10 @@ public class ConfigEntry<T> {
this.value = new_value;
save();
}
/** Sets the value without saving */
public void setWTSave(T new_value) {
this.value = new_value;
}
/** Gets the min value */
public T getMin() {
@@ -2,6 +2,7 @@ package com.seibel.lod.core.config.file;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.seibel.lod.core.ModInfo;
import com.seibel.lod.core.config.ConfigBase;
import com.seibel.lod.core.config.ConfigEntry;
import com.seibel.lod.core.util.SingletonHandler;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftWrapper;
@@ -29,17 +30,33 @@ public class ConfigFileHandling {
}
loadConfig(config);
for (ConfigEntry<?> entry : ConfigBase.entries) {
createComment(entry, config);
saveEntry(entry, config);
}
config.close();
}
public static void loadFromFile() {
try {
config.load();
if (Files.exists(ConfigPath))
config.load();
else {
saveToFile();
return;
}
} catch (Exception e) {
saveToFile();
return;
}
for (ConfigEntry<?> entry : ConfigBase.entries) {
createComment(entry, config);
loadEntry(entry, config);
System.out.println(entry.get());
}
config.close();
}
@@ -49,7 +66,7 @@ public class ConfigFileHandling {
config.close();
}
public static void saveEntry(ConfigEntry<?> entry, CommentedFileConfig workConfig) {
workConfig.set(entry.getNameWCategory(), entry.get());
}
public static void loadEntry(ConfigEntry<?> entry) {
loadConfig(config);
@@ -58,7 +75,25 @@ public class ConfigFileHandling {
}
public static void loadEntry(ConfigEntry<?> entry, CommentedFileConfig workConfig) {
if (workConfig.contains(entry.getNameWCategory())) {
if (entry.get().getClass().isEnum())
entry.setWTSave(workConfig.getEnum(entry.getNameWCategory(), entry.get().getClass()));
else
entry.setWTSave(workConfig.get(entry.getNameWCategory()));
System.out.println(workConfig.get(entry.getNameWCategory()).getClass().toString());
// entry.setWTSave(workConfig.get(entry.getNameWCategory()));
} else {
saveEntry(entry, workConfig);
}
}
public static void createComment(ConfigEntry<?> entry) {
loadConfig(config);
createComment(entry, config);
config.close();
}
public static void createComment(ConfigEntry<?> entry, CommentedFileConfig workConfig) {
workConfig.setComment(entry.getNameWCategory(), entry.getComment());
}
public static void loadConfig(CommentedFileConfig config) {