use of net.minecraft.util.io.netty.channel.Channel in project packetevents by retrooper.
the class EarlyChannelInjectorLegacy method inject.
@Override
public void inject() {
try {
Object serverConnection = NMSUtils.getMinecraftServerConnection();
for (Field field : serverConnection.getClass().getDeclaredFields()) {
field.setAccessible(true);
Object value = null;
try {
value = field.get(serverConnection);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (value instanceof List) {
// Get the list.
List<?> listWrapper = new ListWrapper((List<?>) value) {
@Override
public void processAdd(Object o) {
if (o instanceof ChannelFuture) {
try {
injectChannelFuture((ChannelFuture) o);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
};
HashMap<Field, Object> map = new HashMap<>();
map.put(field, serverConnection);
injectedLists.add(map);
field.set(serverConnection, listWrapper);
synchronized (listWrapper) {
for (Object serverChannel : (List<?>) value) {
// Is this the server channel future list?
if (serverChannel instanceof ChannelFuture) {
// Yes it is...
injectChannelFuture((ChannelFuture) serverChannel);
} else {
// Wrong list
break;
}
}
}
}
}
} catch (Exception ex) {
PacketEvents.get().getPlugin().getLogger().severe("PacketEvents failed to inject!");
ex.printStackTrace();
}
// Player channels might have been registered already. Let us add our handlers. We are a little late though.
// This only happens when you join extremely early on older versions of minecraft.
List<Object> networkManagers = NMSUtils.getNetworkManagers();
synchronized (networkManagers) {
for (Object networkManager : networkManagers) {
WrappedPacket networkManagerWrapper = new WrappedPacket(new NMSPacket(networkManager), NMSUtils.networkManagerClass);
Channel channel = (Channel) networkManagerWrapper.readObject(0, NMSUtils.nettyChannelClass);
if (channel == null || (!(channel.getClass().equals(NioSocketChannel.class))) && !(channel.getClass().equals(EpollSocketChannel.class))) {
continue;
}
if (channel.pipeline().get(PacketEvents.get().getHandlerName()) != null) {
channel.pipeline().remove(PacketEvents.get().getHandlerName());
}
if (channel.pipeline().get("packet_handler") != null) {
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), new PlayerChannelHandlerLegacy());
}
}
}
}
use of net.minecraft.util.io.netty.channel.Channel in project packetevents by retrooper.
the class LateChannelInjectorLegacy method flushPackets.
@Override
public void flushPackets(Object ch) {
Channel channel = (Channel) ch;
channel.flush();
}
use of net.minecraft.util.io.netty.channel.Channel in project packetevents by retrooper.
the class LateChannelInjectorLegacy method writePacket.
@Override
public void writePacket(Object ch, Object rawNMSPacket) {
Channel channel = (Channel) ch;
channel.write(rawNMSPacket);
}
use of net.minecraft.util.io.netty.channel.Channel in project packetevents by retrooper.
the class LateChannelInjectorLegacy method injectPlayer.
@Override
public void injectPlayer(Player player) {
PlayerChannelHandlerLegacy playerChannelHandlerLegacy = new PlayerChannelHandlerLegacy();
playerChannelHandlerLegacy.player = player;
Channel channel = (Channel) PacketEvents.get().getPlayerUtils().getChannel(player);
if (channel.getClass().equals(NioSocketChannel.class) || channel.getClass().equals(EpollSocketChannel.class)) {
channel.pipeline().addBefore("packet_handler", PacketEvents.get().getHandlerName(), playerChannelHandlerLegacy);
}
}
use of net.minecraft.util.io.netty.channel.Channel in project TheAPI by TheDevTec.
the class PacketHandler_Legacy method registerChannelHandler.
private void registerChannelHandler() {
networkManagers = (List<?>) (Ref.get(serverConnection, "e") != null ? Ref.get(serverConnection, "e") : Ref.get(serverConnection, "f"));
if (networkManagers == null) {
// modded server
for (Field f : Ref.getAllFields(Ref.nms("ServerConnection"))) if (List.class == f.getType()) {
networkManagers = (List<?>) Ref.get(serverConnection, f);
break;
}
}
if (networkManagers == null)
return;
if (networkManagers.isEmpty()) {
networkManagers = (List<?>) (Ref.get(serverConnection, "f") != null ? Ref.get(serverConnection, "f") : Ref.get(serverConnection, "e"));
if (networkManagers == null) {
// modded server
for (Field f : Ref.getAllFields(Ref.nms("ServerConnection"))) if (List.class == f.getType()) {
networkManagers = (List<?>) Ref.get(serverConnection, f);
break;
}
}
}
if (networkManagers == null)
return;
createServerChannelHandler();
for (Object item : networkManagers) {
if (!ChannelFuture.class.isInstance(item))
continue;
Channel serverChannel = ((ChannelFuture) item).channel();
serverChannels.add(serverChannel);
serverChannel.pipeline().addFirst(serverChannelHandler);
}
}
Aggregations