Class TinyProtocol
It now supports intercepting packets during login and status ping (such as OUT_SERVER_PING)!
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTinyProtocol(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 TypeMethodDescriptionfinal voidclose()Cease listening for packets.io.netty.channel.ChannelgetChannel(org.bukkit.entity.Player player) Retrieve the Netty channel associated with a player.protected StringRetrieve the name of the channel injector, default implementation is "tiny-" + plugin name + "-" + a unique ID.booleanhasInjected(io.netty.channel.Channel channel) Determine if the given channel has been injected by TinyProtocol.booleanhasInjected(org.bukkit.entity.Player player) Determine if the given player has been injected by TinyProtocol.voidinjectChannel(io.netty.channel.Channel channel) Add a custom channel handler to the given channel.voidinjectPlayer(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.abstract ObjectonPacketInAsync(org.bukkit.entity.Player sender, io.netty.channel.Channel channel, Object packet) Invoked when the server has received a packet from a given player.abstract ObjectonPacketOutAsync(org.bukkit.entity.Player receiver, io.netty.channel.Channel channel, Object packet) Invoked when the server is starting to send a packet to a player.voidreceivePacket(io.netty.channel.Channel channel, Object packet) Pretend that a given packet has been received from a given client.voidreceivePacket(org.bukkit.entity.Player player, Object packet) Pretend that a given packet has been received from a player.voidsendPacket(io.netty.channel.Channel channel, Object packet) Send a packet to a particular client.voidsendPacket(org.bukkit.entity.Player player, Object packet) Send a packet to a particular player.voiduninjectChannel(io.netty.channel.Channel channel) Uninject a specific channel.voiduninjectPlayer(org.bukkit.entity.Player player) Uninject a specific player.
-
Field Details
-
closed
protected volatile boolean closed -
plugin
protected org.bukkit.plugin.Plugin plugin
-
-
Constructor Details
-
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 Details
-
onPacketOutAsync
public abstract Object onPacketOutAsync(org.bukkit.entity.Player receiver, io.netty.channel.Channel channel, 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 abstract Object onPacketInAsync(org.bukkit.entity.Player sender, io.netty.channel.Channel channel, 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
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
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
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
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.
-
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.
- 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.
-