Skip to content

Commit

Permalink
Load settings earlier again, post load target version
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
FlorianMichael committed May 18, 2024
1 parent aef746b commit cd3caa9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public void save() {
public abstract void write(final JsonObject object);
public abstract void read(final JsonObject object);

public void postInit() {
}

public File getFile() {
return file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public SaveManager(final SettingsManager settingsManager) {
settingsSave = new SettingsSave(settingsManager),
accountsSave = new AccountsSave()
);
}

public void init() {
// Load save files
for (AbstractSave save : saves) {
save.init();
Expand All @@ -61,6 +59,12 @@ public void init() {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class SettingsSave extends AbstractSave {

private final SettingsManager settingsManager;
private String selectedProtocolVersion;

public SettingsSave(final SettingsManager settingsManager) {
super("settings");
Expand Down Expand Up @@ -66,8 +67,16 @@ public void read(JsonObject object) {
}
}

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);
}
Expand Down

0 comments on commit cd3caa9

Please sign in to comment.