Skip to content

Commit 9b2da1a

Browse files
authored
Update for configurate (#91)
* Update for configurate * Update required API limit in extension.yml due to the bump * Fix extra newline * Remove bad import * And now it works
1 parent f208e20 commit 9b2da1a

18 files changed

+185
-50
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
exclude group: 'io.netty'
3333
exclude group: 'io.netty.incubator'
3434
}
35+
compileOnly libs.yamlConfigurate
3536

3637
implementation libs.sqlite
3738
implementation libs.mysql

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[versions]
2-
geyser = "2.7.0-SNAPSHOT"
2+
geyser = "2.9.1-SNAPSHOT"
33
sqlite = "3.49.1.0"
44
mysql = "9.2.0"
5+
yamlConfigurate = "4.2.0-GeyserMC-20251111.004649-11"
56

67
[libraries]
78
geyser-core = { group = "org.geysermc.geyser", name = "core", version.ref = "geyser" }
89
geyser-api = { group = "org.geysermc.geyser", name = "api", version.ref = "geyser" }
910
sqlite = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqlite" }
1011
mysql = { group = "com.mysql", name = "mysql-connector-j", version.ref = "mysql" }
12+
yamlConfigurate = { module = "org.spongepowered:configurate-yaml", version.ref = "yamlConfigurate" }
1113

