@@ -309,56 +309,55 @@ what fits best in your situation.
309
309
310
310
## Configuration files
311
311
312
- To use a configurable value in your patch, add a new entry in either the
313
- ` PaperConfig ` or ` PaperWorldConfig ` classes. Use ` PaperConfig ` if a value
312
+ To use a configurable value in your patch, add a new field in either the
313
+ ` GlobalConfiguration ` or ` WorldConfiguration ` classes (inside the
314
+ ` io.papermc.paper.configuration ` package). Use ` GlobalConfiguration ` if a value
314
315
must remain the same throughout all worlds, or the latter if it can change
315
316
between worlds. World-specific configuration options are preferred whenever
316
317
possible.
317
318
318
- ### PaperConfig example
319
-
319
+ ### Example
320
+ This is adding a new miscellaneous setting that doesn't seem to fit in other categories.
321
+ Try to check and see if an existing category (inner class) exists that matches
322
+ whatever configuration option you are adding.
320
323
``` java
321
- public static boolean saveEmptyScoreboardTeams = false ;
322
- private static void saveEmptyScoreboardTeams() {
323
- // This is called automatically!
324
- // The name also doesn't matter.
325
- saveEmptyScoreboardTeams = getBoolean(" settings.save-empty-scoreboard-teams" , false );
324
+ public class GlobalConfiguration {
325
+ // other sections
326
+ public class Misc extends ConfigurationPart {
327
+ // other settings
328
+ public boolean lagCompensateBlockBreaking = true ;
329
+ public boolean useDimensionTypeForCustomSpawners = false ;
330
+ public int maxNumOfPlayers = 20 ; // This is the new setting
331
+ }
326
332
}
327
333
```
328
-
329
- Notice that the field is always public, but the setter is always private. This
330
- is important to the way the configuration generation system works. To access
331
- this value, reference it as you would any other static value:
332
-
334
+ You set the type of the setting as the field type, and the default value is the
335
+ initial field value. The name of the setting defaults to the snake-case of the
336
+ field name, so in this case it would be ` misc.max-num-of-players ` . You can use
337
+ the ` @Setting ` annotation to override that, but generally just try to set the
338
+ field name to what you want the setting to be called.
339
+
340
+ #### Accessing the value
341
+ If you added a new global config value, you can access it in the code just by
342
+ doing
333
343
``` java
334
- if ( ! PaperConfig . saveEmptyScoreboardTeams) {
344
+ int maxPlayers = GlobalConfiguration . get() . misc . maxNumOfPlayers;
335
345
```
336
-
337
- It is often preferred that you use the fully qualified name for the
338
- configuration class when accessing it, like so:
339
- `com.destroystokyo.paper.PaperConfig.valueHere`.
340
- If this is not done, a developer for Paper might fix that for you before
341
- merging, but it's always nice if you make it a habit where you only need 1-2
342
- lines changed.
343
-
344
- ### PaperWorldConfig example
345
-
346
+ Generally for global config values you will use the fully qualified class name,
347
+ ` io.papermc.paper.configuration.GlobalConfiguration ` since it's not imported in
348
+ most places.
349
+ ---
350
+ If you are adding a new world config value, you must have access to an instance
351
+ of the ` net.minecraft.world.level.Level ` which you can then access the config by doing
346
352
``` java
347
- public boolean useInhabitedTime = true;
348
- private void useInhabitedTime() {
349
- // This is called automatically!
350
- // The name also doesn't matter.
351
- useInhabitedTime = getBoolean ("use -chunk -inhabited -timer ", true );
352
- }
353
+ int maxPlayers = level. paperConfig(). misc. maxNumOfPlayers;
353
354
```
354
355
355
- Again , notice that the field is always public , but the setter is always private .
356
- To access this value, you' ll need an instance of the `net.minecraft.world.level.Level`
357
- object:
358
-
359
- ```java
360
- return this.level.paperConfig.useInhabitedTime ? this.inhabitedTime : 0;
361
- ```
356
+ #### Committing changes
357
+ All changes to the ` GlobalConfiguration ` and ` WorldConfiguration ` files
358
+ should be done in the commit that created them. So do an interactive rebase
359
+ or fixup to apply just those changes to that commit, then add a new commit
360
+ that includes the logic that uses that option in the server somewhere.
362
361
363
362
## Testing API changes
364
363
0 commit comments