Skip to content

Commit

Permalink
Fixed config saving and loading
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Feb 15, 2024
1 parent 46361dc commit 4561fc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ public abstract class MixinServerInfo implements IServerInfo {
@Inject(method = "toNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private void saveForcedVersion(CallbackInfoReturnable<NbtCompound> 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<ServerInfo> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 4561fc8

Please sign in to comment.