20
20
*/
21
21
package com .falsepattern .lib .config ;
22
22
23
+ import com .falsepattern .lib .DeprecationDetails ;
23
24
import com .falsepattern .lib .StableAPI ;
24
25
import java .lang .annotation .Documented ;
25
26
import java .lang .annotation .ElementType ;
26
27
import java .lang .annotation .Retention ;
27
28
import java .lang .annotation .RetentionPolicy ;
28
29
import java .lang .annotation .Target ;
30
+ import java .util .function .BiConsumer ;
29
31
30
32
/**
31
33
* A modern configuration system to replace the old and obtuse forge config system.
32
34
*
33
35
* 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[]) }!
35
37
*/
38
+ @ StableAPI (since = "0.6.0" )
36
39
@ Documented
37
40
@ Retention (RetentionPolicy .RUNTIME )
38
41
@ Target (ElementType .TYPE )
39
- @ StableAPI (since = "0.6.0" )
40
42
public @interface Config {
41
43
/**
42
44
* The mod id that this configuration is associated with.
51
53
/**
52
54
* The lang file key of this configuration. Used in config GUIs.
53
55
*/
56
+ @ StableAPI (since = "0.6.0" )
54
57
@ Documented
55
58
@ Retention (RetentionPolicy .RUNTIME )
56
59
@ Target ({ElementType .FIELD , ElementType .TYPE })
61
64
/**
62
65
* The description of the configuration.
63
66
*/
67
+ @ StableAPI (since = "0.6.0" )
64
68
@ Documented
65
69
@ Retention (RetentionPolicy .RUNTIME )
66
70
@ Target (ElementType .FIELD )
72
76
* If you have extra fields in the config class used for anything else other than configuring, you must annotate
73
77
* the using this so that the config engine doesn't pick them up.
74
78
*/
79
+ @ StableAPI (since = "0.6.0" )
75
80
@ Documented
76
81
@ Retention (RetentionPolicy .RUNTIME )
77
82
@ Target (ElementType .FIELD )
82
87
* The default value for a boolean field. Not having a default is deprecated since 0.10, and will be strongly
83
88
* enforced in 0.11+!
84
89
*/
90
+ @ StableAPI (since = "0.6.0" )
85
91
@ Documented
86
92
@ Retention (RetentionPolicy .RUNTIME )
87
93
@ Target (ElementType .FIELD )
92
98
/**
93
99
* The range of possible values an int config can have.
94
100
*/
101
+ @ StableAPI (since = "0.6.0" )
95
102
@ Documented
96
103
@ Retention (RetentionPolicy .RUNTIME )
97
104
@ Target (ElementType .FIELD )
105
112
* The default value for an int field. Not having a default is deprecated since 0.10, and will be strongly
106
113
* enforced in 0.11+!
107
114
*/
115
+ @ StableAPI (since = "0.6.0" )
108
116
@ Documented
109
117
@ Retention (RetentionPolicy .RUNTIME )
110
118
@ Target (ElementType .FIELD )
114
122
115
123
/**
116
124
* The range of possible values a float config can have.
125
+ * Notice: float configs are deprecated! Use double configs instead!
117
126
*/
127
+ @ Deprecated
128
+ @ DeprecationDetails (stableSince = "0.6.0" ,
129
+ deprecatedSince = "0.10.0" )
118
130
@ Documented
119
131
@ Retention (RetentionPolicy .RUNTIME )
120
132
@ Target (ElementType .FIELD )
121
133
@interface RangeFloat {
122
- float min () default Float .MIN_VALUE ;
134
+ float min () default - Float .MAX_VALUE ;
123
135
124
136
float max () default Float .MAX_VALUE ;
125
137
}
126
138
127
139
/**
128
140
* The default value for a float field. Not having a default is deprecated since 0.10, and will be strongly
129
141
* enforced in 0.11+!
142
+ * Notice: float configs are deprecated! Use double configs instead!
130
143
*/
144
+ @ Deprecated
145
+ @ DeprecationDetails (stableSince = "0.6.0" ,
146
+ deprecatedSince = "0.10.0" )
131
147
@ Documented
132
148
@ Retention (RetentionPolicy .RUNTIME )
133
149
@ Target (ElementType .FIELD )
134
150
@interface DefaultFloat {
135
151
float value ();
136
152
}
137
153
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
+
138
179
/**
139
180
* The default value for a String field. Not having a default is deprecated since 0.10, and will be strongly
140
181
* enforced in 0.11+!
141
182
*/
183
+ @ StableAPI (since = "0.6.0" )
142
184
@ Documented
143
185
@ Retention (RetentionPolicy .RUNTIME )
144
186
@ Target (ElementType .FIELD )
145
187
@interface DefaultString {
146
188
String value ();
147
189
}
148
190
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
+
149
208
/**
150
209
* A regex pattern for restricting the allowed strings.
151
210
*/
211
+ @ StableAPI (since = "0.6.0" )
152
212
@ Documented
153
213
@ Retention (RetentionPolicy .RUNTIME )
154
214
@ Target (ElementType .FIELD )
160
220
* The default value for an Enum field. Not having a default is deprecated since 0.10, and will be strongly
161
221
* enforced in 0.11+!
162
222
*/
223
+ @ StableAPI (since = "0.6.0" )
163
224
@ Documented
164
225
@ Retention (RetentionPolicy .RUNTIME )
165
226
@ Target (ElementType .FIELD )
171
232
* The default value for a string array field. Not having a default is deprecated since 0.10, and will be strongly
172
233
* enforced in 0.11+!
173
234
*/
235
+ @ StableAPI (since = "0.6.0" )
174
236
@ Documented
175
237
@ Retention (RetentionPolicy .RUNTIME )
176
238
@ Target (ElementType .FIELD )
177
239
@interface DefaultStringList {
178
240
String [] value ();
179
241
}
180
242
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
+
181
307
/**
182
308
* The name of this config property in the config file. If not specified, the field's name will be used instead.
183
309
*/
310
+ @ StableAPI (since = "0.6.0" )
184
311
@ Documented
185
312
@ Retention (RetentionPolicy .RUNTIME )
186
313
@ Target (ElementType .FIELD )
191
318
/**
192
319
* Whether the specific configuration needs a minecraft restart to be applied.
193
320
*/
321
+ @ StableAPI (since = "0.6.0" )
194
322
@ Documented
195
323
@ Retention (RetentionPolicy .RUNTIME )
196
324
@ Target ({ElementType .FIELD , ElementType .TYPE })
200
328
/**
201
329
* Whether the specific configuration needs a world/server rejoin to be applied.
202
330
*/
331
+ @ StableAPI (since = "0.6.0" )
203
332
@ Documented
204
333
@ Retention (RetentionPolicy .RUNTIME )
205
334
@ Target ({ElementType .FIELD , ElementType .TYPE })
206
335
@interface RequiresWorldRestart {
207
336
}
208
337
209
338
/**
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
211
340
* joining a multiplayer instance.
212
341
*
213
342
* Note that synchronization ALWAYS happens FROM the server TO the client. The server should NEVER attempt to get
216
345
@ StableAPI (since = "0.10.0" )
217
346
@ Documented
218
347
@ Retention (RetentionPolicy .RUNTIME )
219
- @ Target ({ ElementType .FIELD , ElementType . TYPE } )
348
+ @ Target (ElementType .TYPE )
220
349
@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 {
234
360
}
235
361
}
0 commit comments