the grand config refactor

This commit is contained in:
FalsePattern committed 2022-07-31 20:28:37 +02:00
1 parent c5fbf5dee5
commit eaec528f5d
32 files changed
+3038 -190

No files matched your search

@@ -20,23 +20,25 @@
*/
package com.falsepattern.lib.config;
import com.falsepattern.lib.DeprecationDetails;
import com.falsepattern.lib.StableAPI;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.BiConsumer;
/**
* A modern configuration system to replace the old and obtuse forge config system.
*
* Note that just annotating a configuration class with {@link Config} is not enough, you must also register it using
* {@link com.falsepattern.lib.config.ConfigurationManager#registerConfig}!
* {@link ConfigurationManager#initialize(Class[])} or {@link ConfigurationManager#initialize(BiConsumer, Class[])}!
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@StableAPI(since = "0.6.0")
public @interface Config {
/**
* The mod id that this configuration is associated with.
@@ -51,6 +53,7 @@ public @interface Config {
/**
* The lang file key of this configuration. Used in config GUIs.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
@@ -61,6 +64,7 @@ public @interface Config {
/**
* The description of the configuration.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -72,6 +76,7 @@ public @interface Config {
* If you have extra fields in the config class used for anything else other than configuring, you must annotate
* the using this so that the config engine doesn't pick them up.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -82,6 +87,7 @@ public @interface Config {
* The default value for a boolean field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -92,6 +98,7 @@ public @interface Config {
/**
* The range of possible values an int config can have.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -105,6 +112,7 @@ public @interface Config {
* The default value for an int field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -114,12 +122,16 @@ public @interface Config {
/**
* The range of possible values a float config can have.
* Notice: float configs are deprecated! Use double configs instead!
*/
@Deprecated
@DeprecationDetails(stableSince = "0.6.0",
deprecatedSince = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface RangeFloat {
float min() default Float.MIN_VALUE;
float min() default -Float.MAX_VALUE;
float max() default Float.MAX_VALUE;
}
@@ -127,7 +139,11 @@ public @interface Config {
/**
* The default value for a float field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
* Notice: float configs are deprecated! Use double configs instead!
*/
@Deprecated
@DeprecationDetails(stableSince = "0.6.0",
deprecatedSince = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -135,10 +151,36 @@ public @interface Config {
float value();
}
/**
* The range of possible values a double config can have.
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface RangeDouble {
double min() default -Double.MAX_VALUE;
double max() default Double.MAX_VALUE;
}
/**
* The default value for a double field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface DefaultDouble {
double value();
}
/**
* The default value for a String field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -146,9 +188,27 @@ public @interface Config {
String value();
}
/**
* This annotation limits the maximum number of characters present in a string configuration.
*
* Note: If this annotation is not present, the maximum length will be implicitly set to 256 to avoid malicious
* synchronizations that would make clients run out of memory!
*
* When used with a string list, this limit will apply to each element individually, not to the size of the list as a whole.
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface StringMaxLength {
int value();
}
/**
* A regex pattern for restricting the allowed strings.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -160,6 +220,7 @@ public @interface Config {
* The default value for an Enum field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -171,6 +232,7 @@ public @interface Config {
* The default value for a string array field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -178,9 +240,74 @@ public @interface Config {
String[] value();
}
/**
* The default value for a double array field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface DefaultDoubleList {
double[] value();
}
/**
* The default value for an int array field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface DefaultIntList {
int[] value();
}
/**
* The default value for an boolean array field. Not having a default is deprecated since 0.10, and will be strongly
* enforced in 0.11+!
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface DefaultBooleanList {
boolean[] value();
}
/**
* If this annotation is present, the list in the config will be forced to have exactly the amount of elements as
* the default value.
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface ListFixedLength {
}
/**
* This annotation limits the maximum number of elements present in an array configuration. Only effective if
* {@link ListFixedLength} is NOT present.
*
* Note: If this annotation is not present, the maximum length will be implicitly set to 256 to avoid malicious
* synchronizations that would make clients run out of memory!
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface ListMaxLength {
int value();
}
/**
* The name of this config property in the config file. If not specified, the field's name will be used instead.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@@ -191,6 +318,7 @@ public @interface Config {
/**
* Whether the specific configuration needs a minecraft restart to be applied.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
@@ -200,6 +328,7 @@ public @interface Config {
/**
* Whether the specific configuration needs a world/server rejoin to be applied.
*/
@StableAPI(since = "0.6.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
@@ -207,7 +336,7 @@ public @interface Config {
}
/**
* Signals that this configuration entry/class should be synchronized between the client and the server when
* Signals that this configuration class should be synchronized between the client and the server when
* joining a multiplayer instance.
*
* Note that synchronization ALWAYS happens FROM the server TO the client. The server should NEVER attempt to get
@@ -216,20 +345,17 @@ public @interface Config {
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
@Target(ElementType.TYPE)
@interface Synchronize {
/**
* This is a limit on how many bytes the client will accept from the server. If this limit is exceeded,
* the client shall refuse to connect to the server. For String[]-s, the amount of bytes is the sum of all
* strings inside the array.<br><br>
*
* This limitation option exists to avoid malicious servers flooding clients with data.<br><br>
*
* By default, the client will accept any amount of bytes.<br><br>
*
* This only applies for String and String[] configurations, and is ignored on the other config types.
* For enums, this value is computed automatically.
*/
int maxLength();
}
/**
* Use this to mark config fields you don't want to synchronize in a class marked with {@link Synchronize}.
*/
@StableAPI(since = "0.10.0")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface NoSync {
}
}