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)
This commit is contained in:
FlorianMichael 2024-05-18 14:30:02 +02:00
parent aef746bbb2
commit cd3caa9156
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
4 changed files with 24 additions and 9 deletions

View File

@ -59,21 +59,20 @@ public class ViaFabricPlus {
private CompletableFuture<Void> 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();
});
}

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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);
}