Rename ConfigEntry.useApiOverwrite ->allowApiOverride

This commit is contained in:
James Seibel
2022-05-26 20:28:14 -05:00
parent 1809721665
commit 1182a0cac3
2 changed files with 28 additions and 19 deletions
@@ -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<? extends Enum>) entry.getType()) ));
entry.setWithoutSaving((T) ( workConfig.getEnum(entry.getNameWCategory(), (Class<? extends Enum>) 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<? extends Enum>) entry.getType(), jsonItem.toString()));
@@ -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<T> extends AbstractConfigType<T, ConfigEntry<T>> {
private T defaultValue;
public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>>
{
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 <br>
* 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<T> extends AbstractConfigType<T, ConfigEntry<T>> {
}
@Override
public T get() {
if (useApiOverwrite && apiValue != null)
if (allowApiOverride && apiValue != null)
return apiValue;
return value;
}
@@ -53,7 +61,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> {
}
/** Sets the value without saving */
public void setWTSave(T newValue) {
public void setWithoutSaving(T newValue) {
this.value = newValue;
}