mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-01-07 19:28:58 +01:00
Refactor ProtocolHack#injectPreviousVersionReset to match modifications
This commit is contained in:
parent
b5b677da71
commit
ac7121be47
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user