public class SimpleChannel
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SimpleChannel.MessageBuilder<MSG> |
Modifier and Type | Field and Description |
---|---|
private IndexedMessageCodec |
indexedCodec |
private NetworkInstance |
instance |
private java.util.List<java.util.function.Function<java.lang.Boolean,? extends java.util.List<? extends org.apache.commons.lang3.tuple.Pair<java.lang.String,?>>>> |
loginPackets |
private java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> |
registryChangeConsumer |
Modifier | Constructor and Description |
---|---|
|
SimpleChannel(NetworkInstance instance) |
|
SimpleChannel(NetworkInstance instance,
java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify) |
private |
SimpleChannel(NetworkInstance instance,
java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify) |
Modifier and Type | Method and Description |
---|---|
<MSG> int |
encodeMessage(MSG message,
PacketBuffer target) |
<M> SimpleChannel.MessageBuilder<M> |
messageBuilder(java.lang.Class<M> type,
int id)
Build a new MessageBuilder.
|
<M> SimpleChannel.MessageBuilder<M> |
messageBuilder(java.lang.Class<M> type,
int id,
NetworkDirection direction)
Build a new MessageBuilder.
|
private void |
networkEventListener(NetworkEvent networkEvent) |
private void |
networkLoginGather(NetworkEvent.GatherLoginPayloadsEvent gatherEvent) |
<MSG> IndexedMessageCodec.MessageHandler<MSG> |
registerMessage(int index,
java.lang.Class<MSG> messageType,
java.util.function.BiConsumer<MSG,PacketBuffer> encoder,
java.util.function.Function<PacketBuffer,MSG> decoder,
java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer) |
<MSG> IndexedMessageCodec.MessageHandler<MSG> |
registerMessage(int index,
java.lang.Class<MSG> messageType,
java.util.function.BiConsumer<MSG,PacketBuffer> encoder,
java.util.function.Function<PacketBuffer,MSG> decoder,
java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer,
java.util.Optional<NetworkDirection> networkDirection) |
<MSG> void |
reply(MSG msgToReply,
NetworkEvent.Context context) |
<MSG> void |
send(PacketDistributor.PacketTarget target,
MSG message)
Send a message to the
PacketDistributor.PacketTarget from a PacketDistributor instance. |
<MSG> void |
sendTo(MSG message,
NetworkManager manager,
NetworkDirection direction) |
<MSG> void |
sendToServer(MSG message) |
private <MSG> org.apache.commons.lang3.tuple.Pair<PacketBuffer,java.lang.Integer> |
toBuffer(MSG msg) |
<MSG> IPacket<?> |
toVanillaPacket(MSG message,
NetworkDirection direction) |
private final NetworkInstance instance
private final IndexedMessageCodec indexedCodec
private final java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeConsumer
private java.util.List<java.util.function.Function<java.lang.Boolean,? extends java.util.List<? extends org.apache.commons.lang3.tuple.Pair<java.lang.String,?>>>> loginPackets
public SimpleChannel(NetworkInstance instance)
private SimpleChannel(NetworkInstance instance, java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify)
public SimpleChannel(NetworkInstance instance, java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify)
private void networkLoginGather(NetworkEvent.GatherLoginPayloadsEvent gatherEvent)
private void networkEventListener(NetworkEvent networkEvent)
public <MSG> int encodeMessage(MSG message, PacketBuffer target)
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, java.lang.Class<MSG> messageType, java.util.function.BiConsumer<MSG,PacketBuffer> encoder, java.util.function.Function<PacketBuffer,MSG> decoder, java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer)
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, java.lang.Class<MSG> messageType, java.util.function.BiConsumer<MSG,PacketBuffer> encoder, java.util.function.Function<PacketBuffer,MSG> decoder, java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer, java.util.Optional<NetworkDirection> networkDirection)
private <MSG> org.apache.commons.lang3.tuple.Pair<PacketBuffer,java.lang.Integer> toBuffer(MSG msg)
public <MSG> void sendToServer(MSG message)
public <MSG> void sendTo(MSG message, NetworkManager manager, NetworkDirection direction)
public <MSG> void send(PacketDistributor.PacketTarget target, MSG message)
PacketDistributor.PacketTarget
from a PacketDistributor
instance.
channel.send(PacketDistributor.PLAYER.with(()->player), message)
MSG
- The type of the messagetarget
- The curried target from a PacketDistributormessage
- The message to sendpublic <MSG> IPacket<?> toVanillaPacket(MSG message, NetworkDirection direction)
public <MSG> void reply(MSG msgToReply, NetworkEvent.Context context)
public <M> SimpleChannel.MessageBuilder<M> messageBuilder(java.lang.Class<M> type, int id)
IntSupplier
if it is a login
packet.M
- Type of typetype
- Type of messageid
- id in the indexed codecpublic <M> SimpleChannel.MessageBuilder<M> messageBuilder(java.lang.Class<M> type, int id, NetworkDirection direction)
IntSupplier
if it is a login
packet.M
- Type of typetype
- Type of messageid
- id in the indexed codecdirection
- a network direction which will be asserted before any processing of this message occurs. Use to
enforce strict sided handling to prevent spoofing.