Skip to content
hsun324 edited this page Jul 4, 2011 · 1 revision

Basic Things

Setup

Download SimpleBukkit the include it as a library in your plugin. Open up your plugins initial class, and follow the rest of this page.

Import

import com.hsun324.simplebukkit.SimpleBukkitPlugin;

Using SimpleBukkit

Commands

If you are going to be programming commands, then you need to add another import and a line to your onCommand call.

import com.hsun324.simplebukkit.bindings.CommandBindings;
public boolean onCommand(CommandSender sender, Command command, String title, String[] args) {
    return CommandBindings.getInstance().executeCommand(sender, command, title, args);
}

To register commands, you need to use the @CommandDeclaration annotation on a public static ErrorType function. It is required to have the parameters shown below.

import com.hsun324.simplebukkit.CommandBindings.CommandDeclaration;
import com.hsun324.simplebukkit.CommandBindings.ErrorType;
import com.hsun324.simplebukkit.CommandBindings.FlagList;
@CommandDeclaration(
    aliases = {"aliasone", "aliastwo"}, // These are not case-senstive
    description = "example", // This will be shown when there is a syntax error.
    flags = {"flagone", "flagtwo"}, // These are flags. (/aliasone -flagone -flagtwo)
    minArgs = 0, // This is the minimum amount of arguments the command can have.
    maxArgs = 0, // This is the maximum amount of arguments the command can have.
    basePermission = "example.alias", // This is a permissions permissions that you must have to execute this command.
    usage() = "[-flagone|-flagtwo]" // This will be shown when there is a syntax error.
)
public static ErrorType aliasCommand(Player player, String command, String[] arguments, FlagList flags)
{
   //... Do stuff here ...
   return ErrorType.OK;
   return ErrorType.SYNTAX_ERROR;
   return ErrorType.INVALID_PLAYER;
   // OR
   return new ErrorType(203920,     "Error",      true,             false);
   //           Error ID ^^^^    Desc ^^^   Error? ^^  Syntax Error? ^^^
}

You will also need to add a line to both onEnable and onDisable calls.

public void onEnable() {
    //...
    CommandBindings.getInstance().addCommandClass(TheClassWithTheCommand.class);
    //...
}
public void onDisable() {
    //...
    CommandBindings.getInstance().removeCommandClass(TheClassWithTheCommand.class);
    //...
}

Events

If you are going to be programming events then you will need an import.

import com.hsun324.simplebukkit.bindings.EventBindings;

To register events, you need to use the @EventDeclaration annotation on a public static void function. It is required to have the standard parameter for that event until further notice.
You are allowed to have different categories of events and different priorities in a class.

import org.bukkit.event.Event.Type;
@EventDeclaration(
    value = Type.PLAYER_INTERACT, // The event you want to capture.
    priority = Priority.Monitor // The event priority you require.
)
// You may also use simply @EventDeclaration(Type.PLAYER_INTERACT) however this defaults to Normal priority.
public static void (PlayerInteractEvent event)
{
    //... Do stuff here ...
}

Advanced Things

Node Browsing

Node Browsing consists of using a NodeBrowser and browsing through nodes. To create a NodeBrowser you use a ConfigurationWrapper.

import com.hsun324.simplebukkit.config.NodeBrowser;
import com.hsun324.simplebukkit.config.yaml.YAMLConfigurationWrapper;
import java.io.File;

//...

// Creates a NodeBrowser and sets it to use the "stuff" node.
NodeBrowser browser = NodeBrowser.create(new YAMLConfigurationWrapper(someFile), "stuff");

The functions within the NodeBrowser are very self explanatory.

Colored Messages

You are able to send colored messages using the ColoredMessageSender. The colored message sender converts a message like "&eHello &6World!" into one where the "Hello" is yellow and the "World!" is gold.

import com.hsun324.simplebukkit.player.ColoredMessageSender;

//...

// Sends a "yellow" message. The &6 makes the World! golden.
ColoredMessageSender.sendInfoMessage(player, "Hello &6World!");

The ColoredMessageSender converts codes based on the table at Classic server protocol in the Minecraft Wiki. The codes must start with a ampersand (&) and be followed immediatly by a letter from A-F and 0-9.