public abstract class TinyProtocol
extends java.lang.Object
It now supports intercepting packets during login and status ping (such as OUT_SERVER_PING)!
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected org.bukkit.plugin.Plugin |
plugin |
Constructor and Description |
---|
TinyProtocol(org.bukkit.plugin.Plugin plugin)
Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients.
|
Modifier and Type | Method and 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.
|
io.netty.channel.Channel |
getChannel(java.util.UUID uuid,
java.lang.Object playerConnection)
Retrieve the netty channel for async purposes
|
protected java.lang.String |
getHandlerName()
Retrieve the name of the channel injector, default implementation is "tiny-" + plugin name + "-" + a unique ID.
|
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 |
removeChannel(org.bukkit.entity.Player 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.
|
protected volatile boolean closed
protected org.bukkit.plugin.Plugin plugin
public TinyProtocol(org.bukkit.plugin.Plugin plugin)
You can construct multiple instances per plugin.
plugin
- - the plugin.public java.lang.Object onPacketOutAsync(org.bukkit.entity.Player receiver, io.netty.channel.Channel channel, java.lang.Object packet)
Note that this is not executed on the main thread.
receiver
- - the receiving player, NULL for early login/status packets.channel
- - the channel that received the packet. Never NULL.packet
- - the packet being sent.public java.lang.Object onPacketInAsync(org.bukkit.entity.Player sender, io.netty.channel.Channel channel, java.lang.Object packet)
Use Channel.remoteAddress()
to get the remote address of the client.
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.public void sendPacket(org.bukkit.entity.Player player, java.lang.Object packet)
Note that onPacketOutAsync(Player, Channel, Object)
will be invoked with this packet.
player
- - the destination player.packet
- - the packet to send.public void sendPacket(io.netty.channel.Channel channel, java.lang.Object packet)
Note that onPacketOutAsync(Player, Channel, Object)
will be invoked with this packet.
channel
- - client identified by a channel.packet
- - the packet to send.public void receivePacket(org.bukkit.entity.Player player, java.lang.Object packet)
Note that onPacketInAsync(Player, Channel, Object)
will be invoked with this packet.
player
- - the player that sent the packet.packet
- - the packet that will be received by the server.public void receivePacket(io.netty.channel.Channel channel, java.lang.Object packet)
Note that onPacketInAsync(Player, Channel, Object)
will be invoked with this packet.
channel
- - client identified by a channel.packet
- - the packet that will be received by the server.protected java.lang.String getHandlerName()
Note that this method will only be invoked once. It is no longer necessary to override this to support multiple instances.
public void injectPlayer(org.bukkit.entity.Player player)
This will automatically be called when a player has logged in.
player
- - the player to inject.public void injectChannel(io.netty.channel.Channel channel)
channel
- - the channel to inject.public io.netty.channel.Channel getChannel(org.bukkit.entity.Player player)
player
- - the player.public io.netty.channel.Channel getChannel(java.util.UUID uuid, java.lang.Object playerConnection)
uuid
- The uuid of the playerplayerConnection
- PlayerConnection objectpublic void removeChannel(org.bukkit.entity.Player player)
public void uninjectPlayer(org.bukkit.entity.Player player)
player
- - the injected player.public void uninjectChannel(io.netty.channel.Channel channel)
This will also disable the automatic channel injection that occurs when a player has properly logged in.
channel
- - the injected channel.public boolean hasInjected(org.bukkit.entity.Player player)
player
- - the player.public boolean hasInjected(io.netty.channel.Channel channel)
channel
- - the channel.public final void close()