Merge pull request #35 from dimadencep/velocity-tools

Compat with velocity-tools
This commit is contained in:
Adrian Bergqvist 2023-08-02 15:06:15 +02:00 committed by GitHub
commit fbc15bc4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -17,10 +17,12 @@ public class VelocityServerChannelInitializer extends ServerChannelInitializer {
private Method INIT_CHANNEL; private Method INIT_CHANNEL;
private final ChannelInitializer<?> delegate; private final ChannelInitializer<?> delegate;
private final VelocityServer server;
public VelocityServerChannelInitializer(ChannelInitializer<?> delegate,VelocityServer server) { public VelocityServerChannelInitializer(ChannelInitializer<?> delegate,VelocityServer server) {
super(server); super(server);
this.delegate = delegate; this.delegate = delegate;
this.server = server;
try { try {
INIT_CHANNEL = delegate.getClass().getDeclaredMethod("initChannel", Channel.class); INIT_CHANNEL = delegate.getClass().getDeclaredMethod("initChannel", Channel.class);
INIT_CHANNEL.setAccessible(true); INIT_CHANNEL.setAccessible(true);
@ -41,7 +43,7 @@ public class VelocityServerChannelInitializer extends ServerChannelInitializer {
super.initChannel(ch); super.initChannel(ch);
MinecraftConnection handler = ch.pipeline().get(MinecraftConnection.class); MinecraftConnection handler = ch.pipeline().get(MinecraftConnection.class);
HandshakeSessionHandler originalSessionHandler = (HandshakeSessionHandler) handler.getSessionHandler(); HandshakeSessionHandler originalSessionHandler = (HandshakeSessionHandler) handler.getSessionHandler();
handler.setSessionHandler(new VelocityHandshakeSessionHandler(originalSessionHandler, handler)); handler.setSessionHandler(new VelocityHandshakeSessionHandler(originalSessionHandler, handler, server));
} }
} }
} }

View File

@ -1,8 +1,8 @@
package org.adde0109.ambassador.velocity.client; package org.adde0109.ambassador.velocity.client;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.ConnectionTypes;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
import com.velocitypowered.proxy.network.Connections; import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
@ -11,11 +11,12 @@ import com.velocitypowered.proxy.protocol.packet.Handshake;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.adde0109.ambassador.forge.ForgeConstants; import org.adde0109.ambassador.forge.ForgeConstants;
public class VelocityHandshakeSessionHandler implements MinecraftSessionHandler { public class VelocityHandshakeSessionHandler extends HandshakeSessionHandler {
private final HandshakeSessionHandler original; private final HandshakeSessionHandler original;
private final MinecraftConnection connection; private final MinecraftConnection connection;
public VelocityHandshakeSessionHandler(HandshakeSessionHandler original, MinecraftConnection connection) { public VelocityHandshakeSessionHandler(HandshakeSessionHandler original, MinecraftConnection connection, VelocityServer server) {
super(connection, server);
this.original = original; this.original = original;
this.connection = connection; this.connection = connection;
} }