cc.funkemunky.api.tinyprotocol.api.packets.channelhandler

## Class TinyProtocol1_7

- java.lang.Object
- - cc.funkemunky.api.tinyprotocol.api.packets.channelhandler.TinyProtocol1_7

All Implemented Interfaces:
  AbstractTinyProtocol

    public abstract class TinyProtocol1_7
    extends java.lang.Object
    implements AbstractTinyProtocol

Represents a very tiny alternative to ProtocolLib.

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

### Field Summary

Fields
`protected boolean` `closed`
`protected org.bukkit.plugin.Plugin` `plugin`

### Constructor Summary

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

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `close()` Cease listening for packets.
`net.minecraft.util.io.netty.channel.Channel` `getChannel(org.bukkit.entity.Player player)` Retrieve the Netty channel associated with a player.
`protected java.lang.String` `getHandlerName()` Retrieve the name of the channel injector, default implementation is "tiny-" + plugin name + "-" + a unique ID.
`int` `getProtocolVersion(org.bukkit.entity.Player player)`
`boolean` `hasInjected(net.minecraft.util.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(net.minecraft.util.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, 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, java.lang.Object packet)` Invoked when the server is starting to send a packet to a player.
`void` `receivePacket(net.minecraft.util.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(net.minecraft.util.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(net.minecraft.util.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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### closed

    protected volatile boolean closed

#### plugin

    protected org.bukkit.plugin.Plugin plugin

### Constructor Detail

#### TinyProtocol1_7

    public TinyProtocol1_7(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,
                                             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.
  `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,
                                            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.
  `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, Object)` will be invoked with this packet.

Specified by:
  `sendPacket` in interface `AbstractTinyProtocol`
Parameters:
  `player` - - the destination player.
  `packet` - - the packet to send.

#### sendPacket

    public void sendPacket(net.minecraft.util.io.netty.channel.Channel channel,
                           java.lang.Object packet)

Send a packet to a particular client.

Note that `onPacketOutAsync(Player, 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, Object)` will be invoked with this packet.

Specified by:
  `receivePacket` in interface `AbstractTinyProtocol`
Parameters:
  `player` - - the player that sent the packet.
  `packet` - - the packet that will be received by the server.

#### receivePacket

    public void receivePacket(net.minecraft.util.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, Object)` will be invoked with this packet.

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

#### getHandlerName

    protected java.lang.String getHandlerName()

Retrieve the name of the channel injector, default implementation is "tiny-" + plugin name + "-" + a unique ID.

Note that this method will only be invoked once. It is no longer necessary to override this to support multiple instances.

Returns:
  A unique channel handler name.

#### 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.

Specified by:
  `injectPlayer` in interface `AbstractTinyProtocol`
Parameters:
  `player` - - the player to inject.

#### injectChannel

    public void injectChannel(net.minecraft.util.io.netty.channel.Channel channel)

Add a custom channel handler to the given channel.

Parameters:
  `channel` - - the channel to inject.

#### getChannel

    public net.minecraft.util.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.

#### getProtocolVersion

    public int getProtocolVersion(org.bukkit.entity.Player player)

Specified by:
  `getProtocolVersion` in interface `AbstractTinyProtocol`

#### uninjectPlayer

    public void uninjectPlayer(org.bukkit.entity.Player player)

Uninject a specific player.

Specified by:
  `uninjectPlayer` in interface `AbstractTinyProtocol`
Parameters:
  `player` - - the injected player.

#### uninjectChannel

    public void uninjectChannel(net.minecraft.util.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.

Specified by:
  `hasInjected` in interface `AbstractTinyProtocol`
Parameters:
  `player` - - the player.
Returns:
  TRUE if it is, FALSE otherwise.

#### hasInjected

    public boolean hasInjected(net.minecraft.util.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.

Specified by:
  `close` in interface `AbstractTinyProtocol`