Class SimpleChannel.MessageBuilder<MSG,BUF extends FriendlyByteBuf> 
- Enclosing class:
- SimpleChannel
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final SimpleChannelprivate BiConsumer<MSG, CustomPayloadEvent.Context> private PacketFlowprivate BiConsumer<MSG, BUF> private final intprivate final NetworkProtocol<BUF> 
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprivateMessageBuilder(SimpleChannel channel, Class<MSG> type, int id, @Nullable NetworkProtocol<BUF> protocol) 
- 
Method SummaryModifier and TypeMethodDescriptionadd()Finishes building this packet.codec(StreamCodec<BUF, MSG> codec) Set the StreamCodec to be used for marshaling the message object to and from aFriendlyByteBufconsumer(BiConsumer<MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded.consumerMainThread(io.netty.util.AttributeKey<C> key, org.apache.commons.lang3.function.TriConsumer<C, MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded.Set the message consumer, which is called once a message has been decoded.consumerNetworkThread(io.netty.util.AttributeKey<C> key, SimpleChannel.MessageBuilder.ToBooleanTriFunction<C, MSG, CustomPayloadEvent.Context> handler) Function returning a boolean "packet handled" indication, for simpler channel building.consumerNetworkThread(io.netty.util.AttributeKey<C> key, org.apache.commons.lang3.function.TriConsumer<C, MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded.Set the message consumer, which is called once a message has been decoded.consumerNetworkThread(SimpleChannel.MessageBuilder.ToBooleanBiFunction<MSG, CustomPayloadEvent.Context> handler) Function returning a boolean "packet handled" indication, for simpler channel building.Set the message decoder, which reads the message from aFriendlyByteBuf.direction(PacketFlow direction) Set the direction that this packet is allowed to be sent/received.encoder(BiConsumer<MSG, BUF> encoder) Set the message encoder, which writes this message to aFriendlyByteBuf.
- 
Field Details- 
channel
- 
type
- 
idprivate final int id
- 
protocol
- 
encoder
- 
decoder
- 
consumer
- 
direction
 
- 
- 
Constructor Details- 
MessageBuilderprivate MessageBuilder(SimpleChannel channel, Class<MSG> type, int id, @Nullable @Nullable NetworkProtocol<BUF> protocol) 
 
- 
- 
Method Details- 
directionSet the direction that this packet is allowed to be sent/received. Use to enforce strict sided handling to prevent spoofing.- Parameters:
- direction- The direction this packet is allowed on.
- Returns:
- This message builder, for chaining.
 
- 
encoderSet the message encoder, which writes this message to aFriendlyByteBuf.The encoder is called immediately Channel.send(Object, PacketDistributor.PacketTarget) when the packet is sent}. This means encoding typically occurs on the main server/client thread rather than on the network thread. However, this behavior should not be relied on, and the encoder should try to be thread-safe and not interact with the current game state. - Parameters:
- encoder- The message encoder.
- Returns:
- This message builder, for chaining.
 
- 
decoderSet the message decoder, which reads the message from aFriendlyByteBuf.The decoder is called when the message is received on the network thread. The decoder should not attempt to access or mutate any game state, deferring that until the the message is handled. - Parameters:
- decoder- The message decoder.
- Returns:
- The message builder, for chaining.
 
- 
codecSet the StreamCodec to be used for marshaling the message object to and from aFriendlyByteBufThis has all the same limitations of encoder(BiConsumer)anddecoder(Function)as it is equivalent of calling those functions with the codec's encode and decode functions.- Parameters:
- codec- The codec to use.
- Returns:
- The message builder, for chaining.
 
- 
consumerpublic SimpleChannel.MessageBuilder<MSG,BUF> consumer(BiConsumer<MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded. This accepts the decoded message object and the message's context.The consumer is called on the network thread, and so should not interact with most game state by default. CustomPayloadEvent.Context.enqueueWork(Runnable)can be used to handle the message on the main server or client thread. Alternatively one can useconsumerMainThread(BiConsumer)to run the handler on the main thread.- Parameters:
- consumer- The message consumer.
- Returns:
- The message builder, for chaining.
- See Also:
 
- 
consumerNetworkThreadpublic SimpleChannel.MessageBuilder<MSG,BUF> consumerNetworkThread(BiConsumer<MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded. This accepts the decoded message object and the message's context.The consumer is called on the network thread, and so should not interact with most game state by default. CustomPayloadEvent.Context.enqueueWork(Runnable)can be used to handle the message on the main server or client thread. Alternatively one can useconsumerMainThread(BiConsumer)to run the handler on the main thread.- Parameters:
- consumer- The message consumer.
- Returns:
- The message builder, for chaining.
- See Also:
 
- 
consumerNetworkThreadpublic <C> SimpleChannel.MessageBuilder<MSG,BUF> consumerNetworkThread(io.netty.util.AttributeKey<C> key, org.apache.commons.lang3.function.TriConsumer<C, MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded. This accepts the decoded message object and the message's context. The instance will be retrieved from the associated AttributeKey on the channel.The consumer is called on the network thread, and so should not interact with most game state by default. CustomPayloadEvent.Context.enqueueWork(Runnable)can be used to handle the message on the main server or client thread. Alternatively one can useconsumerMainThread(BiConsumer)to run the handler on the main thread.- Parameters:
- consumer- The message consumer.
- Returns:
- The message builder, for chaining.
- See Also:
 
- 
consumerNetworkThreadpublic SimpleChannel.MessageBuilder<MSG,BUF> consumerNetworkThread(SimpleChannel.MessageBuilder.ToBooleanBiFunction<MSG, CustomPayloadEvent.Context> handler) Function returning a boolean "packet handled" indication, for simpler channel building.- See Also:
 
- 
consumerNetworkThreadpublic <C> SimpleChannel.MessageBuilder<MSG,BUF> consumerNetworkThread(io.netty.util.AttributeKey<C> key, SimpleChannel.MessageBuilder.ToBooleanTriFunction<C, MSG, CustomPayloadEvent.Context> handler) Function returning a boolean "packet handled" indication, for simpler channel building.- See Also:
 
- 
consumerMainThreadpublic SimpleChannel.MessageBuilder<MSG,BUF> consumerMainThread(BiConsumer<MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded. This accepts the decoded message object and the message's context.Unlike consumerNetworkThread(BiConsumer), the consumer is called on the main thread, and so can interact with most game state by default.- Parameters:
- consumer- The message consumer.
- Returns:
- The message builder, for chaining.
- See Also:
 
- 
consumerMainThreadpublic <C> SimpleChannel.MessageBuilder<MSG,BUF> consumerMainThread(io.netty.util.AttributeKey<C> key, org.apache.commons.lang3.function.TriConsumer<C, MSG, CustomPayloadEvent.Context> consumer) Set the message consumer, which is called once a message has been decoded. This accepts the decoded message object and the message's context. The instance will be retrieved from the associated AttributeKey on the channel.Unlike consumerNetworkThread(AttributeKey,TriConsumer), the consumer is called on the main thread, and so can interact with most game state by default.- Parameters:
- consumer- The message consumer.
- Returns:
- The message builder, for chaining.
- See Also:
 
- 
addFinishes building this packet.- Returns:
- The attached SimpleChannel to facilitate chaining.
 
 
-