From 0a2fd8f2962f02847748d0941a6d0b2cba603821 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:04:41 +0100 Subject: [PATCH] Add MappingDataLoader#getLogger and MappingDataLoader#getDataFolder (#3757) --- .../viaversion/api/data/MappingDataLoader.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java index 05b76c6d1..7c2ef50ff 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java @@ -48,6 +48,7 @@ import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.logging.Logger; import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.Nullable; @@ -82,7 +83,7 @@ public class MappingDataLoader { * @return loaded json object, or null if not found or invalid */ public @Nullable JsonObject loadFromDataDir(final String name) { - final File file = getFile(name); + final File file = new File(getDataFolder(), name); if (!file.exists()) { return loadData(name); } @@ -92,7 +93,7 @@ public class MappingDataLoader { return GsonUtil.getGson().fromJson(reader, JsonObject.class); } catch (final JsonSyntaxException e) { // Users might mess up the format, so let's catch the syntax error - Via.getPlatform().getLogger().warning(name + " is badly formatted!"); + getLogger().warning(name + " is badly formatted!"); throw new RuntimeException(e); } catch (final IOException | JsonIOException e) { throw new RuntimeException(e); @@ -286,12 +287,16 @@ public class MappingDataLoader { return map; } - public @Nullable InputStream getResource(final String name) { - return dataLoaderClass.getClassLoader().getResourceAsStream(dataPath + name); + public Logger getLogger() { + return Via.getPlatform().getLogger(); } - public File getFile(final String name) { - return new File(Via.getPlatform().getDataFolder(), name); + public File getDataFolder() { + return Via.getPlatform().getDataFolder(); + } + + public @Nullable InputStream getResource(final String name) { + return dataLoaderClass.getClassLoader().getResourceAsStream(dataPath + name); } @FunctionalInterface