Java Reference
In-Depth Information
Here is the Java source code for our
HelloWorld
plugin, which is already typed
in for you in the file
~/Desktop/code/HelloWorld/src/helloworld/HelloWorld.java
. There's a
lot of weird stuff in here. (If you haven't downloaded the code for this topic to
your Desktop yet, grab it now from
http://media.pragprog.com/titles/ahmine2/code/
and create all the files.)
package
helloworld;
❶
❷
import
net.canarymod.plugin.Plugin;
import
net.canarymod.logger.Logman;
import
net.canarymod.Canary;
import
net.canarymod.commandsys.*;
import
net.canarymod.chat.MessageReceiver;
❸
public class
HelloWorld
extends
Plugin
implements
CommandListener {
public static
Logman logger;
public
HelloWorld() {
logger = getLogman();
}
@Override
public boolean
enable() {
logger.info(
"Starting up"
);
try
{
Canary.commands().registerCommands(this, this, false);
}
catch
(CommandDependencyException e) {
logger.error(
"Duplicate command name"
);
}
return
true;
}
@Override
public void
disable() {
}
❹
@Command(aliases = {
"hello"
},
description =
"Displays the hello world message."
,
permissions = {
""
},
toolTip =
"/hello"
)
public void
helloCommand(MessageReceiver caller,
String[]
parameters) {
❺
String
msg =
"That'sss a very niccce EVERYTHING you have there..."
;
Canary.instance().getServer().broadcastMessage(msg);
}
}