Plugins
Note: I'm planning on rewriting this in the near future. Everything will be handled by the server.
Before writing a plugin for RemoteAdmin, you must first understand the format I use to send data to the server. Data is send to the client in this format:
"PREFIX@ARG1@ARG2@ARG3..."
A client plugin binds itself to a prefix, and every message the server sends that starts with that prefix will be send to that plugin.
Sending data:
Sending data is easy, all you have to do is call the send() function. Below is an example of how to do this.
// This will store an instance of RemoteAdmin in 'ra'. RemoteAdmin ra; PluginManager pm = getServer().getPluginManager(); Plugin plugin = pm.getPlugin("RemoteAdmin"); if (plugin != null) { ra = (RemoteAdmin) plugin; } ... // This will send a chat message to all clients, using the previously defined 'ra' object. ra.send("CHAT@Playername@SO I HERD U LIEK MUDKIPZ?");
The client plugin
A client plugin outputs text to a JTextArea object in a tab. A plugin looks like this:
package me.coolblinger.remoteadmin.client.components; import me.coolblinger.remoteadmin.client.RemoteAdminPlugin; /** * This plugin handles messages sent from the server starting with <code>CHAT@</code>. */ public class ChatListener extends RemoteAdminPlugin { /** * This will make sure that the tab <code>chat</code> exists * and register this plugin as a listener for chat messages. */ @Override public void run() { registerTab("chat"); registerListener("CHAT"); } /** * This method wil be called when the server sends a message that starts with * <code>CHAT@</code>. * * @param prefix The prefix * @param args The arguments, in which <code>args[0]</code> is the prefix. */ @Override public void execute(String prefix, String[] args) { if (prefix.equals("CHAT")) { if (args.length >= 3) { String name = args[1]; String message = args[2].replace("%40", "@"); String formattedMessage = name + ": " + message; printToTab("chat", formattedMessage); } } } }
In order for RemoteAdmin to recognize a .jar file as a plugin, you must name the class "main", package it into a .jar file and place it in a folder named "plugins". The file structure looks like this:
../plugins/AwesomePlugin.jar ../plugins/AwesomerPlugin.jar ../RemoteAdmin.jar ../RemoteAdmin.xml
Comments