Search in sources :

Example 1 with CancelException

use of com.viaversion.viaversion.exception.CancelException in project ViaVersion by ViaVersion.

the class UserConnectionImpl method transform.

private void transform(ByteBuf buf, Direction direction, Function<Throwable, Exception> cancelSupplier) throws Exception {
    if (!buf.isReadable())
        return;
    int id = Type.VAR_INT.readPrimitive(buf);
    if (id == PacketWrapper.PASSTHROUGH_ID) {
        if (!passthroughTokens.remove(Type.UUID.read(buf))) {
            throw new IllegalArgumentException("Invalid token");
        }
        return;
    }
    PacketWrapper wrapper = new PacketWrapperImpl(id, buf, this);
    try {
        protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper);
    } catch (CancelException ex) {
        throw cancelSupplier.apply(ex);
    }
    ByteBuf transformed = buf.alloc().buffer();
    try {
        wrapper.writeToBuffer(transformed);
        buf.clear().writeBytes(transformed);
    } finally {
        transformed.release();
    }
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketWrapperImpl(com.viaversion.viaversion.protocol.packet.PacketWrapperImpl) CancelException(com.viaversion.viaversion.exception.CancelException) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)1 CancelException (com.viaversion.viaversion.exception.CancelException)1 PacketWrapperImpl (com.viaversion.viaversion.protocol.packet.PacketWrapperImpl)1 ByteBuf (io.netty.buffer.ByteBuf)1