From f668e0dced771c7b177c39c52048074f6259560d Mon Sep 17 00:00:00 2001 From: aromaa Date: Wed, 8 Jan 2025 01:06:35 +0200 Subject: [PATCH] Implement EngineConnectionState#connection --- SpongeAPI | 2 +- .../network/SpongeClientEngineConnection.java | 16 ++++++++++++++ .../network/SpongeEngineConnection.java | 21 +++---------------- .../network/SpongeServerEngineConnection.java | 15 +++++++++++++ ...ientCommonPacketListenerImplMixin_API.java | 2 ++ ...figurationPacketListenerImplMixin_API.java | 7 +++++++ ...tHandshakePacketListenerImplMixin_API.java | 9 ++++++++ .../ClientPacketListenerMixin_API.java | 9 +++++++- ...rHandshakePacketListenerImplMixin_API.java | 14 +++++++++++++ ...rverCommonPacketListenerImplMixin_API.java | 2 ++ ...figurationPacketListenerImplMixin_API.java | 7 +++++++ ...ServerGamePacketListenerImplMixin_API.java | 7 +++++++ ...rHandshakePacketListenerImplMixin_API.java | 14 +++++++++++++ ...erverLoginPacketListenerImplMixin_API.java | 9 ++++++++ 14 files changed, 114 insertions(+), 20 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index 9b76de689c4..dc9e5527e1a 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 9b76de689c44520df758c95b64de64bf27175831 +Subproject commit dc9e5527e1a2ed6d0b328807f3651ee531d3f8b2 diff --git a/src/main/java/org/spongepowered/common/network/SpongeClientEngineConnection.java b/src/main/java/org/spongepowered/common/network/SpongeClientEngineConnection.java index 49df1b5fc15..cf1acca26fc 100644 --- a/src/main/java/org/spongepowered/common/network/SpongeClientEngineConnection.java +++ b/src/main/java/org/spongepowered/common/network/SpongeClientEngineConnection.java @@ -25,6 +25,7 @@ package org.spongepowered.common.network; import net.minecraft.network.Connection; +import org.spongepowered.api.network.ClientConnectionState; import org.spongepowered.api.network.ClientSideConnection; public final class SpongeClientEngineConnection extends SpongeEngineConnection implements ClientSideConnection { @@ -32,4 +33,19 @@ public final class SpongeClientEngineConnection extends SpongeEngineConnection i public SpongeClientEngineConnection(final Connection connection) { super(connection); } + + @Override + protected ClientConnectionState.Intent createIntentState(final boolean transferred) { + return new ClientConnectionState.Intent() { + @Override + public ClientSideConnection connection() { + return SpongeClientEngineConnection.this; + } + + @Override + public boolean transferred() { + return transferred; + } + }; + } } diff --git a/src/main/java/org/spongepowered/common/network/SpongeEngineConnection.java b/src/main/java/org/spongepowered/common/network/SpongeEngineConnection.java index a69c4b2e324..4fcd4925dd5 100644 --- a/src/main/java/org/spongepowered/common/network/SpongeEngineConnection.java +++ b/src/main/java/org/spongepowered/common/network/SpongeEngineConnection.java @@ -71,7 +71,7 @@ public Optional state() { if (!(state instanceof ServerLoginPacketListenerImplBridge loginBridge) || loginBridge.bridge$isIntentDone()) { return Optional.of(state); } - return Optional.of(DummyIntent.of(state.transferred())); + return Optional.of(this.createIntentState(state.transferred())); } return Optional.empty(); } @@ -129,6 +129,8 @@ private void fireDisconnectEvent() { SpongeCommon.post(event); } + protected abstract EngineConnectionState.Intent createIntentState(boolean transferred); + private enum EventFireState { NONE, IN_FLIGHT, @@ -139,21 +141,4 @@ boolean shouldFireDisconnectionImmediately() { return this == EventFireState.POST; } } - - private record DummyIntent(boolean transferred) implements EngineConnectionState.Intent { - - private static final DummyIntent TRANSFERRED_FALSE = new DummyIntent(false); - private static final DummyIntent TRANSFERRED_TRUE = new DummyIntent(true); - - @Override - public boolean transferred() { - return this.transferred; - } - - static DummyIntent of(final boolean transferred) { - return transferred - ? DummyIntent.TRANSFERRED_TRUE - : DummyIntent.TRANSFERRED_FALSE; - } - } } diff --git a/src/main/java/org/spongepowered/common/network/SpongeServerEngineConnection.java b/src/main/java/org/spongepowered/common/network/SpongeServerEngineConnection.java index da7d2066ba6..b3ac83048f1 100644 --- a/src/main/java/org/spongepowered/common/network/SpongeServerEngineConnection.java +++ b/src/main/java/org/spongepowered/common/network/SpongeServerEngineConnection.java @@ -25,6 +25,7 @@ package org.spongepowered.common.network; import net.minecraft.network.Connection; +import org.spongepowered.api.network.ServerConnectionState; import org.spongepowered.api.network.ServerSideConnection; public final class SpongeServerEngineConnection extends SpongeEngineConnection implements ServerSideConnection { @@ -33,4 +34,18 @@ public SpongeServerEngineConnection(final Connection connection) { super(connection); } + @Override + protected ServerConnectionState.Intent createIntentState(final boolean transferred) { + return new ServerConnectionState.Intent() { + @Override + public ServerSideConnection connection() { + return SpongeServerEngineConnection.this; + } + + @Override + public boolean transferred() { + return transferred; + } + }; + } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientCommonPacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientCommonPacketListenerImplMixin_API.java index 2a3a30381d4..c7e09e28411 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientCommonPacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientCommonPacketListenerImplMixin_API.java @@ -26,6 +26,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; +import net.minecraft.network.Connection; import org.spongepowered.api.network.ClientConnectionState; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -35,6 +36,7 @@ public abstract class ClientCommonPacketListenerImplMixin_API implements ClientConnectionState { // @formatter:off + @Shadow @Final protected Connection connection; @Shadow @Final protected Minecraft minecraft; @Shadow protected boolean isTransferring; // @formatter:on diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientConfigurationPacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientConfigurationPacketListenerImplMixin_API.java index e9458e8535e..aa8f0ed322c 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientConfigurationPacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientConfigurationPacketListenerImplMixin_API.java @@ -26,10 +26,12 @@ import net.minecraft.client.multiplayer.ClientConfigurationPacketListenerImpl; import org.spongepowered.api.network.ClientConnectionState; +import org.spongepowered.api.network.ClientSideConnection; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.profile.SpongeGameProfile; @Mixin(ClientConfigurationPacketListenerImpl.class) @@ -39,6 +41,11 @@ public abstract class ClientConfigurationPacketListenerImplMixin_API extends Cli @Shadow @Final private com.mojang.authlib.GameProfile localGameProfile; // @formatter:on + @Override + public ClientSideConnection connection() { + return (ClientSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public GameProfile profile() { return SpongeGameProfile.of(this.localGameProfile); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientHandshakePacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientHandshakePacketListenerImplMixin_API.java index 78381018197..3d19a11771f 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientHandshakePacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientHandshakePacketListenerImplMixin_API.java @@ -26,21 +26,30 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; +import net.minecraft.network.Connection; import org.spongepowered.api.network.ClientConnectionState; +import org.spongepowered.api.network.ClientSideConnection; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.profile.SpongeGameProfile; @Mixin(ClientHandshakePacketListenerImpl.class) public abstract class ClientHandshakePacketListenerImplMixin_API implements ClientConnectionState.Login { // @formatter:off + @Shadow @Final private Connection connection; @Shadow @Final private Minecraft minecraft; @Shadow @Final private boolean wasTransferredTo; // @formatter:on + @Override + public ClientSideConnection connection() { + return (ClientSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public boolean transferred() { return this.wasTransferredTo; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientPacketListenerMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientPacketListenerMixin_API.java index c06e21c1c2e..0c2229cfaf6 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientPacketListenerMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/client/multiplayer/ClientPacketListenerMixin_API.java @@ -27,19 +27,26 @@ import net.minecraft.client.multiplayer.ClientPacketListener; import org.spongepowered.api.entity.living.player.client.LocalPlayer; import org.spongepowered.api.network.ClientConnectionState; +import org.spongepowered.api.network.ClientSideConnection; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.profile.SpongeGameProfile; @Mixin(ClientPacketListener.class) -public class ClientPacketListenerMixin_API extends ClientCommonPacketListenerImplMixin_API implements ClientConnectionState.Game { +public abstract class ClientPacketListenerMixin_API extends ClientCommonPacketListenerImplMixin_API implements ClientConnectionState.Game { // @formatter:off @Shadow @Final private com.mojang.authlib.GameProfile localGameProfile; // @formatter:on + @Override + public ClientSideConnection connection() { + return (ClientSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public GameProfile profile() { return SpongeGameProfile.of(this.localGameProfile); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/MemoryServerHandshakePacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/MemoryServerHandshakePacketListenerImplMixin_API.java index d4ddc203ff5..8891f61b288 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/MemoryServerHandshakePacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/MemoryServerHandshakePacketListenerImplMixin_API.java @@ -24,14 +24,28 @@ */ package org.spongepowered.common.mixin.api.minecraft.server.network; +import net.minecraft.network.Connection; import net.minecraft.server.network.MemoryServerHandshakePacketListenerImpl; import org.spongepowered.api.network.ServerConnectionState; +import org.spongepowered.api.network.ServerSideConnection; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.bridge.server.network.ServerHandshakePacketListenerImplBridge; @Mixin(MemoryServerHandshakePacketListenerImpl.class) public abstract class MemoryServerHandshakePacketListenerImplMixin_API implements ServerConnectionState.Intent { + // @formatter:off + @Shadow @Final private Connection connection; + // @formatter:on + + @Override + public ServerSideConnection connection() { + return (ServerSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public boolean transferred() { return ((ServerHandshakePacketListenerImplBridge) this).bridge$transferred(); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerCommonPacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerCommonPacketListenerImplMixin_API.java index cfdfed03801..423faf5eee6 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerCommonPacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerCommonPacketListenerImplMixin_API.java @@ -25,6 +25,7 @@ package org.spongepowered.common.mixin.api.minecraft.server.network; import com.mojang.authlib.GameProfile; +import net.minecraft.network.Connection; import net.minecraft.server.network.ServerCommonPacketListenerImpl; import org.spongepowered.api.network.EngineConnectionState; import org.spongepowered.asm.mixin.Final; @@ -36,6 +37,7 @@ public abstract class ServerCommonPacketListenerImplMixin_API implements EngineC // @formatter:off @Shadow @Final private boolean transferred; + @Shadow @Final protected Connection connection; @Shadow protected abstract GameProfile shadow$playerProfile(); @Shadow public abstract int shadow$latency(); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerConfigurationPacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerConfigurationPacketListenerImplMixin_API.java index 273b110b4cc..39973e9bc05 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerConfigurationPacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerConfigurationPacketListenerImplMixin_API.java @@ -26,13 +26,20 @@ import net.minecraft.server.network.ServerConfigurationPacketListenerImpl; import org.spongepowered.api.network.ServerConnectionState; +import org.spongepowered.api.network.ServerSideConnection; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.profile.SpongeGameProfile; @Mixin(ServerConfigurationPacketListenerImpl.class) public abstract class ServerConfigurationPacketListenerImplMixin_API extends ServerCommonPacketListenerImplMixin_API implements ServerConnectionState.Configuration { + @Override + public ServerSideConnection connection() { + return (ServerSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public GameProfile profile() { return SpongeGameProfile.of(this.shadow$playerProfile()); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerGamePacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerGamePacketListenerImplMixin_API.java index 3422a315dc0..288af778939 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerGamePacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerGamePacketListenerImplMixin_API.java @@ -27,11 +27,13 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.spongepowered.api.entity.living.player.server.ServerPlayer; import org.spongepowered.api.network.ServerConnectionState; +import org.spongepowered.api.network.ServerSideConnection; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.profile.SpongeGameProfile; @Mixin(ServerGamePacketListenerImpl.class) @@ -42,6 +44,11 @@ public abstract class ServerGamePacketListenerImplMixin_API extends ServerCommon @Shadow public net.minecraft.server.level.ServerPlayer player; // @formatter:on + @Override + public ServerSideConnection connection() { + return (ServerSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public GameProfile profile() { return SpongeGameProfile.of(this.shadow$playerProfile()); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerHandshakePacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerHandshakePacketListenerImplMixin_API.java index 7ea296d8697..2c3107d2f58 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerHandshakePacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerHandshakePacketListenerImplMixin_API.java @@ -24,14 +24,28 @@ */ package org.spongepowered.common.mixin.api.minecraft.server.network; +import net.minecraft.network.Connection; import net.minecraft.server.network.ServerHandshakePacketListenerImpl; import org.spongepowered.api.network.ServerConnectionState; +import org.spongepowered.api.network.ServerSideConnection; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.bridge.server.network.ServerHandshakePacketListenerImplBridge; @Mixin(ServerHandshakePacketListenerImpl.class) public abstract class ServerHandshakePacketListenerImplMixin_API implements ServerConnectionState.Intent { + // @formatter:off + @Shadow @Final private Connection connection; + // @formatter:on + + @Override + public ServerSideConnection connection() { + return (ServerSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public boolean transferred() { return ((ServerHandshakePacketListenerImplBridge) this).bridge$transferred(); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerLoginPacketListenerImplMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerLoginPacketListenerImplMixin_API.java index f26b8b379da..c82ac90f0b6 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerLoginPacketListenerImplMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/server/network/ServerLoginPacketListenerImplMixin_API.java @@ -24,12 +24,15 @@ */ package org.spongepowered.common.mixin.api.minecraft.server.network; +import net.minecraft.network.Connection; import net.minecraft.server.network.ServerLoginPacketListenerImpl; import org.spongepowered.api.network.ServerConnectionState; +import org.spongepowered.api.network.ServerSideConnection; import org.spongepowered.api.profile.GameProfile; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.ConnectionBridge; import org.spongepowered.common.profile.SpongeGameProfile; @Mixin(ServerLoginPacketListenerImpl.class) @@ -38,8 +41,14 @@ public abstract class ServerLoginPacketListenerImplMixin_API implements ServerCo // @formatter:off @Shadow private com.mojang.authlib.GameProfile authenticatedProfile; @Shadow @Final private boolean transferred; + @Shadow @Final Connection connection; // @formatter:on + @Override + public ServerSideConnection connection() { + return (ServerSideConnection) ((ConnectionBridge) this.connection).bridge$getEngineConnection(); + } + @Override public boolean transferred() { return this.transferred;