GeyserCustomSkullConfiguration uses Configurate

This commit is contained in:
Camotoy 2024-06-26 21:49:26 -04:00
parent 360350d44e
commit add02cadd7
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
4 changed files with 17 additions and 9 deletions

View file

@ -26,7 +26,10 @@ dependencies {
compileOnlyApi(libs.viaversion)
implementation(libs.gson.record.factory) // For 1.16.5/1.17.1
// For 1.16.5/1.17.1
implementation(libs.gson.record.factory) {
isTransitive = false
}
}
platformRelocate("it.unimi.dsi.fastutil")

View file

@ -25,26 +25,21 @@
package org.geysermc.geyser.configuration;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@JsonIgnoreProperties(ignoreUnknown = true)
@ConfigSerializable
@SuppressWarnings("FieldMayBeFinal") // Jackson requires that the fields are not final
public class GeyserCustomSkullConfiguration {
@JsonProperty("player-usernames")
private List<String> playerUsernames;
@JsonProperty("player-uuids")
private List<String> playerUUIDs;
@JsonProperty("player-profiles")
private List<String> playerProfiles;
@JsonProperty("skin-hashes")
private List<String> skinHashes;
public List<String> getPlayerUsernames() {

View file

@ -64,7 +64,7 @@ public class CustomSkullRegistryPopulator {
GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap();
Path skullConfigPath = bootstrap.getConfigFolder().resolve("custom-skulls.yml");
File skullConfigFile = FileUtils.fileOrCopiedFromResource(skullConfigPath.toFile(), "custom-skulls.yml", Function.identity(), bootstrap);
skullConfig = FileUtils.loadConfig(skullConfigFile, GeyserCustomSkullConfiguration.class);
skullConfig = FileUtils.loadConfigNew(skullConfigFile, GeyserCustomSkullConfiguration.class);
} catch (IOException e) {
GeyserImpl.getInstance().getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.config.failed"), e);
return;

View file

@ -32,6 +32,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.BufferedReader;
import java.io.File;
@ -68,6 +70,14 @@ public class FileUtils {
return objectMapper.readValue(src, valueType);
}
public static <T> T loadConfigNew(File src, Class<T> valueType) throws IOException {
YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
.file(src)
.build();
ConfigurationNode node = loader.load();
return node.get(valueType);
}
public static <T> T loadJson(InputStream src, Class<T> valueType) {
// Read specifically with UTF-8 to allow any non-UTF-encoded JSON to read
return GeyserImpl.GSON.fromJson(new InputStreamReader(src, StandardCharsets.UTF_8), valueType);