1214
[bundles]
1315
geyser = [

src/main/java/org/geysermc/extension/connect/GeyserConnect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ public void onPostInitialize(GeyserPostInitializeEvent event) {
103103

104104
// Remove all saved logins to prevent issues connecting
105105
// Maybe worth adding support for this later
106-
geyserInstance.getConfig().getSavedUserLogins().clear();
106+
geyserInstance.config().savedUserLogins().clear();
107107

108-
if (geyserInstance.getConfig().isPassthroughMotd() || geyserInstance.getConfig().isPassthroughPlayerCounts()) {
108+
if (geyserInstance.config().motd().passthroughMotd() || geyserInstance.config().motd().passthroughPlayerCounts()) {
109109
this.logger().warning("Either `passthrough-motd` or `passthrough-player-counts` is enabled in the config, this will likely produce errors");
110110
}
111111

112112
// If we are using floodgate then disable the extension.
113113
// GeyserConnect also doesn't support the connection sequence that occurs when the default RemoteServer
114114
// auth-type is offline (and there is no reason to change it when GeyserConnect is in use).
115-
if (geyserInstance.getConfig().getRemote().authType() != AuthType.ONLINE) {
115+
if (geyserInstance.config().java().authType() != AuthType.ONLINE) {
116116
this.logger().error("auth-type is not set to 'online' in the Geyser config, this will break GeyserConnect. Disabling!");
117117
this.disable();
118118
}
@@ -122,7 +122,7 @@ public void onPostInitialize(GeyserPostInitializeEvent event) {
122122
public void onSessionInitialize(SessionInitializeEvent event) {
123123
GeyserSession session = (GeyserSession) event.connection();
124124
if (config().hardPlayerLimit()) {
125-
if (session.getGeyser().getSessionManager().size() >= session.getGeyser().getConfig().getMaxPlayers()) {
125+
if (session.getGeyser().getSessionManager().size() >= session.getGeyser().config().motd().maxPlayers()) {
126126
session.disconnect("disconnectionScreen.serverFull");
127127
}
128128
}

src/main/java/org/geysermc/extension/connect/PacketHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public PacketHandler(GeyserConnect geyserConnect, GeyserSession session, Bedrock
6767
}
6868

6969
@Override
70-
public void onDisconnect(String reason) {
70+
public void onDisconnect(CharSequence reason) {
7171
// The user has disconnected without having connected to an actual server. If they have connected to
7272
// a server (transfer packet or geyser proxy), then the original packet handler has been restored.
7373
ServerManager.unloadServers(session);

src/main/java/org/geysermc/extension/connect/config/Config.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525

2626
package org.geysermc.extension.connect.config;
2727

28-
import com.fasterxml.jackson.annotation.JsonProperty;
2928
import org.geysermc.extension.connect.utils.Server;
29+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
3030

3131
import java.util.List;
3232

33+
@ConfigSerializable
3334
public record Config(
34-
@JsonProperty("welcome-file") String welcomeFile,
35-
@JsonProperty("hard-player-limit") boolean hardPlayerLimit,
35+
String welcomeFile,
36+
boolean hardPlayerLimit,
3637
List<Server> servers,
37-
@JsonProperty("custom-servers") CustomServersSection customServers,
38+
CustomServersSection customServers,
3839
VirtualHostSection vhost) {
3940
}

src/main/java/org/geysermc/extension/connect/config/ConfigLoader.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,27 @@
2525

2626
package org.geysermc.extension.connect.config;
2727

28-
import com.fasterxml.jackson.databind.DeserializationFeature;
29-
import com.fasterxml.jackson.databind.ObjectMapper;
30-
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
28+
import org.geysermc.extension.connect.config.serializers.ServerCategorySerializer;
29+
import org.geysermc.extension.connect.config.serializers.StorageTypeSerializer;
30+
import org.geysermc.extension.connect.utils.ServerCategory;
3131
import org.geysermc.geyser.api.extension.Extension;
32+
import org.spongepowered.configurate.CommentedConfigurationNode;
33+
import org.spongepowered.configurate.serialize.ScalarSerializer;
34+
import org.spongepowered.configurate.serialize.SerializationException;
35+
import org.spongepowered.configurate.yaml.NodeStyle;
36+
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
3237

3338
import java.io.File;
3439
import java.io.FileWriter;
3540
import java.io.IOException;
3641
import java.io.InputStream;
42+
import java.lang.reflect.Type;
3743
import java.net.URISyntaxException;
3844
import java.nio.file.FileSystem;
3945
import java.nio.file.FileSystems;
4046
import java.nio.file.Files;
4147
import java.util.Collections;
48+
import java.util.function.Predicate;
4249

4350
public class ConfigLoader {
4451
public static <T> T load(Extension extension, Class<?> extensionClass, Class<T> configClass) {
@@ -74,9 +81,21 @@ public static <T> T load(Extension extension, Class<?> extensionClass, Class<T>
7481

7582
// Load the config file
7683
try {
77-
return new ObjectMapper(new YAMLFactory())
78-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
79-
.readValue(configFile, configClass);
84+
YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
85+
.file(configFile)
86+
.indent(2)
87+
.nodeStyle(NodeStyle.BLOCK)
88+
.defaultOptions(options ->
89+
options.serializers(builder ->
90+
builder.register(new StorageTypeSerializer())
91+
.register(new ServerCategorySerializer())
92+
)
93+
)
94+
.build();
95+
96+
CommentedConfigurationNode rootNode = loader.load();
97+
98+
return rootNode.get(configClass);
8099
} catch (IOException e) {
81100
extension.logger().error("Failed to load config", e);
82101
return null;

src/main/java/org/geysermc/extension/connect/config/CustomServersSection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
package org.geysermc.extension.connect.config;
2727

28-
import com.fasterxml.jackson.annotation.JsonProperty;
2928
import org.geysermc.extension.connect.storage.AbstractStorageManager;
29+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
3030

31+
@ConfigSerializable
3132
public record CustomServersSection(
3233
boolean enabled,
3334
int max,
34-
@JsonProperty("storage-type") AbstractStorageManager.StorageType storageType,
35+
AbstractStorageManager.StorageType storageType,
3536
MySQLConnectionSection mysql) {
3637
}

src/main/java/org/geysermc/extension/connect/config/MySQLConnectionSection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
package org.geysermc.extension.connect.config;
2727

28+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
29+
30+
@ConfigSerializable
2831
public record MySQLConnectionSection(
2932
String user,
3033
String pass,

src/main/java/org/geysermc/extension/connect/config/VirtualHostSection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
package org.geysermc.extension.connect.config;
2727

28-
import com.fasterxml.jackson.annotation.JsonProperty;
28+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
2929

3030
import java.util.List;
3131

32+
@ConfigSerializable
3233
public record VirtualHostSection(
3334
boolean enabled,
34-
@JsonProperty("domains") List<String> domains) {
35+
List<String> domains) {
3536
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2019-2025 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/GeyserConnect
24+
*/
25+
26+
package org.geysermc.extension.connect.config.serializers;
27+
28+
import io.leangen.geantyref.TypeToken;
29+
import org.geysermc.extension.connect.utils.ServerCategory;
30+
import org.spongepowered.configurate.serialize.ScalarSerializer;
31+
import org.spongepowered.configurate.serialize.Scalars;
32+
import org.spongepowered.configurate.serialize.SerializationException;
33+
34+
import java.lang.reflect.Type;
35+
import java.util.function.Predicate;
36+
37+
public class ServerCategorySerializer extends ScalarSerializer<ServerCategory> {
38+
public ServerCategorySerializer() {
39+
super(new TypeToken<>() {});
40+
}
41+
42+
@Override
43+
public ServerCategory deserialize(Type type, Object obj) throws SerializationException {
44+
return (ServerCategory) Scalars.ENUM.deserialize(type, obj);
45+
}
46+
47+
@Override
48+
protected Object serialize(ServerCategory item, Predicate<Class<?>> typeSupported) {
49+
return item.name();
50+
}
51+
}

0 commit comments

Comments
 (0)