Class TinyProtocol


  • public abstract class TinyProtocol
    extends java.lang.Object
    Represents a very tiny alternative to ProtocolLib.

    It now supports intercepting packets during login and status ping (such as OUT_SERVER_PING)!

    • Constructor Summary

      Constructors 
      Constructor Description
      TinyProtocol​(org.bukkit.plugin.Plugin plugin)
      Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients.
    • Method Summary

      Modifier and Type Method Description
      void close()
      Cease listening for packets.
      io.netty.channel.Channel getChannel​(org.bukkit.entity.Player player)
      Retrieve the Netty channel associated with a player.
      boolean hasInjected​(io.netty.channel.Channel channel)
      Determine if the given channel has been injected by TinyProtocol.
      boolean hasInjected​(org.bukkit.entity.Player player)
      Determine if the given player has been injected by TinyProtocol.
      void injectChannel​(io.netty.channel.Channel channel)
      Add a custom channel handler to the given channel.
      void injectPlayer​(org.bukkit.entity.Player player)
      Add a custom channel handler to the given player's channel pipeline, allowing us to intercept sent and received packets.
      java.lang.Object onPacketInAsync​(org.bukkit.entity.Player sender, io.netty.channel.Channel channel, java.lang.Object packet)
      Invoked when the server has received a packet from a given player.
      java.lang.Object onPacketOutAsync​(org.bukkit.entity.Player receiver, io.netty.channel.Channel channel, java.lang.Object packet)
      Invoked when the server is starting to send a packet to a player.
      void receivePacket​(io.netty.channel.Channel channel, java.lang.Object packet)
      Pretend that a given packet has been received from a given client.
      void receivePacket​(org.bukkit.entity.Player player, java.lang.Object packet)
      Pretend that a given packet has been received from a player.
      void sendPacket​(io.netty.channel.Channel channel, java.lang.Object packet)
      Send a packet to a particular client.
      void sendPacket​(org.bukkit.entity.Player player, java.lang.Object packet)
      Send a packet to a particular player.
      void uninjectChannel​(io.netty.channel.Channel channel)
      Uninject a specific channel.
      void uninjectPlayer​(org.bukkit.entity.Player player)
      Uninject a specific player.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TinyProtocol

        public TinyProtocol​(org.bukkit.plugin.Plugin plugin)
        Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients.

        You can construct multiple instances per plugin.

        Parameters:
        plugin - - the plugin.
    • Method Detail

      • onPacketOutAsync

        public java.lang.Object onPacketOutAsync​(org.bukkit.entity.Player receiver,
                                                 io.netty.channel.Channel channel,
                                                 java.lang.Object packet)
        Invoked when the server is starting to send a packet to a player.

        Note that this is not executed on the main thread.

        Parameters:
        receiver - - the receiving player, NULL for early login/status packets.
        channel - - the channel that received the packet. Never NULL.
        packet - - the packet being sent.
        Returns:
        The packet to send instead, or NULL to cancel the transmission.
      • onPacketInAsync

        public java.lang.Object onPacketInAsync​(org.bukkit.entity.Player sender,
                                                io.netty.channel.Channel channel,
                                                java.lang.Object packet)
        Invoked when the server has received a packet from a given player.

        Use Channel.remoteAddress() to get the remote address of the client.

        Parameters:
        sender - - the player that sent the packet, NULL for early login/status packets.
        channel - - channel that received the packet. Never NULL.
        packet - - the packet being received.
        Returns:
        The packet to recieve instead, or NULL to cancel.
      • sendPacket

        public void sendPacket​(org.bukkit.entity.Player player,
                               java.lang.Object packet)
        Send a packet to a particular player.

        Note that onPacketOutAsync(Player, Channel, Object) will be invoked with this packet.

        Parameters:
        player - - the destination player.
        packet - - the packet to send.
      • sendPacket

        public void sendPacket​(io.netty.channel.Channel channel,
                               java.lang.Object packet)
        Send a packet to a particular client.

        Note that onPacketOutAsync(Player, Channel, Object) will be invoked with this packet.

        Parameters:
        channel - - client identified by a channel.
        packet - - the packet to send.
      • receivePacket

        public void receivePacket​(org.bukkit.entity.Player player,
                                  java.lang.Object packet)
        Pretend that a given packet has been received from a player.

        Note that onPacketInAsync(Player, Channel, Object) will be invoked with this packet.

        Parameters:
        player - - the player that sent the packet.
        packet - - the packet that will be received by the server.
      • receivePacket

        public void receivePacket​(io.netty.channel.Channel channel,
                                  java.lang.Object packet)
        Pretend that a given packet has been received from a given client.

        Note that onPacketInAsync(Player, Channel, Object) will be invoked with this packet.

        Parameters:
        channel - - client identified by a channel.
        packet - - the packet that will be received by the server.
      • injectPlayer

        public void injectPlayer​(org.bukkit.entity.Player player)
        Add a custom channel handler to the given player's channel pipeline, allowing us to intercept sent and received packets.

        This will automatically be called when a player has logged in.

        Parameters:
        player - - the player to inject.
      • injectChannel

        public void injectChannel​(io.netty.channel.Channel channel)
        Add a custom channel handler to the given channel.
        Parameters:
        channel - - the channel to inject.
      • getChannel

        public io.netty.channel.Channel getChannel​(org.bukkit.entity.Player player)
        Retrieve the Netty channel associated with a player. This is cached.
        Parameters:
        player - - the player.
        Returns:
        The Netty channel.
      • uninjectPlayer

        public void uninjectPlayer​(org.bukkit.entity.Player player)
        Uninject a specific player.
        Parameters:
        player - - the injected player.
      • uninjectChannel

        public void uninjectChannel​(io.netty.channel.Channel channel)
        Uninject a specific channel.

        This will also disable the automatic channel injection that occurs when a player has properly logged in.

        Parameters:
        channel - - the injected channel.
      • hasInjected

        public boolean hasInjected​(org.bukkit.entity.Player player)
        Determine if the given player has been injected by TinyProtocol.
        Parameters:
        player - - the player.
        Returns:
        TRUE if it is, FALSE otherwise.
      • hasInjected

        public boolean hasInjected​(io.netty.channel.Channel channel)
        Determine if the given channel has been injected by TinyProtocol.
        Parameters:
        channel - - the channel.
        Returns:
        TRUE if it is, FALSE otherwise.
      • close

        public final void close()
        Cease listening for packets. This is called automatically when your plugin is disabled.