Skip to content

Commit eaec528

Browse files
committed
the grand config refactor
1 parent c5fbf5d commit eaec528

32 files changed

+3034
-186
lines changed

src/main/java/com/falsepattern/lib/config/Config.java

Lines changed: 144 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,25 @@
2020
*/
2121
package com.falsepattern.lib.config;
2222

23+
import com.falsepattern.lib.DeprecationDetails;
2324
import com.falsepattern.lib.StableAPI;
2425
import java.lang.annotation.Documented;
2526
import java.lang.annotation.ElementType;
2627
import java.lang.annotation.Retention;
2728
import java.lang.annotation.RetentionPolicy;
2829
import java.lang.annotation.Target;
30+
import java.util.function.BiConsumer;
2931

3032
/**
3133
* A modern configuration system to replace the old and obtuse forge config system.
3234
*
3335
* Note that just annotating a configuration class with {@link Config} is not enough, you must also register it using
34-
* {@link com.falsepattern.lib.config.ConfigurationManager#registerConfig}!
36+
* {@link ConfigurationManager#initialize(Class[])} or {@link ConfigurationManager#initialize(BiConsumer, Class[])}!
3537
*/
38+
@StableAPI(since = "0.6.0")
3639
@Documented
3740
@Retention(RetentionPolicy.RUNTIME)
3841
@Target(ElementType.TYPE)
39-
@StableAPI(since = "0.6.0")
4042
public @interface Config {
4143
/**
4244
* The mod id that this configuration is associated with.
@@ -51,6 +53,7 @@
5153
/**
5254
* The lang file key of this configuration. Used in config GUIs.
5355
*/
56+
@StableAPI(since = "0.6.0")
5457
@Documented
5558
@Retention(RetentionPolicy.RUNTIME)
5659
@Target({ElementType.FIELD, ElementType.TYPE})
@@ -61,6 +64,7 @@
6164
/**
6265
* The description of the configuration.
6366
*/
67+
@StableAPI(since = "0.6.0")
6468
@Documented
6569
@Retention(RetentionPolicy.RUNTIME)
6670
@Target(ElementType.FIELD)
@@ -72,6 +76,7 @@
7276
* If you have extra fields in the config class used for anything else other than configuring, you must annotate
7377
* the using this so that the config engine doesn't pick them up.
7478
*/
79+
@StableAPI(since = "0.6.0")
7580
@Documented
7681
@Retention(RetentionPolicy.RUNTIME)
7782
@Target(ElementType.FIELD)
@@ -82,6 +87,7 @@
8287
* The default value for a boolean field. Not having a default is deprecated since 0.10, and will be strongly
8388
* enforced in 0.11+!
8489
*/
90+
@StableAPI(since = "0.6.0")
8591
@Documented
8692
@Retention(RetentionPolicy.RUNTIME)
8793
@Target(ElementType.FIELD)
@@ -92,6 +98,7 @@
9298
/**
9399
* The range of possible values an int config can have.
94100
*/
101+
@StableAPI(since = "0.6.0")
95102
@Documented
96103
@Retention(RetentionPolicy.RUNTIME)
97104
@Target(ElementType.FIELD)
@@ -105,6 +112,7 @@
105112
* The default value for an int field. Not having a default is deprecated since 0.10, and will be strongly
106113
* enforced in 0.11+!
107114
*/
115+
@StableAPI(since = "0.6.0")
108116
@Documented
109117
@Retention(RetentionPolicy.RUNTIME)
110118
@Target(ElementType.FIELD)
@@ -114,41 +122,93 @@
114122

115123
/**
116124
* The range of possible values a float config can have.
125+
* Notice: float configs are deprecated! Use double configs instead!
117126
*/
127+
@Deprecated
128+
@DeprecationDetails(stableSince = "0.6.0",
129+
deprecatedSince = "0.10.0")
118130
@Documented
119131
@Retention(RetentionPolicy.RUNTIME)
120132
@Target(ElementType.FIELD)
121133
@interface RangeFloat {
122-
float min() default Float.MIN_VALUE;
134+
float min() default -Float.MAX_VALUE;
123135

124136
float max() default Float.MAX_VALUE;
125137
}
126138

127139
/**
128140
* The default value for a float field. Not having a default is deprecated since 0.10, and will be strongly
129141
* enforced in 0.11+!
142+
* Notice: float configs are deprecated! Use double configs instead!
130143
*/
144+
@Deprecated
145+
@DeprecationDetails(stableSince = "0.6.0",
146+
deprecatedSince = "0.10.0")
131147
@Documented
132148
@Retention(RetentionPolicy.RUNTIME)
133149
@Target(ElementType.FIELD)
134150
@interface DefaultFloat {
135151
float value();
136152
}
137153

154+
/**
155+
* The range of possible values a double config can have.
156+
*/
157+
@StableAPI(since = "0.10.0")
158+
@Documented
159+
@Retention(RetentionPolicy.RUNTIME)
160+
@Target(ElementType.FIELD)
161+
@interface RangeDouble {
162+
double min() default -Double.MAX_VALUE;
163+
164+
double max() default Double.MAX_VALUE;
165+
}
166+
167+
/**
168+
* The default value for a double field. Not having a default is deprecated since 0.10, and will be strongly
169+
* enforced in 0.11+!
170+
*/
171+
@StableAPI(since = "0.10.0")
172+
@Documented
173+
@Retention(RetentionPolicy.RUNTIME)
174+
@Target(ElementType.FIELD)
175+
@interface DefaultDouble {
176+
double value();
177+
}
178+
138179
/**
139180
* The default value for a String field. Not having a default is deprecated since 0.10, and will be strongly
140181
* enforced in 0.11+!
141182
*/
183+
@StableAPI(since = "0.6.0")
142184
@Documented
143185
@Retention(RetentionPolicy.RUNTIME)
144186
@Target(ElementType.FIELD)
145187
@interface DefaultString {
146188
String value();
147189
}
148190

191+
192+
/**
193+
* This annotation limits the maximum number of characters present in a string configuration.
194+
*
195+
* Note: If this annotation is not present, the maximum length will be implicitly set to 256 to avoid malicious
196+
* synchronizations that would make clients run out of memory!
197+
*
198+
* When used with a string list, this limit will apply to each element individually, not to the size of the list as a whole.
199+
*/
200+
@StableAPI(since = "0.10.0")
201+
@Documented
202+
@Retention(RetentionPolicy.RUNTIME)
203+
@Target(ElementType.FIELD)
204+
@interface StringMaxLength {
205+
int value();
206+
}
207+
149208
/**
150209
* A regex pattern for restricting the allowed strings.
151210
*/
211+
@StableAPI(since = "0.6.0")
152212
@Documented
153213
@Retention(RetentionPolicy.RUNTIME)
154214
@Target(ElementType.FIELD)
@@ -160,6 +220,7 @@
160220
* The default value for an Enum field. Not having a default is deprecated since 0.10, and will be strongly
161221
* enforced in 0.11+!
162222
*/
223+
@StableAPI(since = "0.6.0")
163224
@Documented
164225
@Retention(RetentionPolicy.RUNTIME)
165226
@Target(ElementType.FIELD)
@@ -171,16 +232,82 @@
171232
* The default value for a string array field. Not having a default is deprecated since 0.10, and will be strongly
172233
* enforced in 0.11+!
173234
*/
235+
@StableAPI(since = "0.6.0")
174236
@Documented
175237
@Retention(RetentionPolicy.RUNTIME)
176238
@Target(ElementType.FIELD)
177239
@interface DefaultStringList {
178240
String[] value();
179241
}
180242

243+
/**
244+
* The default value for a double array field. Not having a default is deprecated since 0.10, and will be strongly
245+
* enforced in 0.11+!
246+
*/
247+
@StableAPI(since = "0.10.0")
248+
@Documented
249+
@Retention(RetentionPolicy.RUNTIME)
250+
@Target(ElementType.FIELD)
251+
@interface DefaultDoubleList {
252+
double[] value();
253+
}
254+
255+
/**
256+
* The default value for an int array field. Not having a default is deprecated since 0.10, and will be strongly
257+
* enforced in 0.11+!
258+
*/
259+
@StableAPI(since = "0.10.0")
260+
@Documented
261+
@Retention(RetentionPolicy.RUNTIME)
262+
@Target(ElementType.FIELD)
263+
@interface DefaultIntList {
264+
int[] value();
265+
}
266+
267+
/**
268+
* The default value for an boolean array field. Not having a default is deprecated since 0.10, and will be strongly
269+
* enforced in 0.11+!
270+
*/
271+
@StableAPI(since = "0.10.0")
272+
@Documented
273+
@Retention(RetentionPolicy.RUNTIME)
274+
@Target(ElementType.FIELD)
275+
@interface DefaultBooleanList {
276+
boolean[] value();
277+
}
278+
279+
/**
280+
* If this annotation is present, the list in the config will be forced to have exactly the amount of elements as
281+
* the default value.
282+
*/
283+
@StableAPI(since = "0.10.0")
284+
@Documented
285+
@Retention(RetentionPolicy.RUNTIME)
286+
@Target(ElementType.FIELD)
287+
@interface ListFixedLength {
288+
}
289+
290+
/**
291+
* This annotation limits the maximum number of elements present in an array configuration. Only effective if
292+
* {@link ListFixedLength} is NOT present.
293+
*
294+
* Note: If this annotation is not present, the maximum length will be implicitly set to 256 to avoid malicious
295+
* synchronizations that would make clients run out of memory!
296+
*/
297+
@StableAPI(since = "0.10.0")
298+
@Documented
299+
@Retention(RetentionPolicy.RUNTIME)
300+
@Target(ElementType.FIELD)
301+
@interface ListMaxLength {
302+
int value();
303+
}
304+
305+
306+
181307
/**
182308
* The name of this config property in the config file. If not specified, the field's name will be used instead.
183309
*/
310+
@StableAPI(since = "0.6.0")
184311
@Documented
185312
@Retention(RetentionPolicy.RUNTIME)
186313
@Target(ElementType.FIELD)
@@ -191,6 +318,7 @@
191318
/**
192319
* Whether the specific configuration needs a minecraft restart to be applied.
193320
*/
321+
@StableAPI(since = "0.6.0")
194322
@Documented
195323
@Retention(RetentionPolicy.RUNTIME)
196324
@Target({ElementType.FIELD, ElementType.TYPE})
@@ -200,14 +328,15 @@
200328
/**
201329
* Whether the specific configuration needs a world/server rejoin to be applied.
202330
*/
331+
@StableAPI(since = "0.6.0")
203332
@Documented
204333
@Retention(RetentionPolicy.RUNTIME)
205334
@Target({ElementType.FIELD, ElementType.TYPE})
206335
@interface RequiresWorldRestart {
207336
}
208337

209338
/**
210-
* Signals that this configuration entry/class should be synchronized between the client and the server when
339+
* Signals that this configuration class should be synchronized between the client and the server when
211340
* joining a multiplayer instance.
212341
*
213342
* Note that synchronization ALWAYS happens FROM the server TO the client. The server should NEVER attempt to get
@@ -216,20 +345,17 @@
216345
@StableAPI(since = "0.10.0")
217346
@Documented
218347
@Retention(RetentionPolicy.RUNTIME)
219-
@Target({ElementType.FIELD, ElementType.TYPE})
348+
@Target(ElementType.TYPE)
220349
@interface Synchronize {
221-
/**
222-
* This is a limit on how many bytes the client will accept from the server. If this limit is exceeded,
223-
* the client shall refuse to connect to the server. For String[]-s, the amount of bytes is the sum of all
224-
* strings inside the array.<br><br>
225-
*
226-
* This limitation option exists to avoid malicious servers flooding clients with data.<br><br>
227-
*
228-
* By default, the client will accept any amount of bytes.<br><br>
229-
*
230-
* This only applies for String and String[] configurations, and is ignored on the other config types.
231-
* For enums, this value is computed automatically.
232-
*/
233-
int maxLength();
350+
}
351+
352+
/**
353+
* Use this to mark config fields you don't want to synchronize in a class marked with {@link Synchronize}.
354+
*/
355+
@StableAPI(since = "0.10.0")
356+
@Documented
357+
@Retention(RetentionPolicy.RUNTIME)
358+
@Target(ElementType.FIELD)
359+
@interface NoSync {
234360
}
235361
}

0 commit comments

Comments
 (0)