> implem
public void setListeners(IConfigListener... newListeners) { this.listenerList.addAll(Arrays.asList(newListeners)); }
- /**
- * Checks if the option is valid
- *
- * @return 0 == valid
- * 2 == invalid
- *
1 == number too high
- *
-1 == number too low
- */
- @Override
- public byte isValid() { return isValid(this.value, this.min, this.max); }
- /**
- * Checks if a new value is valid
- *
- * @param value Value that is being checked whether valid
- * @return 0 == valid
- *
2 == invalid
- *
1 == number too high
- *
-1 == number too low
- */
- @Override
- public byte isValid(T value) { return this.isValid(value, this.min, this.max); }
- /**
- * Checks if a new value is valid
- *
- * @param min The minimum that the value can be
- * @param max The maximum that the value can be
- * @return 0 == valid
- *
2 == invalid
- *
1 == number too high
- *
-1 == number too low
- */
- public byte isValid(T min, T max) { return this.isValid(this.value, min, max); }
- /**
- * Checks if a new value is valid
- *
- * @param value Value that is being checked whether valid
- * @param min The minimum that the value can be
- * @param max The maximum that the value can be
- * @return 0 == valid
- *
2 == invalid
- *
1 == number too high
- *
-1 == number too low
- */
- public byte isValid(T value, T min, T max)
+
+ //====================//
+ // min/max validation //
+ //====================//
+
+ /** Checks if this config's current value is valid */
+ public EConfigValidity getValidity() { return this.getValidity(this.value, this.min, this.max); }
+ /** Checks if the given value is valid */
+ public EConfigValidity getValidity(@Nullable T value) { return this.getValidity(value, this.min, this.max); }
+ /** Checks if the given value is valid */
+ public EConfigValidity getValidity(@Nullable T value, @Nullable T min, @Nullable T max)
{
- if (this.configBase.disableMinMax)
+ if (ConfigHandler.INSTANCE.runMinMaxValidation)
{
- return 0;
+ return EConfigValidity.VALID;
}
- else if (min == null && max == null)
+ else if (min == null
+ && max == null)
{
// no validation is needed for this field
- return 0;
+ return EConfigValidity.VALID;
}
- else if (value == null || this.value == null
+ else if (value == null
+ || this.value == null
|| value.getClass() != this.value.getClass())
{
- // If the 2 variables aren't the same type then it will be invalid
- return 2;
+ // If the 2 variables aren't the same type
+ // or the input is missing
+ // then it will be invalid
+ return EConfigValidity.INVALID;
}
- else if (Number.class.isAssignableFrom(value.getClass()))
+ else if (value instanceof Number)
{
- // Only check min max if it is a number
- if (max != null && NumberUtil.greaterThan((Number) value, (Number) max))
+ // Only check min/max if this config's type is a number
+ if (max != null
+ && NumberUtil.greaterThan((Number) value, (Number) max))
{
- return 1;
- }
- if (min != null && NumberUtil.lessThan((Number) value, (Number) min))
- {
- return -1;
+ return EConfigValidity.NUMBER_TOO_HIGH;
}
- return 0;
+ if (min != null
+ && NumberUtil.lessThan((Number) value, (Number) min))
+ {
+ return EConfigValidity.NUMBER_TOO_LOW;
+ }
+
+ return EConfigValidity.VALID;
}
else
{
- return 0;
+ return EConfigValidity.VALID;
}
}
+
+
+ //===============//
+ // file handling //
+ //===============//
+
/** This should normally not be called since set() automatically calls this */
- public void save() { configBase.configFileHandler.saveEntry(this); }
+ public void save() { ConfigHandler.INSTANCE.configFileHandler.saveEntry(this); }
/** This should normally not be called except for special circumstances */
- public void load() { configBase.configFileHandler.loadEntry(this); }
+ public void load() { ConfigHandler.INSTANCE.configFileHandler.loadEntry(this); }
- @Override
- public boolean equals(IConfigEntry> obj) { return obj.getClass() == ConfigEntry.class && equals((ConfigEntry>) obj); }
+
+ //================//
+ // base overrides //
+ //================//
+
+ public boolean equals(AbstractConfigBase> obj)
+ {
+ return obj.getClass() == ConfigEntry.class
+ && this.equals((ConfigEntry>) obj);
+ }
/** Is the value of this equal to another */
public boolean equals(ConfigEntry> obj)
{
// Can all of this just be "return this.value.equals(obj.value)"?
if (Number.class.isAssignableFrom(this.value.getClass()))
+ {
return this.value == obj.value;
+ }
else
+ {
return this.value.equals(obj.value);
+ }
}
- public static class Builder extends AbstractConfigType.Builder>
+
+ //=========//
+ // builder //
+ //=========//
+
+ public static class Builder extends AbstractConfigBase.Builder>
{
private String tmpComment = null;
private T tmpMin = null;
@@ -337,6 +318,8 @@ public class ConfigEntry extends AbstractConfigType> implem
private EConfigEntryPerformance tmpPerformance = EConfigEntryPerformance.DONT_SHOW;
protected ArrayList tmpIConfigListener = new ArrayList<>();
+
+
public Builder comment(String newComment)
{
this.tmpComment = newComment;
@@ -416,12 +399,14 @@ public class ConfigEntry extends AbstractConfigType> implem
+ // build //
+
public ConfigEntry build()
{
return new ConfigEntry<>(
- this.tmpAppearance,
- this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax,
- this.tmpChatCommandName, this.tmpUseApiOverwrite,
+ this.tmpAppearance,
+ this.tmpComment, this.tmpChatCommandName, this.tmpValue, this.tmpMin, this.tmpMax,
+ this.tmpUseApiOverwrite,
this.tmpPerformance, this.tmpIConfigListener);
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java
index e23f3fa28..41a077793 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java
@@ -21,29 +21,42 @@ package com.seibel.distanthorizons.core.config.types;
import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance;
-public class ConfigUIButton extends AbstractConfigType
+public class ConfigUIButton extends AbstractConfigBase
{
- public ConfigUIButton(Runnable runnable)
- {
- super(EConfigEntryAppearance.ONLY_IN_GUI, runnable);
- }
+ //=============//
+ // constructor //
+ //=============//
- /** Runs the action of the button. NOTE: Will run on the main thread (so can halt the main process if not offloaded to a different thread) */
+ public ConfigUIButton(Runnable runnable)
+ { super(EConfigEntryAppearance.ONLY_IN_GUI, runnable); }
+
+
+
+ //=========//
+ // actions //
+ //=========//
+
+ /**
+ * Runs the action of the button.
+ * NOTE: This will run on the render thread
+ * (so it can halt the main process if it takes too long and isn't offloaded to another thread)
+ */
public void runAction() { this.value.run(); }
- public static class Builder extends AbstractConfigType.Builder
+
+
+ //=========//
+ // builder //
+ //=========//
+
+ public static class Builder extends AbstractConfigBase.Builder
{
/** Appearance shouldn't be changed */
@Override
- public Builder setAppearance(EConfigEntryAppearance newAppearance)
- {
- return this;
- }
+ public Builder setAppearance(EConfigEntryAppearance newAppearance) { return this; }
public ConfigUIButton build()
- {
- return new ConfigUIButton(this.tmpValue);
- }
+ { return new ConfigUIButton(this.tmpValue); }
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java
index 46dbb0e40..a34f97e94 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
*
* @author coolGi
*/
-public class ConfigUIComment extends AbstractConfigType
+public class ConfigUIComment extends AbstractConfigBase
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -43,8 +43,11 @@ public class ConfigUIComment extends AbstractConfigType
- public ConfigUIComment() { this(null, null); }
- public ConfigUIComment(String parentConfigPath, EConfigCommentTextPosition textPosition)
+ //=============//
+ // constructor //
+ //=============//
+
+ public ConfigUIComment(String parentConfigPath, @Nullable EConfigCommentTextPosition textPosition)
{
super(EConfigEntryAppearance.ONLY_IN_GUI, "");
this.parentConfigPath = parentConfigPath;
@@ -53,6 +56,10 @@ public class ConfigUIComment extends AbstractConfigType
+ //=========//
+ // setters //
+ //=========//
+
/** Appearance shouldn't be changed */
@Override
public void setAppearance(EConfigEntryAppearance newAppearance) { }
@@ -63,9 +70,14 @@ public class ConfigUIComment extends AbstractConfigType
- public static class Builder extends AbstractConfigType.Builder
+ //=========//
+ // builder //
+ //=========//
+
+ public static class Builder extends AbstractConfigBase.Builder
{
public String tempParentConfigPath = null;
+ @Nullable
public EConfigCommentTextPosition tempTextPosition = null;
@@ -155,9 +167,13 @@ public class ConfigUIComment extends AbstractConfigType
+ // build //
+
public ConfigUIComment build()
{ return new ConfigUIComment(this.tempParentConfigPath, this.tempTextPosition); }
}
+
+
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java
index 43d870cdf..4f8ce4267 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java
@@ -25,13 +25,21 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance
* Adds empty space the height of a button.
* Useful for separating different categories.
*/
-public class ConfigUISpacer extends AbstractConfigType
+public class ConfigUISpacer extends AbstractConfigBase
{
+ //=============//
+ // constructor //
+ //=============//
+
public ConfigUISpacer()
{ super(EConfigEntryAppearance.ONLY_IN_GUI, ""); }
+ //=========//
+ // setters //
+ //=========//
+
/** Appearance shouldn't be changed */
@Override
public void setAppearance(EConfigEntryAppearance newAppearance) { }
@@ -42,7 +50,11 @@ public class ConfigUISpacer extends AbstractConfigType
- public static class Builder extends AbstractConfigType.Builder
+ //=========//
+ // builder //
+ //=========//
+
+ public static class Builder extends AbstractConfigBase.Builder
{
/** Appearance shouldn't be changed */
@Override
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java
index 2e515951f..ff164c82e 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java
@@ -23,16 +23,24 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance
/**
* Creates a UI element that copies everything from another element.
- * This only effects the UI
+ * This element is only visible in the GUI.
*
* @author coolGi
*/
-public class ConfigUiLinkedEntry extends AbstractConfigType, ConfigUiLinkedEntry>
+public class ConfigUiLinkedEntry extends AbstractConfigBase>
{
- public ConfigUiLinkedEntry(AbstractConfigType, ?> value)
- {
- super(EConfigEntryAppearance.ONLY_IN_GUI, value);
- }
+ //=============//
+ // constructor //
+ //=============//
+
+ public ConfigUiLinkedEntry(AbstractConfigBase> value)
+ { super(EConfigEntryAppearance.ONLY_IN_GUI, value); }
+
+
+
+ //=========//
+ // setters //
+ //=========//
/** Appearance shouldn't be changed */
@Override
@@ -40,10 +48,15 @@ public class ConfigUiLinkedEntry extends AbstractConfigType newValue) { }
+ public void set(AbstractConfigBase> newValue) { }
- public static class Builder extends AbstractConfigType.Builder, Builder>
+
+ //=========//
+ // builder //
+ //=========//
+
+ public static class Builder extends AbstractConfigBase.Builder, Builder>
{
/** Appearance shouldn't be changed */
@Override
@@ -59,4 +72,6 @@ public class ConfigUiLinkedEntry extends AbstractConfigType worldGeneratorEnabledConfig;
@Nullable
private final SyncOnLoadRequestQueue syncOnLoadRequestQueue;
@@ -134,7 +132,6 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
}
this.dataFileHandler = new RemoteFullDataSourceProvider(this, saveStructure, fullDataSaveDirOverride, this.syncOnLoadRequestQueue);
- this.worldGeneratorEnabledConfig = new AppliedConfigState<>(Config.Common.WorldGenerator.enableDistantGeneration);
this.worldGenModule = new WorldGenModule(this, this.dataFileHandler, () -> new WorldGenState(this, networkState));
this.clientside = new ClientLevelModule(this);
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/NumberUtil.java
similarity index 74%
rename from core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java
rename to core/src/main/java/com/seibel/distanthorizons/core/util/NumberUtil.java
index a6e4b9cb5..08aec38f6 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/util/NumberUtil.java
@@ -17,54 +17,50 @@
* along with this program. If not, see .
*/
-package com.seibel.distanthorizons.core.config;
+package com.seibel.distanthorizons.core.util;
import java.util.HashMap;
import java.util.Map;
/**
- * Helps with working with numbers that the value of which is unknown
+ * Helps when working with numbers where the type is unknown.
*
* @author coolGi
- * @version 2023-7-16
*/
-// TODO: Should this be moved out of here into somewhere like the util section
public class NumberUtil
{
// Is there no better way of doing this?
public static Map, Number> minValues = new HashMap, Number>()
{{
- put(Byte.class, Byte.MIN_VALUE);
- put(Short.class, Short.MIN_VALUE);
- put(Integer.class, Integer.MIN_VALUE);
- put(Long.class, Long.MIN_VALUE);
- put(Double.class, Double.MIN_VALUE);
- put(Float.class, Float.MIN_VALUE);
+ this.put(Byte.class, Byte.MIN_VALUE);
+ this.put(Short.class, Short.MIN_VALUE);
+ this.put(Integer.class, Integer.MIN_VALUE);
+ this.put(Long.class, Long.MIN_VALUE);
+ this.put(Double.class, Double.MIN_VALUE);
+ this. put(Float.class, Float.MIN_VALUE);
}};
public static Map, Number> maxValues = new HashMap, Number>()
{{
- put(Byte.class, Byte.MAX_VALUE);
- put(Short.class, Short.MAX_VALUE);
- put(Integer.class, Integer.MAX_VALUE);
- put(Long.class, Long.MAX_VALUE);
- put(Double.class, Double.MAX_VALUE);
- put(Float.class, Float.MAX_VALUE);
+ this.put(Byte.class, Byte.MAX_VALUE);
+ this.put(Short.class, Short.MAX_VALUE);
+ this.put(Integer.class, Integer.MAX_VALUE);
+ this.put(Long.class, Long.MAX_VALUE);
+ this.put(Double.class, Double.MAX_VALUE);
+ this.put(Float.class, Float.MAX_VALUE);
}};
- public static Number getMinimum(Class> c)
- {
- return minValues.get(c);
- }
- public static Number getMaximum(Class> c)
- {
- return maxValues.get(c);
- }
+
+
+ public static Number getMinimum(Class> c) { return minValues.get(c); }
+ public static Number getMaximum(Class> c) { return maxValues.get(c); }
/** Does a greater than (>) operator on any number */
public static boolean greaterThan(Number a, Number b)
{
if (a.getClass() != b.getClass())
+ {
return false;
+ }
Class> typeClass = a.getClass();
if (typeClass == Byte.class) return a.byteValue() > b.byteValue();
@@ -73,6 +69,7 @@ public class NumberUtil
if (typeClass == Long.class) return a.longValue() > b.longValue();
if (typeClass == Double.class) return a.doubleValue() > b.doubleValue();
if (typeClass == Float.class) return a.floatValue() > b.floatValue();
+
return false;
}
@@ -80,7 +77,9 @@ public class NumberUtil
public static boolean lessThan(Number a, Number b)
{
if (a.getClass() != b.getClass())
+ {
return false;
+ }
Class> typeClass = a.getClass();
if (typeClass == Byte.class) return a.byteValue() < b.byteValue();
@@ -89,6 +88,7 @@ public class NumberUtil
if (typeClass == Long.class) return a.longValue() < b.longValue();
if (typeClass == Double.class) return a.doubleValue() < b.doubleValue();
if (typeClass == Float.class) return a.floatValue() < b.floatValue();
+
return false;
}