Skip to content

Instantly share code, notes, and snippets.

@spenk
Created July 26, 2012 01:30
Show Gist options
  • Select an option

  • Save spenk/3179742 to your computer and use it in GitHub Desktop.

Select an option

Save spenk/3179742 to your computer and use it in GitHub Desktop.
Canary Plugin Tutorial 1.0
import java.util.logging.Logger;
/**
*
* @author Spenk
*/
//dont forget to let your MAIN class extends Plugin
public class HelloWorld extends Plugin{
//initialize our listener
HelloWorldListener listener = new HelloWorldListener();
//initialize our logger
Logger log = Logger.getLogger("Minecraft");
//enable is called when the plugin is about to enabled
public void enable(){
//initalize our hooks
//@URL http://www.canarymod.net/javadocs/PluginLoader.Hook
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.PLAYER_CONNECT, listener, this, PluginListener.Priority.MEDIUM);
//add our command to help (command, description)
etc.getInstance().addCommand("/hello", "makes the sever greet you");
//notify that the plugin is enabled
log.info("HelloWorld by spenk Version 1.0 Enabled");
}
//disable is called when the plugin is about to disable
public void disable(){
//removes our command from /help
etc.getInstance().removeCommand("/hello");
//notify that the plugin is disabled
log.info("HelloWorld by spenk Version 1.0 Disabled");
}
}
/**
*
* @author Spenk
*
*/
//Dont forget to extend all classes wich uses hooks only PluginListener
//NEVER CALL YOUR PLUGINLISTENER PluginListener or something make it indicate the plugin
//so if ever an error occures we know wich plugin it is
public class HelloWorldListener extends PluginListener{
//add our hooks
//http://www.canarymod.net/javadocs/PluginListener
public boolean onCommand(Player player, String[] split) {
//checks if the command is /hello and the player also has the permission
if (split[0].equalsIgnoreCase("/hello") && player.canUseCommand("/hellouse")){
//checks if the command length is big/small enough
if (split.length > 1 || split.length < 1){
//sends the player a color.rose message
player.notify("Incorrect command usage!");
//stops the plugin from looping further
return true;
}
//sends a nice colored message to the player
player.sendMessage("§3Hello §5"+player.getName()+"§4!");
//stops the plugin from looping further
return true;
}
//let the server handle it further if the player cant use the command or the command is incorrect
return false;
}
//add our login check listener
public java.lang.Object onPlayerConnect(Player player,HookParametersConnect hookParametersConnect){
//checks if the player is allowed to have another message
if (player.canUseCommand("/helloLogin")){
//changes the login message
hookParametersConnect.setJoinMessage("§4Hey "+player.getName()+" JUST JOINED THE SERVER :D");
}
//returns
return hookParametersConnect;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment