Java Reference
In-Depth Information
Import the plugin listener and the event hook(s) classes.
Declare that your plugin implementsPluginListener .
Register to listen for events with registerListener .
Add the magical tag @HookHandler , marking your function as an event
handler. Give the event you want as an argument.
You'll see all four parts in this short example skeleton of a listener:
import net.canarymod.hook.HookHandler;
import net.canarymod.plugin.PluginListener;
// import the particular hook class here
// Add "implements PluginListener" here:
public class HelloWorld extends EZPlugin implements PluginListener {
public boolean enable() {
Canary.hooks().registerListener(this, this);
return super.enable(); // Call parent class's version too.
// Here's one event listener:
public void anyname(SomeHook hookevent) {
// Some code goes here
First off, you have to import the class for the event you're interested in (you'd
add this somewhere around ).
There are a ton of events available, all listed in the Canary documentation
under net.canarymod.hook and its children. Suppose you're interested in doing
something whenever someone in the game teleports. You'd want the TeleportHook
class in the package net.canarymod.hook.player , so first thing here you'd import
net.canarymod.hook.player.TeleportHook .
Then the declaration for the plugin needs to add the magic words implements
PluginListener , as shown at .
Next you need to add your own enable() function, which then calls the parent
class's enable as shown starting at . This is a standard piece of boilerplate
code that just says “make this plugin listen for events.” You need this only
once in this file; it will work for all events you'll use. Add it in, and off we go.
Finally we come to the event listener itself, starting at . That @HookHandler
thing is an annotation that tells Java that the next function is special, just
Search WWH ::

Custom Search