Interface PacketReceiver<C extends ListenerContext>

Type Parameters:
C - the receiver's context beyond channel
All Superinterfaces:
ChannelAware

public interface PacketReceiver<C extends ListenerContext>
extends ChannelAware
Associates packets to individual packet reception handlers by channel.
  • Method Summary

    Modifier and Type Method Description
    Collection<net.minecraft.util.Identifier> getChannels()
    Returns the collection of all channels that have handlers in this receiver.
    boolean hasChannel​(net.minecraft.util.Identifier channel)
    Returns whether a channel has a handler in this receiver.
    boolean register​(net.minecraft.util.Identifier channel, ChannelHandler<? super C> handler)
    Registers a handler to a channel.
    ChannelHandler<? super C> unregister​(net.minecraft.util.Identifier channel)
    Removes the handler of a channel.
  • Method Details

    • register

      boolean register​(net.minecraft.util.Identifier channel, ChannelHandler<? super C> handler)
      Registers a handler to a channel.

      If a handler is already registered to the channel, this method will return false, and no change will be made. Use unregister(Identifier) to unregister the existing handler.

      Parameters:
      channel - the id of the channel
      handler - the handler
      Returns:
      whether the handler is registered
    • unregister

      ChannelHandler<? super C> unregister​(net.minecraft.util.Identifier channel)
      Removes the handler of a channel.

      The channel is guaranteed not to have a handler after this call.

      Parameters:
      channel - the id of the channel
      Returns:
      the previous handler, or null if no handler was bound to the channel
    • getChannels

      Collection<net.minecraft.util.Identifier> getChannels()
      Returns the collection of all channels that have handlers in this receiver.

      This collection does not contain duplicate channels.

      Specified by:
      getChannels in interface ChannelAware
      Returns:
      a collection of channels
    • hasChannel

      boolean hasChannel​(net.minecraft.util.Identifier channel)
      Returns whether a channel has a handler in this receiver.
      Specified by:
      hasChannel in interface ChannelAware
      Parameters:
      channel - the id of the channel to check
      Returns:
      whether the channel has a handler