//
// Decompiled by Procyon v0.5.36
//

package net.md_5.bungee.netty;

import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;

public class ChannelWrapper {
    private final Channel ch;
    private volatile boolean closed;

    public ChannelWrapper(final ChannelHandlerContext ctx) {
        System.out.println("ChannelWrapper created");
        this.ch = ctx.channel();
    }

    public synchronized void write(final Object packet) {
        if (!this.closed) {
            if(packet instanceof byte[]){
                this.ch.write(Unpooled.wrappedBuffer((byte[]) packet));
            }else {
                this.ch.write(packet);
            }

            //ch.unsafe().flushNow();
        }
    }

    public synchronized void close() {
        if (!this.closed) {
            this.closed = true;
            this.ch.close();
        }
    }

    public Channel getHandle() {
        return this.ch;
    }

    public boolean isClosed() {
        return this.closed;
    }
}
