Skip to content

Commit 23955b6

Browse files
authored
Bump version to 3.11.2 and update dependencies (#347)
2 parents 8e13c16 + 819c174 commit 23955b6

12 files changed

Lines changed: 195 additions & 22 deletions

File tree

buildSrc/src/main/kotlin/core-convention.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ tasks {
7272

7373
val relocationPrefix: String by project
7474
relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt")
75+
relocate("org.spongepowered.configurate", "$relocationPrefix.configurate")
7576
}
7677

7778
javadoc {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
77
javaVersion=25
88
mcVersion=26.1.2
99
group=dev.slne.surf.api
10-
version=3.11.1
10+
version=3.11.2
1111
relocationPrefix=dev.slne.surf.api.libs
1212
snapshot=false

gradle/libs.versions.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ dazzleconf = "1.4.0-M2"
5151
reflection-remapper = "0.1.3"
5252
brigadier = "1.0.500"
5353
datafixerupper = "8.0.16"
54-
configurate = "4.2.0"
54+
configurate = "1.0.0"
5555
more-persistent-data-types = "2.4.0"
56-
inventory-framework = "3.7.1"
56+
inventory-framework = "1.0.4"
5757
flogger = "0.9"
5858
aide-reflection = "1.3"
5959
auto-service = "1.1.1"
@@ -142,12 +142,12 @@ okhttp-kotlin = { module = "com.squareup.okhttp3:okhttp-coroutines", version.ref
142142
dazzleconf = { module = "space.arim.dazzleconf:dazzleconf-ext-snakeyaml", version.ref = "dazzleconf" }
143143
reflection-remapper = { module = "xyz.jpenilla:reflection-remapper", version.ref = "reflection-remapper" }
144144
brigadier = { module = "com.mojang:brigadier", version.ref = "brigadier" }
145-
configurate-yaml = { module = "org.spongepowered:configurate-yaml", version.ref = "configurate" }
146-
configurate-jackson = { module = "org.spongepowered:configurate-jackson", version.ref = "configurate" }
147-
configurate-kotlin = { module = "org.spongepowered:configurate-extra-kotlin", version.ref = "configurate" }
145+
configurate-yaml = { module = "dev.slne.forks.configurate:configurate-yaml", version.ref = "configurate" }
146+
configurate-jackson = { module = "dev.slne.forks.configurate:configurate-jackson", version.ref = "configurate" }
147+
configurate-kotlin = { module = "dev.slne.forks.configurate:configurate-extra-kotlin", version.ref = "configurate" }
148148
more-persistent-data-types = { module = "com.jeff-media:MorePersistentDataTypes", version.ref = "more-persistent-data-types" }
149-
inventory-framework-platform-paper = { module = "me.devnatan:inventory-framework-platform-paper", version.ref = "inventory-framework" }
150-
inventory-framework-platform-bukkit = { module = "me.devnatan:inventory-framework-platform-bukkit", version.ref = "inventory-framework" }
149+
inventory-framework-platform-paper = { module = "dev.slne.forks.inventoryframework:inventory-framework-platform-paper", version.ref = "inventory-framework" }
150+
inventory-framework-platform-bukkit = { module = "dev.slne.forks.inventoryframework:inventory-framework-platform-bukkit", version.ref = "inventory-framework" }
151151
flogger = { module = "com.google.flogger:flogger", version.ref = "flogger" }
152152
flogger-slf4j-backend = { module = "com.google.flogger:flogger-slf4j-backend", version.ref = "flogger" }
153153
aide-reflection = { module = "tech.hiddenproject:aide-reflection", version.ref = "aide-reflection" }

surf-api-core/surf-api-core/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ dependencies {
1515
compileOnlyApi(libs.fastutil)
1616
compileOnlyApi(libs.commandapi.core)
1717
compileOnlyApi(libs.brigadier)
18-
compileOnlyApi(libs.configurate.yaml)
19-
compileOnlyApi(libs.configurate.jackson)
18+
api(libs.configurate.yaml)
19+
api(libs.configurate.jackson)
2020
api(libs.configurate.kotlin)
2121
compileOnlyApi(libs.flogger)
2222
compileOnlyApi(libs.commons.math4.core)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package dev.slne.surf.api.core.config.manager;
2+
3+
import org.jspecify.annotations.NullMarked;
4+
5+
import java.lang.annotation.Annotation;
6+
import java.lang.invoke.MethodHandle;
7+
import java.lang.invoke.MethodHandles;
8+
import java.lang.invoke.MethodType;
9+
10+
@SuppressWarnings("unchecked")
11+
@NullMarked
12+
final class OldSpongeReflections {
13+
static final Class<? extends Annotation> OLD_CONFIG_SERIALIZABLE_ANNOTATION;
14+
static final Class<? extends Annotation> OLD_COMMENT_ANNOTATION;
15+
static final Class<? extends Annotation> OLD_MATCHES_ANNOTATION;
16+
static final Class<? extends Annotation> OLD_REQUIRED_ANNOTATION;
17+
static final Class<? extends Annotation> OLD_SETTING_ANNOTATION;
18+
19+
private static final MethodHandle OLD_COMMENT_OVERRIDE;
20+
private static final MethodHandle OLD_COMMENT_VALUE;
21+
22+
private static final MethodHandle OLD_MATCHES_VALUE;
23+
private static final MethodHandle OLD_MATCHES_FLAGS;
24+
private static final MethodHandle OLD_MATCHES_FAILURE_MESSAGE;
25+
26+
private static final MethodHandle OLD_SETTING_VALUE;
27+
private static final MethodHandle OLD_SETTING_NODE_FROM_PARENT;
28+
29+
static boolean isCommentOverride(final Annotation annotation) throws Throwable {
30+
return (boolean) OLD_COMMENT_OVERRIDE.invoke(annotation);
31+
}
32+
33+
static String getCommentValue(final Annotation annotation) throws Throwable {
34+
return (String) OLD_COMMENT_VALUE.invoke(annotation);
35+
}
36+
37+
static String getMatchesValue(final Annotation annotation) throws Throwable {
38+
return (String) OLD_MATCHES_VALUE.invoke(annotation);
39+
}
40+
41+
static int getMatchesFlags(final Annotation annotation) throws Throwable {
42+
return (int) OLD_MATCHES_FLAGS.invoke(annotation);
43+
}
44+
45+
static String getMatchesFailureMessage(final Annotation annotation) throws Throwable {
46+
return (String) OLD_MATCHES_FAILURE_MESSAGE.invoke(annotation);
47+
}
48+
49+
static String getSettingValue(final Annotation annotation) throws Throwable {
50+
return (String) OLD_SETTING_VALUE.invoke(annotation);
51+
}
52+
53+
static boolean isSettingNodeFromParent(final Annotation annotation) throws Throwable {
54+
return (boolean) OLD_SETTING_NODE_FROM_PARENT.invoke(annotation);
55+
}
56+
57+
static {
58+
try {
59+
final MethodHandles.Lookup lookup = MethodHandles.lookup();
60+
61+
OLD_CONFIG_SERIALIZABLE_ANNOTATION = (Class<? extends Annotation>) Class.forName("org.spongepowered".concat(".configurate.objectmapping.ConfigSerializable"));
62+
OLD_COMMENT_ANNOTATION = (Class<? extends Annotation>) Class.forName("org.spongepowered".concat(".configurate.objectmapping.meta.Comment"));
63+
OLD_MATCHES_ANNOTATION = (Class<? extends Annotation>) Class.forName("org.spongepowered".concat(".configurate.objectmapping.meta.Matches"));
64+
OLD_REQUIRED_ANNOTATION = (Class<? extends Annotation>) Class.forName("org.spongepowered".concat(".configurate.objectmapping.meta.Required"));
65+
OLD_SETTING_ANNOTATION = (Class<? extends Annotation>) Class.forName("org.spongepowered".concat(".configurate.objectmapping.meta.Setting"));
66+
67+
OLD_COMMENT_OVERRIDE = lookup.findVirtual(OLD_COMMENT_ANNOTATION, "override", MethodType.methodType(boolean.class));
68+
OLD_COMMENT_VALUE = lookup.findVirtual(OLD_COMMENT_ANNOTATION, "value", MethodType.methodType(String.class));
69+
70+
OLD_MATCHES_VALUE = lookup.findVirtual(OLD_MATCHES_ANNOTATION, "value", MethodType.methodType(String.class));
71+
OLD_MATCHES_FLAGS = lookup.findVirtual(OLD_MATCHES_ANNOTATION, "flags", MethodType.methodType(int.class));
72+
OLD_MATCHES_FAILURE_MESSAGE = lookup.findVirtual(OLD_MATCHES_ANNOTATION, "failureMessage", MethodType.methodType(String.class));
73+
74+
OLD_SETTING_VALUE = lookup.findVirtual(OLD_SETTING_ANNOTATION, "value", MethodType.methodType(String.class));
75+
OLD_SETTING_NODE_FROM_PARENT = lookup.findVirtual(OLD_SETTING_ANNOTATION, "nodeFromParent", MethodType.methodType(boolean.class));
76+
77+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
78+
throw new ExceptionInInitializerError(e);
79+
}
80+
}
81+
}

surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/manager/SpongeConfigManager.kt

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ import dev.slne.surf.api.core.config.migration.ConfigMigration
88
import dev.slne.surf.api.core.config.migration.ConfigMigrationBuilder
99
import dev.slne.surf.api.core.config.serializer.surfSpongeConfigSerializers
1010
import dev.slne.surf.api.core.util.logger
11+
import io.leangen.geantyref.GenericTypeReflector
12+
import org.spongepowered.configurate.CommentedConfigurationNodeIntermediary
1113
import org.spongepowered.configurate.ConfigurateException
1214
import org.spongepowered.configurate.ConfigurationNode
1315
import org.spongepowered.configurate.ScopedConfigurationNode
1416
import org.spongepowered.configurate.jackson.JacksonConfigurationLoader
17+
import org.spongepowered.configurate.kotlin.dataClassFieldDiscoverer
1518
import org.spongepowered.configurate.loader.AbstractConfigurationLoader
1619
import org.spongepowered.configurate.loader.ConfigurationLoader
20+
import org.spongepowered.configurate.objectmapping.ObjectMapper
21+
import org.spongepowered.configurate.objectmapping.meta.Constraint
22+
import org.spongepowered.configurate.objectmapping.meta.NodeResolver
1723
import org.spongepowered.configurate.serialize.SerializationException
24+
import org.spongepowered.configurate.serialize.TypeSerializerCollection
1825
import org.spongepowered.configurate.yaml.NodeStyle
1926
import org.spongepowered.configurate.yaml.YamlConfigurationLoader
2027
import java.io.Serial
2128
import java.io.UncheckedIOException
2229
import java.nio.file.Path
30+
import java.text.MessageFormat
31+
import java.util.*
32+
import java.util.regex.Pattern
2333

2434
/**
2535
* Manages configurations using Sponge's Configurate library, including loading, saving, and reloading configurations.
@@ -186,7 +196,7 @@ class SpongeConfigManager<C> private constructor(
186196
migrations: ConfigMigrationBuilder = ConfigMigrationBuilder()
187197
): SpongeConfigManager<C> = buildConfigManager(
188198
"https://yamlchecker.com/",
189-
YamlConfigurationLoader.builder().nodeStyle(NodeStyle.BLOCK),
199+
YamlConfigurationLoader.builder().nodeStyle(NodeStyle.BLOCK).commentsEnabled(true),
190200
configClass,
191201
configFolder,
192202
configFileName,
@@ -229,8 +239,16 @@ class SpongeConfigManager<C> private constructor(
229239
): SpongeConfigManager<C> {
230240
val loader = builder.path(configFolder.resolve(configFileName))
231241
.defaultOptions {
232-
it.serializers(surfSpongeConfigSerializers.buildSerializersModule())
233-
.shouldCopyDefaults(true)
242+
it.serializers { serializers ->
243+
surfSpongeConfigSerializers.buildSerializersModule().accept(serializers)
244+
245+
try {
246+
OldSpongeReflections.OLD_CONFIG_SERIALIZABLE_ANNOTATION // If this throws an exception, there are no non-relocated annotations, no need to register — most likely the standalone version
247+
serializers.registerBackwardsCompatibleSerializers()
248+
} catch (_: Throwable) {
249+
// no non-relocated annotations, no need to register
250+
}
251+
}.shouldCopyDefaults(true)
234252
}
235253
.build()
236254

@@ -268,6 +286,75 @@ class SpongeConfigManager<C> private constructor(
268286
throw LoadConfigException(e)
269287
}
270288
}
289+
290+
private fun TypeSerializerCollection.Builder.registerBackwardsCompatibleSerializers() {
291+
register(
292+
{ type ->
293+
GenericTypeReflector.annotate(type)
294+
.isAnnotationPresent(OldSpongeReflections.OLD_CONFIG_SERIALIZABLE_ANNOTATION)
295+
},
296+
ObjectMapper.factoryBuilder()
297+
.addDiscoverer(dataClassFieldDiscoverer())
298+
.addProcessor(OldSpongeReflections.OLD_COMMENT_ANNOTATION) { data, _ ->
299+
{ _, destination ->
300+
if (destination is CommentedConfigurationNodeIntermediary<*>) {
301+
if (OldSpongeReflections.isCommentOverride(data)) {
302+
destination.comment(OldSpongeReflections.getCommentValue(data))
303+
} else {
304+
destination.commentIfAbsent(OldSpongeReflections.getCommentValue(data))
305+
}
306+
}
307+
}
308+
}
309+
.addConstraint(
310+
OldSpongeReflections.OLD_MATCHES_ANNOTATION,
311+
String::class.java
312+
) { data, _ ->
313+
val value = OldSpongeReflections.getMatchesValue(data)
314+
val flags = OldSpongeReflections.getMatchesFlags(data)
315+
val failureMessage = OldSpongeReflections.getMatchesFailureMessage(data)
316+
317+
val test = Pattern.compile(value, flags)
318+
val format = MessageFormat(failureMessage, Locale.getDefault())
319+
320+
Constraint { toValidate ->
321+
if (toValidate != null) {
322+
val match = test.matcher(toValidate)
323+
if (!match.matches()) {
324+
throw SerializationException(format.format(arrayOf(toValidate, value)))
325+
}
326+
}
327+
}
328+
}
329+
.addConstraint(OldSpongeReflections.OLD_REQUIRED_ANNOTATION, Constraint.required())
330+
.addNodeResolver(fun(name, element): NodeResolver? {
331+
if (element.isAnnotationPresent(OldSpongeReflections.OLD_SETTING_ANNOTATION)) {
332+
val annotation =
333+
element.getAnnotation(OldSpongeReflections.OLD_SETTING_ANNOTATION)
334+
val key = OldSpongeReflections.getSettingValue(annotation)
335+
if (key.isNotEmpty()) {
336+
return { node -> node.node(key) }
337+
}
338+
}
339+
340+
return null
341+
})
342+
.addNodeResolver(fun(name, element): NodeResolver? {
343+
if (element.isAnnotationPresent(OldSpongeReflections.OLD_SETTING_ANNOTATION)) {
344+
val annotation =
345+
element.getAnnotation(OldSpongeReflections.OLD_SETTING_ANNOTATION)
346+
val nodeFromParent = OldSpongeReflections.isSettingNodeFromParent(annotation)
347+
if (nodeFromParent) {
348+
return { node -> node }
349+
}
350+
}
351+
352+
return null
353+
})
354+
.build()
355+
.asTypeSerializer()
356+
)
357+
}
271358
}
272359
}
273360

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/core/CoreSurfPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ internal abstract class AbstractCoreSurfPlugin<E : CoreSurfExtension>(
1111
"com.mojang.serialization" relocatesTo "mojang.serialization"
1212
"com.mojang.datafixers" relocatesTo "mojang.datafixers"
1313
"net.kyori.adventure.nbt" relocatesTo "kyori.nbt"
14+
"org.spongepowered.configurate" relocatesTo "configurate"
1415
}
1516

1617
final override fun Project.afterEvaluated0(extension: E) {

surf-api-paper/surf-api-paper-plugin-test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/PaperPluginMain.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import com.destroystokyo.paper.event.server.ServerTickStartEvent
55
import com.github.shynixn.mccoroutine.folia.SuspendingJavaPlugin
66
import dev.jorel.commandapi.CommandAPI
77
import dev.slne.surf.api.core.component.surfComponentApi
8+
import dev.slne.surf.api.core.config.SurfConfigApi
89
import dev.slne.surf.api.paper.event.listen
910
import dev.slne.surf.api.paper.inventory.framework.register
1011
import dev.slne.surf.api.paper.nms.NmsUseWithCaution
1112
import dev.slne.surf.api.paper.packet.listener.SurfPaperPacketListenerApi
1213
import dev.slne.surf.api.paper.test.command.SurfApiTestCommand
1314
import dev.slne.surf.api.paper.test.command.subcommands.reflection.Reflection
15+
import dev.slne.surf.api.paper.test.config.TestConfig2
1416
import dev.slne.surf.api.paper.test.listener.ChatListener
1517
import dev.slne.surf.surfapi.bukkit.test.command.dialog.dialogTestCommand
1618
import dev.slne.surf.surfapi.bukkit.test.command.subcommands.inventory.TestInventoryView
@@ -31,6 +33,8 @@ class PaperPluginMain : SuspendingJavaPlugin() {
3133
SurfPaperPacketListenerApi.registerListeners(ChatListener())
3234
TestInventoryView.register()
3335
testInventoryViewDsl.register()
36+
37+
SurfConfigApi.createSpongeYmlConfig(TestConfig2::class.java, dataPath, "test-config-2.yml")
3438
}
3539

3640
override suspend fun onEnableAsync() {

surf-api-paper/surf-api-paper-plugin-test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/config/ModernTestConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package dev.slne.surf.surfapi.bukkit.test.config
33
import dev.slne.surf.api.core.config.SpongeYmlConfigClass
44
import dev.slne.surf.surfapi.bukkit.test.plugin
55
import org.spongepowered.configurate.objectmapping.ConfigSerializable
6+
import org.spongepowered.configurate.objectmapping.meta.Comment
67

78
@ConfigSerializable
89
data class ModernTestConfig(
10+
@Comment("This is a modern config!")
911
var message: String = "Hello from Modern Config!",
1012
var number: Int = 42,
1113
var enabled: Boolean = true

surf-api-paper/surf-api-paper-server/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ dependencies {
3939
paperLibrary(libs.okhttp)
4040
paperLibrary(libs.fastutil)
4141
paperLibrary(libs.reflection.remapper)
42-
paperLibrary(libs.configurate.yaml)
43-
paperLibrary(libs.configurate.jackson)
4442
paperLibrary(libs.more.persistent.data.types)
4543
paperLibrary(libs.flogger)
4644
paperLibrary(libs.flogger.slf4j.backend)

0 commit comments

Comments
 (0)