Skip to content

Commit 25e7deb

Browse files
committed
Start implementing Configurate config system
1 parent 6f4c29c commit 25e7deb

File tree

10 files changed

+594
-6
lines changed

10 files changed

+594
-6
lines changed

bootstrap/spigot/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ platformRelocate("net.kyori", "net.kyori.adventure.text.logger.slf4j.ComponentLo
2828
platformRelocate("org.objectweb.asm")
2929
platformRelocate("me.lucko.commodore")
3030
platformRelocate("org.yaml") // Broken as of 1.20
31+
platformRelocate("org.spongepowered")
32+
platformRelocate("io.leangen.geantyref")
3133

3234
// These dependencies are already present on the platform
3335
provided(libs.viaversion)

bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java

+3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
import org.geysermc.geyser.api.extension.Extension;
5353
import org.geysermc.geyser.api.util.PlatformType;
5454
import org.geysermc.geyser.command.GeyserCommandManager;
55+
import org.geysermc.geyser.configuration.ConfigLoaderTemp;
5556
import org.geysermc.geyser.configuration.GeyserConfiguration;
57+
import org.geysermc.geyser.configuration.GeyserPluginConfig;
5658
import org.geysermc.geyser.dump.BootstrapDumpInfo;
5759
import org.geysermc.geyser.level.WorldManager;
5860
import org.geysermc.geyser.network.GameProtocol;
@@ -485,6 +487,7 @@ private boolean loadConfig() {
485487
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml",
486488
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this);
487489
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserSpigotConfiguration.class);
490+
ConfigLoaderTemp.load(GeyserPluginConfig.class);
488491
} catch (IOException ex) {
489492
getLogger().log(Level.SEVERE, GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
490493
ex.printStackTrace();

bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
import org.geysermc.geyser.GeyserImpl;
4444
import org.geysermc.geyser.api.util.PlatformType;
4545
import org.geysermc.geyser.command.GeyserCommandManager;
46+
import org.geysermc.geyser.configuration.ConfigLoaderTemp;
4647
import org.geysermc.geyser.configuration.GeyserConfiguration;
4748
import org.geysermc.geyser.configuration.GeyserJacksonConfiguration;
49+
import org.geysermc.geyser.configuration.GeyserRemoteConfig;
4850
import org.geysermc.geyser.dump.BootstrapDumpInfo;
4951
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
5052
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
@@ -59,12 +61,7 @@
5961
import java.nio.file.Path;
6062
import java.nio.file.Paths;
6163
import java.text.MessageFormat;
62-
import java.util.HashMap;
63-
import java.util.List;
64-
import java.util.Locale;
65-
import java.util.Map;
66-
import java.util.Set;
67-
import java.util.UUID;
64+
import java.util.*;
6865
import java.util.stream.Collectors;
6966

7067
public class GeyserStandaloneBootstrap implements GeyserBootstrap {
@@ -201,6 +198,8 @@ public void onGeyserEnable() {
201198
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this);
202199
geyserConfig = FileUtils.loadConfig(configFile, GeyserStandaloneConfiguration.class);
203200

201+
ConfigLoaderTemp.load(GeyserRemoteConfig.class);
202+
204203
handleArgsConfigOptions();
205204

206205
if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {

core/build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ dependencies {
1515

1616
// Jackson JSON and YAML serialization
1717
api(libs.bundles.jackson)
18+
annotationProcessor(libs.configurate.`interface`.ap)
19+
api(libs.configurate.`interface`)
20+
implementation(libs.configurate.yaml)
1821
api(libs.guava)
1922

2023
// Fastutil Maps

core/src/main/java/org/geysermc/geyser/Constants.java

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public final class Constants {
4545

4646
public static final String MINECRAFT_SKIN_SERVER_URL = "https://textures.minecraft.net/texture/";
4747

48+
public static final int CONFIG_VERSION = 5;
49+
4850
static {
4951
URI wsUri = null;
5052
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2024 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.configuration;
27+
28+
import org.spongepowered.configurate.ConfigurationNode;
29+
import org.spongepowered.configurate.NodePath;
30+
import org.spongepowered.configurate.interfaces.InterfaceDefaultOptions;
31+
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
32+
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
import java.nio.file.Files;
37+
import java.nio.file.Path;
38+
39+
public class ConfigLoaderTemp {
40+
private static final String HEADER = """
41+
--------------------------------
42+
Geyser Configuration File
43+
44+
A bridge between Minecraft: Bedrock Edition and Minecraft: Java Edition.
45+
46+
GitHub: https://github.com/GeyserMC/Geyser
47+
Discord: https://discord.gg/geysermc
48+
Wiki: https://wiki.geysermc.org/
49+
50+
NOTICE: See https://wiki.geysermc.org/geyser/setup/ for the setup guide. Many video tutorials are outdated.
51+
In most cases, especially with server hosting providers, further hosting-specific configuration is required.
52+
--------------------------------""";
53+
54+
public static <T extends GeyserConfig> T load(Class<T> configClass) throws IOException {
55+
var loader = YamlConfigurationLoader.builder()
56+
.file(new File("newconfig.yml"))
57+
.defaultOptions(InterfaceDefaultOptions.get()
58+
.header(HEADER))
59+
.build();
60+
ConfigurationNode node = loader.load();
61+
// temp fix for node.virtual() being broken
62+
var virtual = !Files.exists(Path.of("newconfig.yml"));
63+
64+
// TODO needed or else Configurate breaks
65+
var migrations = ConfigurationTransformation.versionedBuilder()
66+
// Pre-Configurate
67+
.addVersion(5, ConfigurationTransformation.builder()
68+
.addAction(NodePath.path("legacyPingPassthrough"), (path, value) -> {
69+
// Invert value
70+
value.set(Boolean.FALSE.equals(value.get(boolean.class)));
71+
return new Object[]{"integratedPingPassthrough"};
72+
})
73+
.addAction(NodePath.path("remote"), (path, value) ->
74+
new Object[]{"java"})
75+
.build())
76+
.build();
77+
78+
migrations.apply(node);
79+
80+
T config = node.get(configClass);
81+
System.out.println(config);
82+
83+
loader.save(node);
84+
85+
return config;
86+
}
87+
}

0 commit comments

Comments
 (0)