mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-20 16:37:48 +01:00
Let users move and change block/sound mappings in the data folder
This commit is contained in:
parent
b1c4d563b4
commit
07cc5fd7ed
@ -71,7 +71,7 @@ public interface ViaBackwardsPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logger provided by the platform
|
* Logger provided by the platform.
|
||||||
*
|
*
|
||||||
* @return logger instance
|
* @return logger instance
|
||||||
*/
|
*/
|
||||||
@ -98,4 +98,11 @@ public interface ViaBackwardsPlatform {
|
|||||||
* Disable the plugin.
|
* Disable the plugin.
|
||||||
*/
|
*/
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ViaBackwards's data folder.
|
||||||
|
*
|
||||||
|
* @return data folder
|
||||||
|
*/
|
||||||
|
File getDataFolder();
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,32 @@ import nl.matsv.viabackwards.ViaBackwards;
|
|||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
import us.myles.viaversion.libs.gson.JsonArray;
|
import us.myles.viaversion.libs.gson.*;
|
||||||
import us.myles.viaversion.libs.gson.JsonElement;
|
|
||||||
import us.myles.viaversion.libs.gson.JsonObject;
|
|
||||||
import us.myles.viaversion.libs.gson.JsonPrimitive;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
//TODO merge data loading with VV's MappingDataLoader, diff is in data folder and data inputstream
|
||||||
public class VBMappingDataLoader {
|
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) {
|
public static JsonObject loadData(String name) {
|
||||||
InputStream stream = VBMappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viabackwards/data/" + name);
|
InputStream stream = VBMappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viabackwards/data/" + name);
|
||||||
InputStreamReader reader = new InputStreamReader(stream);
|
InputStreamReader reader = new InputStreamReader(stream);
|
||||||
|
@ -30,7 +30,7 @@ public class BackwardsMappings {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json");
|
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json");
|
||||||
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.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...");
|
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"));
|
blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates"));
|
||||||
|
@ -15,7 +15,7 @@ public class BackwardsMappings {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json");
|
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json");
|
||||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.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...");
|
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"));
|
blockStateMappings = new VBMappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_13_2.getAsJsonObject("blockstates"), mapping1_13_2to1_14.getAsJsonObject("blockstates"));
|
||||||
|
@ -15,7 +15,7 @@ public class BackwardsMappings {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
|
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
|
||||||
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.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...");
|
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"));
|
blockStateMappings = new VBMappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"), mapping1_14to1_15.getAsJsonObject("blockstates"));
|
||||||
|
@ -16,19 +16,29 @@ import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
|
|||||||
import nl.matsv.viabackwards.fabric.util.LoggerWrapper;
|
import nl.matsv.viabackwards.fabric.util.LoggerWrapper;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable {
|
public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable {
|
||||||
@Getter
|
@Getter
|
||||||
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaBackwards"));
|
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaBackwards"));
|
||||||
|
private File configDir;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
// Not possible
|
// Not possible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDataFolder() {
|
||||||
|
return configDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import org.spongepowered.api.plugin.Dependency;
|
|||||||
import org.spongepowered.api.plugin.Plugin;
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
|
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -53,4 +54,9 @@ public class SpongePlugin implements ViaBackwardsPlatform {
|
|||||||
public void disable() {
|
public void disable() {
|
||||||
// Not possible
|
// Not possible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDataFolder() {
|
||||||
|
return configPath.toFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
|
|||||||
import nl.matsv.viabackwards.velocity.VersionInfo;
|
import nl.matsv.viabackwards.velocity.VersionInfo;
|
||||||
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
|
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -53,4 +54,9 @@ public class VelocityPlugin implements ViaBackwardsPlatform {
|
|||||||
public void disable() {
|
public void disable() {
|
||||||
// Not possible
|
// Not possible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDataFolder() {
|
||||||
|
return configPath.toFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user