3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 17:10:13 +01:00

Only load mappings file from dir if manually copied

Dieser Commit ist enthalten in:
KennyTV 2020-01-06 10:52:42 +01:00
Ursprung 4bdb566fb5
Commit 3384b6bc17

Datei anzeigen

@ -5,33 +5,25 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.util.Map; import java.util.Map;
public class MappingDataLoader { public class MappingDataLoader {
public static JsonObject loadFromDataDir(String name) { public static JsonObject loadFromDataDir(String name) {
File file = new File(Via.getPlatform().getDataFolder(), name); File file = new File(Via.getPlatform().getDataFolder(), name);
if (!file.exists()) { if (!file.exists()) return loadData(name);
try (InputStream in = getResource(name)) {
Files.copy(in, file.toPath());
} catch (IOException e) {
Via.getPlatform().getLogger().warning("Error loading " + name + " from the config directory!");
e.printStackTrace();
return null;
}
}
// Load the file from the platform's directory if present
try (FileReader reader = new FileReader(file)) { try (FileReader reader = new FileReader(file)) {
return GsonUtil.getGson().fromJson(reader, JsonObject.class); return GsonUtil.getGson().fromJson(reader, JsonObject.class);
} catch (IOException e) { } catch (JsonSyntaxException e) {
e.printStackTrace(); // Users might mess up the format, so let's catch the syntax error
return null;
} catch (JsonSyntaxException | JsonIOException e) {
Via.getPlatform().getLogger().warning(name + " is badly formatted!"); Via.getPlatform().getLogger().warning(name + " is badly formatted!");
e.printStackTrace(); e.printStackTrace();
return null; } catch (IOException | JsonIOException e) {
e.printStackTrace();
} }
return null;
} }
public static JsonObject loadData(String name) { public static JsonObject loadData(String name) {