3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 00:00:33 +01:00

Let users move and change block/sound mappings in the data folder

Dieser Commit ist enthalten in:
KennyTV 2020-01-06 16:34:39 +01:00
Ursprung b1c4d563b4
Commit 07cc5fd7ed
8 geänderte Dateien mit 55 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -71,7 +71,7 @@ public interface ViaBackwardsPlatform {
}
/**
* Logger provided by the platform
* Logger provided by the platform.
*
* @return logger instance
*/
@ -98,4 +98,11 @@ public interface ViaBackwardsPlatform {
* Disable the plugin.
*/
void disable();
/**
* Returns ViaBackwards's data folder.
*
* @return data folder
*/
File getDataFolder();
}

Datei anzeigen

@ -4,18 +4,32 @@ import nl.matsv.viabackwards.ViaBackwards;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.gson.JsonArray;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import us.myles.viaversion.libs.gson.JsonPrimitive;
import us.myles.viaversion.libs.gson.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.util.Map;
//TODO merge data loading with VV's MappingDataLoader, diff is in data folder and data inputstream
public class VBMappingDataLoader {
public static JsonObject loadFromDataDir(String name) {
File file = new File(ViaBackwards.getPlatform().getDataFolder(), name);
if (!file.exists()) return loadData(name);
// Load the file from the platform's directory if present
try (FileReader reader = new FileReader(file)) {
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
} catch (JsonSyntaxException e) {
ViaBackwards.getPlatform().getLogger().warning(name + " is badly formatted!");
e.printStackTrace();
ViaBackwards.getPlatform().getLogger().warning("Falling back to resource's file!");
return loadData(name);
} catch (IOException | JsonIOException e) {
e.printStackTrace();
}
return null;
}
public static JsonObject loadData(String name) {
InputStream stream = VBMappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viabackwards/data/" + name);
InputStreamReader reader = new InputStreamReader(stream);

Datei anzeigen

@ -30,7 +30,7 @@ public class BackwardsMappings {
public static void init() {
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json");
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json");
JsonObject mapping1_12_2to1_13 = VBMappingDataLoader.loadData("mapping-1.12.2to1.13.json");
JsonObject mapping1_12_2to1_13 = VBMappingDataLoader.loadFromDataDir("mapping-1.12.2to1.13.json");
ViaBackwards.getPlatform().getLogger().info("Loading 1.13 -> 1.12.2 block mapping...");
blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates"));

Datei anzeigen

@ -15,7 +15,7 @@ public class BackwardsMappings {
public static void init() {
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json");
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
JsonObject mapping1_13_2to1_14 = VBMappingDataLoader.loadData("mapping-1.13.2to1.14.json");
JsonObject mapping1_13_2to1_14 = VBMappingDataLoader.loadFromDataDir("mapping-1.13.2to1.14.json");
ViaBackwards.getPlatform().getLogger().info("Loading 1.14 -> 1.13.2 block mapping...");
blockStateMappings = new VBMappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_13_2.getAsJsonObject("blockstates"), mapping1_13_2to1_14.getAsJsonObject("blockstates"));

Datei anzeigen

@ -15,7 +15,7 @@ public class BackwardsMappings {
public static void init() {
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json");
JsonObject mapping1_14to1_15 = VBMappingDataLoader.loadData("mapping-1.14.4to1.15.json");
JsonObject mapping1_14to1_15 = VBMappingDataLoader.loadFromDataDir("mapping-1.14.4to1.15.json");
ViaBackwards.getPlatform().getLogger().info("Loading 1.15 -> 1.14.4 mappings...");
blockStateMappings = new VBMappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"), mapping1_14to1_15.getAsJsonObject("blockstates"));

Datei anzeigen

@ -16,19 +16,29 @@ import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.fabric.util.LoggerWrapper;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Logger;
public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable {
@Getter
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaBackwards"));
private File configDir;
@Override
public void run() {
this.init(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaBackwards").resolve("config.yml").toFile());
Path configDirPath = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaBackwards");
configDir = configDirPath.toFile();
this.init(configDirPath.resolve("config.yml").toFile());
}
@Override
public void disable() {
// Not possible
}
@Override
public File getDataFolder() {
return configDir;
}
}

Datei anzeigen

@ -22,6 +22,7 @@ import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Logger;
@ -53,4 +54,9 @@ public class SpongePlugin implements ViaBackwardsPlatform {
public void disable() {
// Not possible
}
@Override
public File getDataFolder() {
return configPath.toFile();
}
}

Datei anzeigen

@ -22,6 +22,7 @@ import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.velocity.VersionInfo;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Logger;
@ -53,4 +54,9 @@ public class VelocityPlugin implements ViaBackwardsPlatform {
public void disable() {
// Not possible
}
@Override
public File getDataFolder() {
return configPath.toFile();
}
}