Made a way to save 1 config entry at a time
This commit is contained in:
@@ -86,6 +86,7 @@ public abstract class ConfigGui
|
||||
private static final Pattern DECIMAL_ONLY_REGEX = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||
|
||||
private static final List<EntryInfo> entries = new ArrayList<>();
|
||||
public static final Map<String,EntryInfo> entryMap = new HashMap<>();
|
||||
|
||||
// Change these to your own mod
|
||||
private static final String MOD_NAME = ModInfo.NAME; // For file saving and identifying
|
||||
@@ -163,6 +164,7 @@ public abstract class ConfigGui
|
||||
if (field.isAnnotationPresent(ConfigAnnotations.Entry.class) || field.isAnnotationPresent(ConfigAnnotations.Comment.class) || field.isAnnotationPresent(ConfigAnnotations.ScreenEntry.class))
|
||||
{
|
||||
// If putting in your own mod then put your own check for server sided
|
||||
entryMap.put((!category.isEmpty() ? category + "." : "") + field.getName(), info);
|
||||
info.category = category;
|
||||
if (!LodCommonMain.serverSided)
|
||||
initClient(field, info, category);
|
||||
@@ -353,24 +355,39 @@ public abstract class ConfigGui
|
||||
// Puts everything into its variable
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.field.isAnnotationPresent(ConfigAnnotations.Entry.class)) {
|
||||
String itemPath = (info.category.isEmpty() ? "" : info.category + ".") + info.field.getName();
|
||||
if (config.contains(itemPath)) {
|
||||
if (info.field.getType().isEnum())
|
||||
info.value = config.getEnum(itemPath, info.varClass);
|
||||
else
|
||||
info.value = config.get(itemPath);
|
||||
} else
|
||||
config.set(itemPath, info.value);
|
||||
|
||||
try {
|
||||
info.field.set(null, info.value);
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
saveOption(info);
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
}
|
||||
|
||||
// TODO: Use this in the config wrapper singleton
|
||||
public static void saveOption(String name) {
|
||||
saveOption(entryMap.get(name));
|
||||
}
|
||||
|
||||
public static void saveOption(EntryInfo info)
|
||||
{
|
||||
CommentedFileConfig config = CommentedFileConfig.builder(configFilePath.toFile()).autosave().build();
|
||||
config.load();
|
||||
|
||||
String itemPath = (info.category.isEmpty() ? "" : info.category + ".") + info.field.getName();
|
||||
if (config.contains(itemPath)) {
|
||||
if (info.field.getType().isEnum())
|
||||
info.value = config.getEnum(itemPath, info.varClass);
|
||||
else
|
||||
info.value = config.get(itemPath);
|
||||
} else
|
||||
config.set(itemPath, info.value);
|
||||
|
||||
try {
|
||||
info.field.set(null, info.value);
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
|
||||
config.close();
|
||||
}
|
||||
|
||||
|
||||
public static Screen getScreen(Screen parent, String category)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user