net.minecraft.util.io.netty.channel.ChannelPromise Java Examples

The following examples show how to use net.minecraft.util.io.netty.channel.ChannelPromise. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DuplexHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * The write() method sends packets to the client
 * It needs to be overrode in order to listen for outgoing packets
 */
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
	if(msg instanceof PacketStatusOutServerInfo) {
		PacketStatusOutServerInfo packet = (PacketStatusOutServerInfo) msg;
		PingReply reply = ServerInfoPacketHandler.constructReply(packet, ctx);
		this.event = new PingEvent(reply);
		for(PingListener listener : PingAPI.getListeners()) {
			listener.onPing(event);
		}
		if(!this.event.isCancelled()) {
			super.write(ctx, ServerInfoPacketHandler.constructPacket(reply), promise);
		}
		return;
	}
	else if(msg instanceof PacketStatusOutPong) {
		if(this.event != null && this.event.isPongCancelled()) {
			return;
		}
	}
	super.write(ctx, msg, promise);
}
 
Example #2
Source File: DuplexHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * The write() method sends packets to the client
 * It needs to be overrode in order to listen for outgoing packets
 */
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
	if(msg instanceof PacketStatusOutServerInfo) {
		PacketStatusOutServerInfo packet = (PacketStatusOutServerInfo) msg;
		PingReply reply = ServerInfoPacketHandler.constructReply(packet, ctx);
		this.event = new PingEvent(reply);
		for(PingListener listener : PingAPI.getListeners()) {
			listener.onPing(event);
		}
		if(!this.event.isCancelled()) {
			super.write(ctx, ServerInfoPacketHandler.constructPacket(reply), promise);
		}
		return;
	}
	else if(msg instanceof PacketStatusOutPong) {
		if(this.event != null && this.event.isPongCancelled()) {
			return;
		}
	}
	super.write(ctx, msg, promise);
}
 
Example #3
Source File: DuplexHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * The write() method sends packets to the client
 * It needs to be overrode in order to listen for outgoing packets
 */
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
	if(msg instanceof PacketStatusOutServerInfo) {
		PacketStatusOutServerInfo packet = (PacketStatusOutServerInfo) msg;
		PingReply reply = ServerInfoPacketHandler.constructReply(packet, ctx);
		this.event = new PingEvent(reply);
		for(PingListener listener : PingAPI.getListeners()) {
			listener.onPing(event);
		}
		if(!this.event.isCancelled()) {
			super.write(ctx, ServerInfoPacketHandler.constructPacket(reply), promise);
		}
		return;
	}
	else if(msg instanceof PacketStatusOutPong) {
		if(this.event != null && this.event.isPongCancelled()) {
			return;
		}
	}
	super.write(ctx, msg, promise);
}
 
Example #4
Source File: NMUChannel.java    From PacketListenerAPI with MIT License 5 votes vote down vote up
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
	Cancellable cancellable = new Cancellable();
	Object pckt = msg;
	if (Packet.isAssignableFrom(msg.getClass())) {
		pckt = onPacketSend(this.owner, msg, cancellable);
	}
	if (cancellable.isCancelled()) { return; }
	super.write(ctx, pckt, promise);
}