@@ -113,10 +113,10 @@ index 0000000000000000000000000000000000000000..7a4a7a654fe2516ed894a68f2657344d
113
113
+ }
114
114
diff --git a/src/main/java/io/papermc/paper/configuration/Configurations.java b/src/main/java/io/papermc/paper/configuration/Configurations.java
115
115
new file mode 100644
116
- index 0000000000000000000000000000000000000000..844275e8671c62633e370ae3d4e0738eedac3e7e
116
+ index 0000000000000000000000000000000000000000..13d7d1c24ec9192d0163f6eedeac8fca82b6e80c
117
117
--- /dev/null
118
118
+++ b/src/main/java/io/papermc/paper/configuration/Configurations.java
119
- @@ -0,0 +1,285 @@
119
+ @@ -0,0 +1,296 @@
120
120
+ package io.papermc.paper.configuration;
121
121
+
122
122
+ import io.leangen.geantyref.TypeToken;
@@ -248,23 +248,34 @@ index 0000000000000000000000000000000000000000..844275e8671c62633e370ae3d4e0738e
248
248
+ final ContextMap contextMap = this.createDefaultContextMap()
249
249
+ .put(FIRST_DEFAULT)
250
250
+ .build();
251
- + final YamlConfigurationLoader loader = this.createDefaultWorldLoader(false, contextMap);
251
+ + final DefaultWorldLoader result = this.createDefaultWorldLoader(false, contextMap);
252
+ + final YamlConfigurationLoader loader = result.loader();
252
253
+ final ConfigurationNode node = loader.load();
254
+ + if (result.isNewFile()) { // add version to new files
255
+ + node.node(Configuration.VERSION_FIELD).raw(WorldConfiguration.CURRENT_VERSION);
256
+ + }
253
257
+ this.applyWorldConfigTransformations(contextMap, node);
254
258
+ final W instance = node.require(this.worldConfigClass);
255
259
+ node.set(this.worldConfigClass, instance);
256
260
+ loader.save(node);
257
261
+ }
258
262
+
259
- + private YamlConfigurationLoader createDefaultWorldLoader(final boolean requireFile, final ContextMap contextMap) {
263
+ + private DefaultWorldLoader createDefaultWorldLoader(final boolean requireFile, final ContextMap contextMap) {
260
264
+ final Path configFile = this.globalFolder.resolve(this.defaultWorldConfigFileName);
261
- + if (requireFile && !Files.exists(configFile)) {
265
+ + boolean willCreate = Files.notExists(configFile);
266
+ + if (requireFile && willCreate) {
262
267
+ throw new IllegalStateException("World defaults configuration file '" + configFile + "' doesn't exist");
263
268
+ }
264
- + return this.createWorldConfigLoaderBuilder(contextMap)
265
- + .defaultOptions(this.applyObjectMapperFactory(this.createWorldObjectMapperFactoryBuilder(contextMap).build()))
266
- + .path(configFile)
267
- + .build();
269
+ + return new DefaultWorldLoader(
270
+ + this.createWorldConfigLoaderBuilder(contextMap)
271
+ + .defaultOptions(this.applyObjectMapperFactory(this.createWorldObjectMapperFactoryBuilder(contextMap).build()))
272
+ + .path(configFile)
273
+ + .build(),
274
+ + willCreate
275
+ + );
276
+ + }
277
+ +
278
+ + private record DefaultWorldLoader(YamlConfigurationLoader loader, boolean isNewFile) {
268
279
+ }
269
280
+
270
281
+ protected ObjectMapper.Factory.Builder createWorldObjectMapperFactoryBuilder(final ContextMap contextMap) {
@@ -282,7 +293,7 @@ index 0000000000000000000000000000000000000000..844275e8671c62633e370ae3d4e0738e
282
293
+ }
283
294
+
284
295
+ protected W createWorldConfig(final ContextMap contextMap, final CheckedFunction<ConfigurationNode, W, SerializationException> creator) throws IOException {
285
- + final YamlConfigurationLoader defaultsLoader = this.createDefaultWorldLoader(true, this.createDefaultContextMap().build());
296
+ + final YamlConfigurationLoader defaultsLoader = this.createDefaultWorldLoader(true, this.createDefaultContextMap().build()).loader() ;
286
297
+ final ConfigurationNode defaultsNode = defaultsLoader.load();
287
298
+
288
299
+ boolean newFile = false;
@@ -299,7 +310,7 @@ index 0000000000000000000000000000000000000000..844275e8671c62633e370ae3d4e0738e
299
310
+ .path(worldConfigFile)
300
311
+ .build();
301
312
+ final ConfigurationNode worldNode = worldLoader.load();
302
- + if (newFile) {
313
+ + if (newFile) { // set the version field if new file
303
314
+ worldNode.node(Configuration.VERSION_FIELD).set(WorldConfiguration.CURRENT_VERSION);
304
315
+ }
305
316
+ this.applyWorldConfigTransformations(contextMap, worldNode);
@@ -2734,10 +2745,10 @@ index 0000000000000000000000000000000000000000..0300fb1e09d41465e4a50bfdc987b957
2734
2745
+ }
2735
2746
diff --git a/src/main/java/io/papermc/paper/configuration/transformation/global/LegacyPaperConfig.java b/src/main/java/io/papermc/paper/configuration/transformation/global/LegacyPaperConfig.java
2736
2747
new file mode 100644
2737
- index 0000000000000000000000000000000000000000..943cd629c48a60f108c7a724201cfcad07fcc4ff
2748
+ index 0000000000000000000000000000000000000000..3be5cb126e41a533e9453bbd6326cd1c10dd879d
2738
2749
--- /dev/null
2739
2750
+++ b/src/main/java/io/papermc/paper/configuration/transformation/global/LegacyPaperConfig.java
2740
- @@ -0,0 +1,250 @@
2751
+ @@ -0,0 +1,248 @@
2741
2752
+ package io.papermc.paper.configuration.transformation.global;
2742
2753
+
2743
2754
+ import com.mojang.logging.LogUtils;
@@ -2748,13 +2759,11 @@ index 0000000000000000000000000000000000000000..943cd629c48a60f108c7a724201cfcad
2748
2759
+ import net.kyori.adventure.text.format.NamedTextColor;
2749
2760
+ import net.kyori.adventure.text.minimessage.MiniMessage;
2750
2761
+ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2751
- + import net.minecraft.network.protocol.Packet;
2752
2762
+ import net.minecraft.network.protocol.game.ServerboundPlaceRecipePacket;
2753
2763
+ import org.bukkit.ChatColor;
2754
2764
+ import org.bukkit.configuration.file.YamlConfiguration;
2755
2765
+ import org.checkerframework.checker.nullness.qual.Nullable;
2756
2766
+ import org.slf4j.Logger;
2757
- + import org.spongepowered.configurate.BasicConfigurationNode;
2758
2767
+ import org.spongepowered.configurate.ConfigurationNode;
2759
2768
+ import org.spongepowered.configurate.transformation.ConfigurationTransformation;
2760
2769
+ import org.spongepowered.configurate.transformation.TransformAction;
@@ -3067,7 +3076,7 @@ index 0000000000000000000000000000000000000000..75f612b04f872d0d014fdc40b07c1511
3067
3076
+ }
3068
3077
diff --git a/src/main/java/io/papermc/paper/configuration/transformation/world/LegacyPaperWorldConfig.java b/src/main/java/io/papermc/paper/configuration/transformation/world/LegacyPaperWorldConfig.java
3069
3078
new file mode 100644
3070
- index 0000000000000000000000000000000000000000..4861470fee09c757874c02a2abbdf56e25404c2f
3079
+ index 0000000000000000000000000000000000000000..6af307481a6752529d87869760945cb140d05bed
3071
3080
--- /dev/null
3072
3081
+++ b/src/main/java/io/papermc/paper/configuration/transformation/world/LegacyPaperWorldConfig.java
3073
3082
@@ -0,0 +1,321 @@
@@ -3209,7 +3218,7 @@ index 0000000000000000000000000000000000000000..4861470fee09c757874c02a2abbdf56e
3209
3218
+ Map<String, Integer> rebuild = new HashMap<>();
3210
3219
+ value.childrenMap().forEach((key, node) -> {
3211
3220
+ String itemName = key.toString();
3212
- + final Optional<Holder<Item>> itemHolder = Registry.ITEM.getHolder(ResourceKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(itemName)));
3221
+ + final Optional<Holder<Item>> itemHolder = Registry.ITEM.getHolder(ResourceKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(itemName.toLowerCase(Locale.ENGLISH) )));
3213
3222
+ final @Nullable String item;
3214
3223
+ if (itemHolder.isEmpty()) {
3215
3224
+ final @Nullable Material bukkitMat = Material.matchMaterial(itemName);
@@ -3264,7 +3273,7 @@ index 0000000000000000000000000000000000000000..4861470fee09c757874c02a2abbdf56e
3264
3273
+ moveFromRoot(builder, "all-chunks-are-slime-chunks", "entities", "spawning");
3265
3274
+ moveFromRoot(builder, "skeleton-horse-thunder-spawn-chance", "entities", "spawning");
3266
3275
+ moveFromRoot(builder, "iron-golems-can-spawn-in-air", "entities", "spawning");
3267
- + moveFromRoot(builder, "alt-item-despawn-rate", "entities", "spawning"); // TODO versioned migration is broken, fix it here
3276
+ + moveFromRoot(builder, "alt-item-despawn-rate", "entities", "spawning");
3268
3277
+ moveFromRoot(builder, "count-all-mobs-for-spawning", "entities", "spawning");
3269
3278
+ moveFromRoot(builder, "creative-arrow-despawn-rate", "entities", "spawning");
3270
3279
+ moveFromRoot(builder, "non-player-arrow-despawn-rate", "entities", "spawning");
0 commit comments