Java Code Examples for io.netty.handler.codec.MessageToMessageDecoder

The following are top voted examples for showing how to use io.netty.handler.codec.MessageToMessageDecoder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CratesPlus   File: SignInputHandler.java   View source code 6 votes vote down vote up
public static void injectNetty(final Player player) {
    try {
        Object handle = player.getClass().getMethod("getHandle").invoke(player);
        Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
        final Channel channel = (Channel) channelField.get(playerConnection.getClass().getField("networkManager").get(playerConnection));
        if (channel != null) {
            channel.pipeline().addAfter("decoder", "update_sign", new MessageToMessageDecoder<Object>() {
                @Override
                protected void decode(ChannelHandlerContext channelHandlerContext, Object object, List list) throws Exception {
                    if (object.toString().contains("PacketPlayInUpdateSign")) {
                        Object packet = ReflectionUtil.getNMSClass("PacketPlayInUpdateSign").cast(object);
                        Bukkit.getPluginManager().callEvent(new PlayerInputEvent(player, (String[]) packet.getClass().getMethod("b").invoke(packet)));
                    }
                    list.add(object);
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Project: ViaVersion   File: BungeePipelineUtil.java   View source code 5 votes vote down vote up
public static List<Object> callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, ByteBuf input) throws InvocationTargetException {
    List<Object> output = new ArrayList<>();
    try {
        BungeePipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return output;
}
 
Example 3
Project: ViaVersion   File: BungeePipelineUtil.java   View source code 5 votes vote down vote up
public static ByteBuf decompress(ChannelHandlerContext ctx, ByteBuf bytebuf) {
    try {
        return (ByteBuf) callDecode((MessageToMessageDecoder) ctx.pipeline().get("decompress"), ctx.pipeline().context("decompress"), bytebuf).get(0);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return ctx.alloc().buffer();
    }
}
 
Example 4
Project: Cascade   File: CryptoFunction.java   View source code 4 votes vote down vote up
public CryptoFunction(byte[] key, MessageToMessageEncoder<ByteBuf> encoder, MessageToMessageDecoder<ByteBuf> decoder) {

        this.key = key;
        this.encoder = encoder;
        this.decoder = decoder;
    }
 
Example 5
Project: Cascade   File: CryptoFunction.java   View source code 2 votes vote down vote up
public MessageToMessageDecoder<ByteBuf> getDecoder() {

        return decoder;
    }