diff --git a/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java b/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java index 6dde3bb06..0f6193057 100644 --- a/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java +++ b/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java @@ -17,9 +17,10 @@ import java.nio.file.Files; import java.nio.file.Path; /** - * Handles all stuff to do with the files + * Handles reading and writing config files. * * @author coolGi + * @version 2022-5-26 */ public class ConfigFileHandling { public static final Path ConfigPath = SingletonHandler.get(IMinecraftClientWrapper.class).getGameDirectory().toPath().resolve("config").resolve(ModInfo.NAME+".toml"); @@ -114,14 +115,14 @@ public class ConfigFileHandling { if (workConfig.contains(entry.getNameWCategory())) { try { if (entry.getType().isEnum()) { - entry.setWTSave((T) ( workConfig.getEnum(entry.getNameWCategory(), (Class) entry.getType()) )); + entry.setWithoutSaving((T) ( workConfig.getEnum(entry.getNameWCategory(), (Class) entry.getType()) )); } else if (ConfigTypeConverters.convertObjects.containsKey(entry.getType())) { - entry.setWTSave((T) ConfigTypeConverters.convertFromString(entry.getType(), workConfig.get(entry.getNameWCategory()))); + entry.setWithoutSaving((T) ConfigTypeConverters.convertFromString(entry.getType(), workConfig.get(entry.getNameWCategory()))); } else { - entry.setWTSave((T) workConfig.get(entry.getNameWCategory())); + entry.setWithoutSaving((T) workConfig.get(entry.getNameWCategory())); if (entry.isValid() == 0) return; - else if (entry.isValid() == -1) entry.setWTSave(entry.getMin()); - else if (entry.isValid() == 1) entry.setWTSave(entry.getMax()); + else if (entry.isValid() == -1) entry.setWithoutSaving(entry.getMin()); + else if (entry.isValid() == 1) entry.setWithoutSaving(entry.getMax()); } } catch (Exception e) { e.printStackTrace(); @@ -176,7 +177,7 @@ public class ConfigFileHandling { /** ALWAYS CLEAR WHEN NOT ON SERVER!!!! */ public static void clearApiValues() { for (AbstractConfigType entry : ConfigBase.entries) { - if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && ((ConfigEntry) entry).useApiOverwrite) { + if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && ((ConfigEntry) entry).allowApiOverride) { ((ConfigEntry) entry).setApiValue(null); } } @@ -186,7 +187,7 @@ public class ConfigFileHandling { JSONObject jsonObject = new JSONObject(); jsonObject.put("configVersion", ConfigBase.configVersion); for (AbstractConfigType entry : ConfigBase.entries) { - if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && ((ConfigEntry) entry).useApiOverwrite) { + if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && ((ConfigEntry) entry).allowApiOverride) { if (ConfigTypeConverters.convertObjects.containsKey(entry.getType())) { jsonObject.put(entry.getNameWCategory(), ConfigTypeConverters.convertToString(entry.getType(), ((ConfigEntry) entry).getTrueValue())); } else { @@ -207,7 +208,7 @@ public class ConfigFileHandling { // Importing code for (AbstractConfigType entry : ConfigBase.entries) { - if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && ((ConfigEntry) entry).useApiOverwrite) { + if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && ((ConfigEntry) entry).allowApiOverride) { Object jsonItem = jsonObject.get(entry.getNameWCategory()); if (entry.getType().isEnum()) { ((ConfigEntry) entry).setApiValue(Enum.valueOf((Class) entry.getType(), jsonItem.toString())); diff --git a/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java b/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java index e798b4155..642047c3c 100644 --- a/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java +++ b/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java @@ -1,31 +1,39 @@ package com.seibel.lod.core.config.types; import com.seibel.lod.core.config.ConfigBase; -import com.seibel.lod.core.config.types.ConfigEntryAppearance; import com.seibel.lod.core.config.file.ConfigFileHandling; /** * Use for making the config variables * * @author coolGi + * @version 2022-5-26 */ -public class ConfigEntry extends AbstractConfigType> { - private T defaultValue; +public class ConfigEntry extends AbstractConfigType> +{ + private final T defaultValue; private String comment; private T min; private T max; - // Stuff for server overwrites - public final boolean useApiOverwrite; + + // API control // + /** + * If true this config can be controlled by the API
+ * and any get() method calls will return the apiValue if it is set. + */ + public final boolean allowApiOverride; private T apiValue; - + + + /** Creates the entry */ - private ConfigEntry(ConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean useApiOverwrite) { + private ConfigEntry(ConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean allowApiOverride) { super(appearance, value); this.defaultValue = value; this.comment = comment; this.min = min; this.max = max; - this.useApiOverwrite = useApiOverwrite; + this.allowApiOverride = allowApiOverride; } @@ -44,7 +52,7 @@ public class ConfigEntry extends AbstractConfigType> { } @Override public T get() { - if (useApiOverwrite && apiValue != null) + if (allowApiOverride && apiValue != null) return apiValue; return value; } @@ -53,7 +61,7 @@ public class ConfigEntry extends AbstractConfigType> { } /** Sets the value without saving */ - public void setWTSave(T newValue) { + public void setWithoutSaving(T newValue) { this.value = newValue; }