Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Add MappingDataLoader#getLogger and MappingDataLoader#getDataFolder (#3757)
Dieser Commit ist enthalten in:
Ursprung
f2c816df72
Commit
0a2fd8f296
@ -48,6 +48,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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
|
* @return loaded json object, or null if not found or invalid
|
||||||
*/
|
*/
|
||||||
public @Nullable JsonObject loadFromDataDir(final String name) {
|
public @Nullable JsonObject loadFromDataDir(final String name) {
|
||||||
final File file = getFile(name);
|
final File file = new File(getDataFolder(), name);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return loadData(name);
|
return loadData(name);
|
||||||
}
|
}
|
||||||
@ -92,7 +93,7 @@ public class MappingDataLoader {
|
|||||||
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
|
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
|
||||||
} catch (final JsonSyntaxException e) {
|
} catch (final JsonSyntaxException e) {
|
||||||
// Users might mess up the format, so let's catch the syntax error
|
// 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);
|
throw new RuntimeException(e);
|
||||||
} catch (final IOException | JsonIOException e) {
|
} catch (final IOException | JsonIOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -286,12 +287,16 @@ public class MappingDataLoader {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable InputStream getResource(final String name) {
|
public Logger getLogger() {
|
||||||
return dataLoaderClass.getClassLoader().getResourceAsStream(dataPath + name);
|
return Via.getPlatform().getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile(final String name) {
|
public File getDataFolder() {
|
||||||
return new File(Via.getPlatform().getDataFolder(), name);
|
return Via.getPlatform().getDataFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable InputStream getResource(final String name) {
|
||||||
|
return dataLoaderClass.getClassLoader().getResourceAsStream(dataPath + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren