use of net.minecraft.util.io.netty.channel.ChannelHandler in project packetevents by retrooper.
the class EarlyChannelInjectorLegacy method getHandler.
private PlayerChannelHandlerLegacy getHandler(Object rawChannel) {
Channel channel = (Channel) rawChannel;
ChannelHandler handler = channel.pipeline().get(PacketEvents.get().getHandlerName());
if (handler instanceof PlayerChannelHandlerLegacy) {
return (PlayerChannelHandlerLegacy) handler;
} else {
return null;
}
}
use of net.minecraft.util.io.netty.channel.ChannelHandler in project packetevents by retrooper.
the class EarlyChannelInjectorLegacy method eject.
@Override
public void eject() {
Field childHandlerField = null;
for (ChannelFuture future : injectedFutures) {
List<String> names = future.channel().pipeline().names();
ChannelHandler bootstrapAcceptor = null;
// Pick best
for (String name : names) {
try {
ChannelHandler handler = future.channel().pipeline().get(name);
if (childHandlerField == null) {
childHandlerField = handler.getClass().getDeclaredField("childHandler");
childHandlerField.setAccessible(true);
}
ChannelInitializer<Channel> oldInit = (ChannelInitializer<Channel>) childHandlerField.get(handler);
if (oldInit instanceof PEChannelInitializerLegacy) {
bootstrapAcceptor = handler;
}
} catch (Exception e) {
// Not this one
}
}
// Default to first
if (bootstrapAcceptor == null) {
bootstrapAcceptor = future.channel().pipeline().first();
}
try {
ChannelInitializer<Channel> oldInit = (ChannelInitializer<Channel>) childHandlerField.get(bootstrapAcceptor);
if (oldInit instanceof PEChannelInitializerLegacy) {
childHandlerField.setAccessible(true);
childHandlerField.set(bootstrapAcceptor, ((PEChannelInitializerLegacy) oldInit).getOldChannelInitializer());
}
} catch (Exception e) {
PacketEvents.get().getPlugin().getLogger().severe("PacketEvents failed to eject the injection handler! Please reboot!");
}
}
injectedFutures.clear();
for (Map<Field, Object> map : injectedLists) {
try {
for (Field key : map.keySet()) {
key.setAccessible(true);
Object o = map.get(key);
if (o instanceof ListWrapper) {
key.set(o, ((ListWrapper) o).getOriginalList());
}
}
} catch (IllegalAccessException e) {
PacketEvents.get().getPlugin().getLogger().severe("PacketEvents failed to eject the injection handler! Please reboot!!");
}
}
injectedLists.clear();
}
use of net.minecraft.util.io.netty.channel.ChannelHandler in project packetevents by retrooper.
the class EarlyChannelInjectorLegacy method injectChannelFuture.
private void injectChannelFuture(ChannelFuture channelFuture) {
List<String> channelHandlerNames = channelFuture.channel().pipeline().names();
ChannelHandler bootstrapAcceptor = null;
Field bootstrapAcceptorField = null;
for (String handlerName : channelHandlerNames) {
ChannelHandler handler = channelFuture.channel().pipeline().get(handlerName);
try {
bootstrapAcceptorField = handler.getClass().getDeclaredField("childHandler");
bootstrapAcceptorField.setAccessible(true);
bootstrapAcceptorField.get(handler);
bootstrapAcceptor = handler;
} catch (Exception ignored) {
}
}
if (bootstrapAcceptor == null) {
bootstrapAcceptor = channelFuture.channel().pipeline().first();
}
ChannelInitializer<?> oldChannelInitializer = null;
try {
oldChannelInitializer = (ChannelInitializer<?>) bootstrapAcceptorField.get(bootstrapAcceptor);
ChannelInitializer<?> channelInitializer = new PEChannelInitializerLegacy(oldChannelInitializer);
// Replace the old channel initializer with our own.
bootstrapAcceptorField.setAccessible(true);
bootstrapAcceptorField.set(bootstrapAcceptor, channelInitializer);
injectedFutures.add(channelFuture);
} catch (IllegalAccessException e) {
ClassLoader cl = bootstrapAcceptor.getClass().getClassLoader();
if (cl.getClass().getName().equals("org.bukkit.plugin.java.PluginClassLoader")) {
PluginDescriptionFile yaml = null;
try {
yaml = (PluginDescriptionFile) PluginDescriptionFile.class.getDeclaredField("description").get(cl);
} catch (IllegalAccessException | NoSuchFieldException e2) {
e2.printStackTrace();
}
throw new IllegalStateException("PacketEvents failed to inject, because of " + bootstrapAcceptor.getClass().getName() + ", you might want to try running without " + yaml.getName() + "?");
} else {
throw new IllegalStateException("PacketEvents failed to find core component 'childHandler', please check your plugins. issue: " + bootstrapAcceptor.getClass().getName());
}
}
}
Aggregations