Fix bungee packetevents injector.
This commit is contained in:
1 parent
2ce1fc1e79
commit
33d3a72d4d
3 files changed
+46
-20
No files matched your search
@@ -209,9 +209,9 @@ public class User {
|
||||
}
|
||||
|
||||
public void sendTitle(Component title, Component subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
|
||||
ServerVersion version = PacketEvents.getAPI().getInjector().isProxy() ? getClientVersion().toServerVersion() :
|
||||
PacketEvents.getAPI().getServerManager().getVersion();
|
||||
boolean modern = version.isNewerThanOrEquals(ServerVersion.V_1_17);
|
||||
ClientVersion version = PacketEvents.getAPI().getInjector().isProxy() ? getClientVersion() :
|
||||
PacketEvents.getAPI().getServerManager().getVersion().toClientVersion();
|
||||
boolean modern = version.isNewerThanOrEquals(ClientVersion.V_1_17);
|
||||
PacketWrapper<?> animation;
|
||||
PacketWrapper<?> setTitle = null;
|
||||
PacketWrapper<?> setSubtitle = null;
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package io.github.retrooper.packetevents.injector;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class BungeeChannelInitializer extends ChannelInitializer<Channel> {
|
||||
private static final Method INIT_CHANNEL_METHOD;
|
||||
|
||||
static {
|
||||
try {
|
||||
INIT_CHANNEL_METHOD = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
|
||||
INIT_CHANNEL_METHOD.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private final Object oldInitializer;
|
||||
public BungeeChannelInitializer(Object oldInitializer) {
|
||||
this.oldInitializer = oldInitializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(@NotNull Channel channel) throws Exception {
|
||||
if (!channel.isActive()) return;
|
||||
INIT_CHANNEL_METHOD.invoke(oldInitializer, channel);
|
||||
|
||||
ServerConnectionInitializer.initChannel(channel, ConnectionState.HANDSHAKING);
|
||||
}
|
||||
}
|
||||
+10
-17
@@ -73,25 +73,18 @@ public class BungeePipelineInjector implements ChannelInjector {
|
||||
return;
|
||||
}
|
||||
|
||||
Field finalInitializerField = initializerField;
|
||||
ChannelHandler finalBootstrapAcceptor = bootstrapAcceptor;
|
||||
ChannelInitializer<Channel> newInitializer = new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(@NotNull Channel channel) throws Exception {
|
||||
if (!channel.isActive()) return;
|
||||
Method initChannelMethod = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
|
||||
initChannelMethod.setAccessible(true);
|
||||
|
||||
Object initializer = finalInitializerField.get(finalBootstrapAcceptor);
|
||||
initChannelMethod.invoke(initializer, channel);
|
||||
|
||||
ServerConnectionInitializer.initChannel(channel, ConnectionState.HANDSHAKING);
|
||||
}
|
||||
};
|
||||
ChannelInitializer<Channel> newInitializer;
|
||||
try {
|
||||
newInitializer = new BungeeChannelInitializer(initializerField.get(bootstrapAcceptor));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
finalInitializerField.set(bootstrapAcceptor, newInitializer);
|
||||
} catch (IllegalAccessException e) {
|
||||
Field f = bootstrapAcceptor.getClass().getDeclaredField("childHandler");
|
||||
f.setAccessible(true);
|
||||
f.set(bootstrapAcceptor, newInitializer);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user