Skip to content

Commit

Permalink
Fix YAML implementation using Velocity YAML library
Browse files Browse the repository at this point in the history
  • Loading branch information
ActualPlayer committed Jun 30, 2020
1 parent 45c2629 commit 56d8254
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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;
Expand All @@ -25,7 +28,7 @@ public FileHandler(RememberMe rememberMe) {
public CompletableFuture<String> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
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> 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);

return yaml.loadAs(stream, clazz);
Expand Down

0 comments on commit 56d8254

Please sign in to comment.