diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/perserverversion/MixinServerInfo.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/perserverversion/MixinServerInfo.java index 25bae6b40..5db18ad33 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/perserverversion/MixinServerInfo.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/perserverversion/MixinServerInfo.java @@ -50,17 +50,15 @@ public abstract class MixinServerInfo implements IServerInfo { @Inject(method = "toNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD) private void saveForcedVersion(CallbackInfoReturnable cir, NbtCompound nbtCompound) { if (viaFabricPlus$forcedVersion != null) { - nbtCompound.putInt("viafabricplus_forcedversion", viaFabricPlus$forcedVersion.getOriginalVersion()); + nbtCompound.putString("viafabricplus_forcedversion", viaFabricPlus$forcedVersion.getName()); } } @Inject(method = "fromNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD) private static void loadForcedVersion(NbtCompound root, CallbackInfoReturnable cir, ServerInfo serverInfo) { if (root.contains("viafabricplus_forcedversion")) { - final ProtocolVersion version = ProtocolVersion.getProtocol(root.getInt("viafabricplus_forcedversion")); - if (!version.isKnown()) { - ((IServerInfo) serverInfo).viaFabricPlus$forceVersion(null); - } else { + final ProtocolVersion version = ProtocolVersion.getClosest(root.getString("viafabricplus_forcedversion")); + if (version != null) { ((IServerInfo) serverInfo).viaFabricPlus$forceVersion(version); } } 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 c4cad09db..4d7a3c7f9 100644 --- a/src/main/java/de/florianmichael/viafabricplus/save/impl/SettingsSave.java +++ b/src/main/java/de/florianmichael/viafabricplus/save/impl/SettingsSave.java @@ -51,7 +51,7 @@ public void write(JsonObject object) { object.add(AbstractSetting.mapTranslationKey(ChatUtil.uncoverTranslationKey(group.getName())), groupObject); } - object.addProperty("selected-protocol-version", ProtocolHack.getTargetVersion().getOriginalVersion()); + object.addProperty("selected-protocol-version", ProtocolHack.getTargetVersion().getName()); } @Override @@ -67,9 +67,8 @@ public void read(JsonObject object) { } if (GeneralSettings.global().saveSelectedProtocolVersion.getValue() && object.has("selected-protocol-version")) { - final ProtocolVersion protocolVersion = ProtocolVersion.getProtocol(object.get("selected-protocol-version").getAsInt()); - - if (protocolVersion.isKnown()) { + final ProtocolVersion protocolVersion = ProtocolVersion.getClosest(object.get("selected-protocol-version").getAsString()); + if (protocolVersion != null) { ProtocolHack.setTargetVersion(protocolVersion); } } else {