Hooking into the Plugin Channel with your plugin!
Despite how "scary" plugin channels may seem, they are simple to use and hook into.
If you want your plugin to send messages to a player, you have to register that your plugin is going to output to the channel in on enable:
public void onEnable() { // Register plugin channel getServer().getMessenger().registerOutgoingPluginChannel(this, "SimpleNotice"); }
To send a message to a player, I suggest the use of this code:
if (player.getListeningPluginChannels().contains("SimpleNotice")) { player.sendPluginMessage(plugin, "SimpleNotice", message.getBytes(java.nio.charset.Charset.forName("UTF-8"))); } else { // Do something else }
Notice:
- Due to how Plugin Channels were implemented in Minecraft, you can not send Plugin Messages to players until after the player "joins" the game