Fix YAML implementation using Velocity YAML library

This commit is contained in:
ActualPlayer 2020-06-30 21:14:03 +02:00
parent 45c26293e4
commit 56d8254cc7
3 changed files with 6 additions and 4 deletions

View File

@ -36,8 +36,6 @@ dependencies {
compileOnly("com.velocitypowered:velocity-api:1.1.0-SNAPSHOT") compileOnly("com.velocitypowered:velocity-api:1.1.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:1.1.0-SNAPSHOT") annotationProcessor("com.velocitypowered:velocity-api:1.1.0-SNAPSHOT")
implementation("org.yaml:snakeyaml:1.18")
testImplementation("junit", "junit", "4.12") testImplementation("junit", "junit", "4.12")
} }

View File

@ -5,6 +5,9 @@ import com.actualplayer.rememberme.models.UserServer;
import com.actualplayer.rememberme.util.FileUtils; import com.actualplayer.rememberme.util.FileUtils;
import com.actualplayer.rememberme.util.YamlUtils; import com.actualplayer.rememberme.util.YamlUtils;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.gson.GsonConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -25,7 +28,7 @@ public class FileHandler implements IRememberMeHandler {
public CompletableFuture<String> getLastServerName(UUID uuid) { public CompletableFuture<String> getLastServerName(UUID uuid) {
try { try {
File userFile = FileUtils.getOrCreate(rememberMe.getDataFolderPath().resolve("data"), uuid.toString() + ".yml"); File userFile = FileUtils.getOrCreate(rememberMe.getDataFolderPath().resolve("data"), uuid.toString() + ".yml");
UserServer userServer = YamlUtils.readFile(userFile, com.actualplayer.rememberme.models.UserServer.class); UserServer userServer = YamlUtils.readFile(userFile, UserServer.class);
if(userServer == null) return null; if(userServer == null) return null;

View File

@ -3,13 +3,14 @@ package com.actualplayer.rememberme.util;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;
import java.io.*; import java.io.*;
public class YamlUtils { public class YamlUtils {
public static <T> T readFile(File file, Class<T> clazz) throws FileNotFoundException { public static <T> T readFile(File file, Class<T> clazz) throws FileNotFoundException {
Yaml yaml = new Yaml(new Constructor(clazz)); Yaml yaml = new Yaml(new CustomClassLoaderConstructor(clazz.getClassLoader()));
InputStream stream = new FileInputStream(file); InputStream stream = new FileInputStream(file);
return yaml.loadAs(stream, clazz); return yaml.loadAs(stream, clazz);