3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-02 00:10:06 +02:00

Add MappingDataLoader#getLogger and MappingDataLoader#getDataFolder (#3757)

Dieser Commit ist enthalten in:
EnZaXD 2024-03-24 22:04:41 +01:00 committet von GitHub
Ursprung f2c816df72
Commit 0a2fd8f296
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -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