Guide to bukkit plugins.

Off topicProgramming → Guide to bukkit plugins.

#Bukkit Plugins Hi there, this is a beginners guide to bukkit plugins. Bukkit Plugins are written in the high level programming language java. You should have some knowledge of Java to successfully code plugins, this just explains the creation of the plugin, not the language.

##Software-Needs To create the plugin you will need something called an IDE ,which you should know about when already being able to code java. Basically, the choice of the IDE is on personal preference. I prefer IntelliJ, so this tutorial will explain how to set everything up in that IDE. You can download it on its site. After installing it, you still need the bukkit.jar. Disclamer: Bukkit downloads are not available (at the moment) as a result of a DMCA takedown request.

##Setting up Now. Let’s get to the actual buisness. To create the project, start up IntelliJ and create a new Project. You’ll need to set a name and location of your preference. After creating it, you just create a packege and a class. To import the bukkit api, go Files > Project Structure > Modules > Dependencies and add the bukkit.jar and set the Scope to Provided. (Otherwise you will end up with a 40MB Project file.) Then, create a file in the project (not in the packege!) called plugin.yml. Copy this template and fill in:

name: (Plugin Name)
version: (Plugin Version)
author: (Your name)
main: (Packege and Main class name, e.g. com.example.plugin.MainClass)

Now, to set up your jar, just go to Files > Project Structure > Artifacts > + > From Modules with Dependencies, put in your main class name, add the plugin.yml via the + Button and you’re done. The jar will be created everytime you build your project.

#Coding Now to actual coding. ##Setting up the main class. Your main class is based on this example.

public class MainClass extends JavaPlugin
{
    public void onEnable ()
    {
        //This is the method called on enabling the plugin.
    }  
    public void onDisable
    {
        //This is the method called on disabling the plugin.
    }
}

You can copy this template. It will work for you. ##Adding a command This is one of the most important things in bukkit plugins. Commands. Now, bukkit has a method that is called when a command is entered.

public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
    //This is the method called when the command is executed.
    //CommandSender is the "sender" of the command, either the player or the console. Command is the actual command object, well use that in a few seconds. The label is the String used to call the command, and, self-explanatory, the String[] of args are the command arguments.
    //Now, we have to check whether the command is "ours".
    if (cmd.getName().equalsIgnoreCase("test")) {
        //Now do something.
        return true;
    }
    return false;
}

Looks like our highlight.js doesn’t like comments You also need to “register” the command in the plugin.yml. To do that, you can copy and fill out this:

commands:
    (CommandName):
        usage: (Text that displays when something went wrong)
        description: (Description of the command)

Done! ##Adding an event Events are called basically everytime something happens. Examples are an entity taking damage, a block being broken, a bucket filled and much, much, much more. The easiest way of using events is in the main plugin class. In the onEnable()-Method, you just have to insert this:

this.getServer().getPluginManager().registerEvents(this,this);

Then you can paste this method in your code:

public void onBlockBroken(BlockBreakEvent event) {
    //The blockbreakevent is replacable by every other event, of couse. See bukkit api javadoc for infos.
}

Bukkit-API

Panda-Compatible Code!

lel panda-compatible :P
:D yes, the first { in a new line. @PanFritz ;)
Then its Kidwai-compatible too :p