Skip to content

Commit 9806283

Browse files
committed
Stop using Configurate interfaces due to issues
1 parent 294eb52 commit 9806283

File tree

4 files changed

+33
-43
lines changed

4 files changed

+33
-43
lines changed

core/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ plugins {
55
}
66

77
dependencies {
8-
annotationProcessor(libs.configurate.`interface`.ap)
9-
api(libs.configurate.`interface`)
10-
118
compileOnly(libs.adventure.api)
129
compileOnly(libs.adventure.minimessage)
1310
implementation(libs.cloud.core)

core/src/main/java/dev/triassic/template/configuration/ConfigurationManager.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.concurrent.atomic.AtomicReference;
2121
import org.spongepowered.configurate.CommentedConfigurationNode;
2222
import org.spongepowered.configurate.ConfigurateException;
23-
import org.spongepowered.configurate.interfaces.InterfaceDefaultOptions;
23+
import org.spongepowered.configurate.objectmapping.ObjectMapper;
2424
import org.spongepowered.configurate.objectmapping.meta.Processor;
2525
import org.spongepowered.configurate.yaml.NodeStyle;
2626
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
@@ -33,7 +33,7 @@
3333
* @param <T> the type of the configuration object
3434
*/
3535
public record ConfigurationManager<T>(
36-
Class<T> clazz,
36+
Class<T> configClass,
3737
YamlConfigurationLoader loader,
3838
AtomicReference<T> config
3939
) {
@@ -50,52 +50,59 @@ public record ConfigurationManager<T>(
5050
/**
5151
* Loads the configuration from the path and
5252
* creates a new {@link ConfigurationManager} instance.
53-
* If the configuration file does not exist, it will create a new one with default values.
5453
*
55-
* @param path the path to the directory containing the configuration file
56-
* @param clazz the class type of the configuration object
57-
* @param <T> the type of the configuration object
54+
* <p>If the configuration file does not exist, it'll create a new one with default values.</p>
55+
*
56+
* @param path the path to the directory containing the configuration file
57+
* @param configClass the class type of the configuration object
58+
* @param <T> the type of the configuration object
5859
* @return a {@link ConfigurationManager} instance containing the loaded configuration
5960
* @throws IOException if an error occurs while loading the configuration
6061
*/
6162
public static <T> ConfigurationManager<T> load(
6263
Path path,
63-
final Class<T> clazz,
64-
final PlatformType platformType
64+
Class<T> configClass,
65+
PlatformType platformType
6566
) throws IOException {
6667
path = path.resolve("config.yml");
6768

68-
final YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
69+
ObjectMapper.Factory mapperFactory = ObjectMapper.factoryBuilder()
70+
.addProcessor(ExcludePlatform.class, excludePlatform(platformType))
71+
.build();
72+
73+
YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
6974
.path(path)
7075
.indent(2)
7176
.nodeStyle(NodeStyle.BLOCK)
72-
.defaultOptions(opts -> InterfaceDefaultOptions.addTo(opts,
73-
builder -> builder.addProcessor(ExcludePlatform.class,
74-
excludePlatform(platformType)))
75-
.header(HEADER))
77+
.defaultOptions(options -> options
78+
.header(HEADER)
79+
.serializers(builder ->
80+
builder.registerAnnotatedObjects(mapperFactory))
81+
)
7682
.build();
7783

78-
final CommentedConfigurationNode root = loader.load();
79-
final T config = root.get(clazz);
84+
CommentedConfigurationNode root = loader.load();
85+
T config = root.get(configClass);
8086

8187
if (Files.notExists(path)) {
8288
loader.save(root);
8389
}
8490

85-
return new ConfigurationManager<>(clazz, loader, new AtomicReference<>(config));
91+
return new ConfigurationManager<>(configClass, loader, new AtomicReference<>(config));
8692
}
8793

8894
/**
8995
* Asynchronously reloads the configuration from disk.
90-
* The current configuration object is updated with the newly loaded data.
96+
*
97+
* <p>The current configuration object is updated with the newly loaded data.</p>
9198
*
9299
* @return a {@link CompletableFuture} that completes when the reload is complete
93100
*/
94101
public CompletableFuture<Void> reload() {
95102
return CompletableFuture.runAsync(() -> {
96103
try {
97-
final CommentedConfigurationNode root = loader.load();
98-
config.set(root.get(clazz));
104+
CommentedConfigurationNode root = loader.load();
105+
config.set(root.get(configClass));
99106
} catch (ConfigurateException e) {
100107
throw new CompletionException("Failed to load configuration", e);
101108
}
@@ -112,7 +119,7 @@ public T get() {
112119
}
113120

114121
private static Processor.Factory<ExcludePlatform, Object> excludePlatform(
115-
final PlatformType platformType
122+
PlatformType platformType
116123
) {
117124
return (annotation, fieldType) -> (value, destination) -> {
118125
for (PlatformType platform : annotation.value()) {

core/src/main/java/dev/triassic/template/configuration/TemplateConfiguration.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,22 @@
1111

1212
import dev.triassic.template.annotation.ExcludePlatform;
1313
import dev.triassic.template.util.PlatformType;
14-
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultNumeric;
15-
import org.spongepowered.configurate.interfaces.meta.defaults.DefaultString;
14+
import lombok.Getter;
1615
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
1716
import org.spongepowered.configurate.objectmapping.meta.Comment;
1817

1918
/**
2019
* Represents the plugin's base configuration file.
2120
*/
21+
@Getter
2222
@ConfigSerializable
23-
public interface TemplateConfiguration {
23+
@SuppressWarnings("FieldMayBeFinal")
24+
public class TemplateConfiguration {
2425

25-
/**
26-
* An example string that showcases the usage of {@link ExcludePlatform}.
27-
*
28-
* <p>Take note of how the {@link ExcludePlatform} annotation goes after
29-
* the {@link Comment} annotation, it is important to do it in this order,
30-
* otherwise the node will be recreated empty to add the comment.</p>
31-
*/
3226
@Comment("This string should not appear on Velocity and Bungeecord platforms.")
33-
@DefaultString("This is an example string!")
3427
@ExcludePlatform({PlatformType.BUNGEECORD, PlatformType.VELOCITY})
35-
String exampleString();
28+
private String exampleString = "This is an example string!";
3629

37-
/**
38-
* The version of the configuration file.
39-
*/
4030
@Comment("Used internally, do not change.")
41-
@DefaultNumeric(1)
42-
int configVersion();
31+
private int configVersion = 1;
4332
}

gradle/libs.versions.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ cloud-neoforge = { group = "org.incendo", name = "cloud-neoforge", version.ref =
4545
cloud-paper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloud-minecraft" }
4646
cloud-velocity = { group = "org.incendo", name = "cloud-velocity", version.ref = "cloud-minecraft" }
4747

48-
# Config and YAML Libraries
49-
configurate-interface-ap = { group = "org.spongepowered", name = "configurate-extra-interface-ap", version.ref = "configurate" }
50-
configurate-interface = { group = "org.spongepowered", name = "configurate-extra-interface", version.ref = "configurate" }
5148
configurate-yaml = { group = "org.spongepowered", name = "configurate-yaml", version.ref = "configurate" }
5249

5350
minecraft = { group = "net.minecraft", name = "minecraft", version.ref = "minecraft" }

0 commit comments

Comments
 (0)