From cd3caa915646afe412c83f81f4a6741b44de1733 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 18 May 2024 14:30:02 +0200 Subject: [PATCH] Load settings earlier again, post load target version Fixes GeneralSettings#emulateInventoryActionsInAlphaVersions not working because config loading was AFTER loading Via providers, target version loading has to be late, so it catches up versions added by Via* addons and VFP (auto protocol) --- .../florianmichael/viafabricplus/ViaFabricPlus.java | 9 ++++----- .../viafabricplus/save/AbstractSave.java | 3 +++ .../viafabricplus/save/SaveManager.java | 8 ++++++-- .../viafabricplus/save/impl/SettingsSave.java | 13 +++++++++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 654d82fc..7d3c5b74 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -59,21 +59,20 @@ public class ViaFabricPlus { private CompletableFuture loadingFuture; - @SuppressWarnings("ResultOfMethodCallIgnored") public void init() { directory.mkdir(); ClassLoaderPriorityUtil.loadOverridingJars(directory); // Load overriding jars first so other code can access the new classes - ClientsideFixes.init(); // Init clientside related fixes - loadingFuture = ProtocolTranslator.init(directory); // Init ViaVersion protocol translator platform - settingsManager = new SettingsManager(); saveManager = new SaveManager(settingsManager); + ClientsideFixes.init(); // Init clientside related fixes + loadingFuture = ProtocolTranslator.init(directory); // Init ViaVersion protocol translator platform + // Block game loading until ViaVersion has loaded PostGameLoadCallback.EVENT.register(() -> { loadingFuture.join(); - saveManager.init(); + saveManager.postInit(); }); } diff --git a/src/main/java/de/florianmichael/viafabricplus/save/AbstractSave.java b/src/main/java/de/florianmichael/viafabricplus/save/AbstractSave.java index adba2711..99c16b24 100644 --- a/src/main/java/de/florianmichael/viafabricplus/save/AbstractSave.java +++ b/src/main/java/de/florianmichael/viafabricplus/save/AbstractSave.java @@ -84,6 +84,9 @@ public abstract class AbstractSave { public abstract void write(final JsonObject object); public abstract void read(final JsonObject object); + public void postInit() { + } + public File getFile() { return file; } diff --git a/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java b/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java index d6b31351..4d43e64f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java +++ b/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java @@ -43,9 +43,7 @@ public class SaveManager { settingsSave = new SettingsSave(settingsManager), accountsSave = new AccountsSave() ); - } - public void init() { // Load save files for (AbstractSave save : saves) { save.init(); @@ -61,6 +59,12 @@ public class SaveManager { LoadSaveFilesCallback.EVENT.invoker().onLoadSaveFiles(this, LoadSaveFilesCallback.State.POST); } + public void postInit() { + for (AbstractSave save : saves) { + save.postInit(); + } + } + public void add(final AbstractSave... saves) { this.saves.addAll(Arrays.asList(saves)); } diff --git a/src/main/java/de/florianmichael/viafabricplus/save/impl/SettingsSave.java b/src/main/java/de/florianmichael/viafabricplus/save/impl/SettingsSave.java index e260e22b..a3a87f64 100644 --- a/src/main/java/de/florianmichael/viafabricplus/save/impl/SettingsSave.java +++ b/src/main/java/de/florianmichael/viafabricplus/save/impl/SettingsSave.java @@ -33,6 +33,7 @@ import de.florianmichael.viafabricplus.util.ChatUtil; public class SettingsSave extends AbstractSave { private final SettingsManager settingsManager; + private String selectedProtocolVersion; public SettingsSave(final SettingsManager settingsManager) { super("settings"); @@ -66,8 +67,16 @@ public class SettingsSave extends AbstractSave { } } - if (GeneralSettings.global().saveSelectedProtocolVersion.getValue() && object.has("selected-protocol-version")) { - final ProtocolVersion protocolVersion = ProtocolVersion.getClosest(object.get("selected-protocol-version").getAsString()); + if (object.has("selected-protocol-version")) { + selectedProtocolVersion = object.get("selected-protocol-version").getAsString(); + } + } + + @Override + public void postInit() { + // Set target version AFTER protocol loading, so we can reach all versions + if (GeneralSettings.global().saveSelectedProtocolVersion.getValue()) { + final ProtocolVersion protocolVersion = ProtocolVersion.getClosest(selectedProtocolVersion); if (protocolVersion != null) { ProtocolTranslator.setTargetVersion(protocolVersion); }