Skip to content

Commit

Permalink
Start implementing Configurate config system
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed May 23, 2024
1 parent 6f4c29c commit 25e7deb
Show file tree
Hide file tree
Showing 10 changed files with 594 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bootstrap/spigot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ platformRelocate("net.kyori", "net.kyori.adventure.text.logger.slf4j.ComponentLo
platformRelocate("org.objectweb.asm")
platformRelocate("me.lucko.commodore")
platformRelocate("org.yaml") // Broken as of 1.20
platformRelocate("org.spongepowered")
platformRelocate("io.leangen.geantyref")

// These dependencies are already present on the platform
provided(libs.viaversion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.ConfigLoaderTemp;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.configuration.GeyserPluginConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.network.GameProtocol;
Expand Down Expand Up @@ -485,6 +487,7 @@ private boolean loadConfig() {
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml",
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this);
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserSpigotConfiguration.class);
ConfigLoaderTemp.load(GeyserPluginConfig.class);
} catch (IOException ex) {
getLogger().log(Level.SEVERE, GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.ConfigLoaderTemp;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.configuration.GeyserJacksonConfiguration;
import org.geysermc.geyser.configuration.GeyserRemoteConfig;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
Expand All @@ -59,12 +61,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;

This comment has been minimized.

Copy link
@toinouH

toinouH May 24, 2024

Contributor

IntellJ Evil

import java.util.stream.Collectors;

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

ConfigLoaderTemp.load(GeyserRemoteConfig.class);

handleArgsConfigOptions();

if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {
Expand Down
3 changes: 3 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ dependencies {

// Jackson JSON and YAML serialization
api(libs.bundles.jackson)
annotationProcessor(libs.configurate.`interface`.ap)
api(libs.configurate.`interface`)
implementation(libs.configurate.yaml)
api(libs.guava)

// Fastutil Maps
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/geysermc/geyser/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public final class Constants {

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

public static final int CONFIG_VERSION = 5;

static {
URI wsUri = null;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.configuration;

import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.interfaces.InterfaceDefaultOptions;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class ConfigLoaderTemp {
private static final String HEADER = """
--------------------------------
Geyser Configuration File
A bridge between Minecraft: Bedrock Edition and Minecraft: Java Edition.
GitHub: https://github.com/GeyserMC/Geyser
Discord: https://discord.gg/geysermc
Wiki: https://wiki.geysermc.org/
NOTICE: See https://wiki.geysermc.org/geyser/setup/ for the setup guide. Many video tutorials are outdated.
In most cases, especially with server hosting providers, further hosting-specific configuration is required.
--------------------------------""";

public static <T extends GeyserConfig> T load(Class<T> configClass) throws IOException {
var loader = YamlConfigurationLoader.builder()
.file(new File("newconfig.yml"))
.defaultOptions(InterfaceDefaultOptions.get()
.header(HEADER))
.build();
ConfigurationNode node = loader.load();
// temp fix for node.virtual() being broken
var virtual = !Files.exists(Path.of("newconfig.yml"));

// TODO needed or else Configurate breaks
var migrations = ConfigurationTransformation.versionedBuilder()
// Pre-Configurate
.addVersion(5, ConfigurationTransformation.builder()
.addAction(NodePath.path("legacyPingPassthrough"), (path, value) -> {
// Invert value
value.set(Boolean.FALSE.equals(value.get(boolean.class)));
return new Object[]{"integratedPingPassthrough"};
})
.addAction(NodePath.path("remote"), (path, value) ->
new Object[]{"java"})
.build())
.build();

migrations.apply(node);

T config = node.get(configClass);
System.out.println(config);

loader.save(node);

return config;
}
}
Loading

0 comments on commit 25e7deb

Please sign in to comment.