类 SimpleChannel.MessageBuilder<MSG,BUF extends FriendlyByteBuf>
- 封闭类:
SimpleChannel
-
嵌套类概要
嵌套类修饰符和类型类说明static interface
static interface
-
字段概要
字段修饰符和类型字段说明private final SimpleChannel
private BiConsumer
<MSG, CustomPayloadEvent.Context> private PacketFlow
private BiConsumer
<MSG, BUF> private final int
private final NetworkProtocol
<BUF> -
构造器概要
构造器限定符构造器说明private
MessageBuilder
(SimpleChannel channel, Class<MSG> type, int id, @Nullable NetworkProtocol<BUF> protocol) -
方法概要
修饰符和类型方法说明add()
Finishes building this packet.codec
(StreamCodec<BUF, MSG> codec) Set the StreamCodec to be used for marshaling the message object to and from aFriendlyByteBuf
consumer
(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
.
-
字段详细资料
-
channel
-
type
-
id
private final int id -
protocol
-
encoder
-
decoder
-
consumer
-
direction
-
-
构造器详细资料
-
MessageBuilder
private MessageBuilder(SimpleChannel channel, Class<MSG> type, int id, @Nullable @Nullable NetworkProtocol<BUF> protocol)
-
-
方法详细资料
-
direction
Set the direction that this packet is allowed to be sent/received. Use to enforce strict sided handling to prevent spoofing.- 参数:
direction
- The direction this packet is allowed on.- 返回:
- This message builder, for chaining.
-
encoder
Set 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.
- 参数:
encoder
- The message encoder.- 返回:
- This message builder, for chaining.
-
decoder
Set 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.
- 参数:
decoder
- The message decoder.- 返回:
- The message builder, for chaining.
-
codec
Set the StreamCodec to be used for marshaling the message object to and from aFriendlyByteBuf
This 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.- 参数:
codec
- The codec to use.- 返回:
- The message builder, for chaining.
-
consumer
public 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.- 参数:
consumer
- The message consumer.- 返回:
- The message builder, for chaining.
- 另请参阅:
-
consumerNetworkThread
public 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.- 参数:
consumer
- The message consumer.- 返回:
- The message builder, for chaining.
- 另请参阅:
-
consumerNetworkThread
public <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.- 参数:
consumer
- The message consumer.- 返回:
- The message builder, for chaining.
- 另请参阅:
-
consumerNetworkThread
public SimpleChannel.MessageBuilder<MSG,BUF> consumerNetworkThread(SimpleChannel.MessageBuilder.ToBooleanBiFunction<MSG, CustomPayloadEvent.Context> handler) Function returning a boolean "packet handled" indication, for simpler channel building.- 另请参阅:
-
consumerNetworkThread
public <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.- 另请参阅:
-
consumerMainThread
public 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.- 参数:
consumer
- The message consumer.- 返回:
- The message builder, for chaining.
- 另请参阅:
-
consumerMainThread
public <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.- 参数:
consumer
- The message consumer.- 返回:
- The message builder, for chaining.
- 另请参阅:
-
add
Finishes building this packet.- 返回:
- The attached SimpleChannel to facilitate chaining.
-