From 56d8254cc78f326c998e2c48f56c77ee82aaa3f3 Mon Sep 17 00:00:00 2001 From: ActualPlayer Date: Tue, 30 Jun 2020 21:14:03 +0200 Subject: [PATCH] Fix YAML implementation using Velocity YAML library --- build.gradle.kts | 2 -- .../com/actualplayer/rememberme/handlers/FileHandler.java | 5 ++++- .../java/com/actualplayer/rememberme/util/YamlUtils.java | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4579fd1..73f4ce9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,8 +36,6 @@ dependencies { compileOnly("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") } diff --git a/src/main/java/com/actualplayer/rememberme/handlers/FileHandler.java b/src/main/java/com/actualplayer/rememberme/handlers/FileHandler.java index e832f39..a95a9ed 100644 --- a/src/main/java/com/actualplayer/rememberme/handlers/FileHandler.java +++ b/src/main/java/com/actualplayer/rememberme/handlers/FileHandler.java @@ -5,6 +5,9 @@ import com.actualplayer.rememberme.models.UserServer; import com.actualplayer.rememberme.util.FileUtils; import com.actualplayer.rememberme.util.YamlUtils; 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.IOException; @@ -25,7 +28,7 @@ public class FileHandler implements IRememberMeHandler { public CompletableFuture getLastServerName(UUID uuid) { try { 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; diff --git a/src/main/java/com/actualplayer/rememberme/util/YamlUtils.java b/src/main/java/com/actualplayer/rememberme/util/YamlUtils.java index 61ab949..87d4c07 100644 --- a/src/main/java/com/actualplayer/rememberme/util/YamlUtils.java +++ b/src/main/java/com/actualplayer/rememberme/util/YamlUtils.java @@ -3,13 +3,14 @@ package com.actualplayer.rememberme.util; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; import java.io.*; public class YamlUtils { public static T readFile(File file, Class clazz) throws FileNotFoundException { - Yaml yaml = new Yaml(new Constructor(clazz)); + Yaml yaml = new Yaml(new CustomClassLoaderConstructor(clazz.getClassLoader())); InputStream stream = new FileInputStream(file); return yaml.loadAs(stream, clazz);