1.x/API

From Citizens Wiki

< 1.x

Revision as of 11:51, 2 September 2011 by APunch (talk | contribs)

JavaDocs

Our API documentation can be found here. For a basic guide on hooking into Citizens, see below.

Using the Citizens API

Hooking into Citizens is the same as hooking into any other Bukkit plugin like PermissionsBukkit or iConomy. Add the latest version of Citizens.jar to your build path. Then, add this code to your onEnable in the main class:


public void onEnable() {
    PluginManager pm = getServer().getPluginManager();
    Plugin test = pm.getPlugin("Citizens");
    if (test != null) {
        System.out.println("Successfully hooked into Citizens!");
    } else {
        System.out.println("Citizens isn't loaded.");
        // disable your plugin because Citizens was not loaded
        pm.disablePlugin(this);
    }

Now, to actually use the methods that Citizens has to offer, add the following import to your code:

import net.citizensnpcs.api.CitizensManager

For specifics on the methods CitizensManager has, see our JavaDocs. For now, here is a basic example of how to use the class.

//checks if the passed Bukkit entity is an NPC
public void checkNPC(Entity entity) {
    if(CitizensManager.isNPC(entity)) {
        Bukkit.getServer().broadcastMessage(CitizensManager.get(entity).getStrippedName() + " is an NPC!");
    }
}

The last step is to make sure Citizens loads before your plugin. If it doesn't your plugin will throw some nasty console errors. To do this, add this line to your plugin.yml:

soft-depend: [Citizens]