Refactor ProtocolHack#injectPreviousVersionReset to match modifications

This commit is contained in:
FlorianMichael 2024-01-29 14:12:09 +01:00
parent b5b677da71
commit ac7121be47
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 10 additions and 8 deletions

View File

@ -75,7 +75,7 @@ public abstract class MixinConnectScreen_1 {
this.viaFabricPlus$useClassiCubeAccount = AuthenticationSettings.global().setSessionNameToClassiCubeNameInServerList.getValue() && ViaFabricPlusClassicMPPassProvider.classicMpPassForNextJoin != null;
final ChannelFuture future = original.call(address, useEpoll, connection);
future.channel().closeFuture().addListener(channel -> ProtocolHack.resetPreviousVersion());
ProtocolHack.injectPreviousVersionReset(future.channel());
return future;
}

View File

@ -44,7 +44,7 @@ public abstract class MixinMinecraftClient {
@Inject(method = "startIntegratedServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;connect(Ljava/lang/String;ILnet/minecraft/network/listener/ClientLoginPacketListener;)V", shift = At.Shift.BEFORE))
private void disableProtocolHack(LevelStorage.Session session, ResourcePackManager dataPackManager, SaveLoader saveLoader, boolean newWorld, CallbackInfo ci, @Local ClientConnection clientConnection) {
ProtocolHack.setTargetVersion(ProtocolHack.NATIVE_VERSION, true);
clientConnection.channel.closeFuture().addListener(channel -> ProtocolHack.resetPreviousVersion());
ProtocolHack.injectPreviousVersionReset(clientConnection.channel);
}
}

View File

@ -162,11 +162,13 @@ public class ProtocolHack {
/**
* Resets the previous version if it is set. Calling {@link #setTargetVersion(VersionEnum, boolean)} with revertOnDisconnect set to true will set it.
*/
public static void resetPreviousVersion() {
if (previousVersion != null) { // Revert the version if the player disconnects and a previous version is set
public static void injectPreviousVersionReset(final Channel channel) {
if (previousVersion == null) return;
channel.closeFuture().addListener(future -> {
setTargetVersion(previousVersion);
previousVersion = null;
}
});
}
/**
@ -205,11 +207,11 @@ public class ProtocolHack {
*/
public static UserConnection getPlayNetworkUserConnection() {
final ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
if (handler != null) {
return ((IClientConnection) handler.getConnection()).viaFabricPlus$getUserConnection();
if (handler == null) {
throw new IllegalStateException("The player is not connected to a server");
}
throw new IllegalStateException("The player is not connected to a server");
return ((IClientConnection) handler.getConnection()).viaFabricPlus$getUserConnection();
}
/**