1.x/API: Difference between revisions
From Citizens Wiki
< 1.x
No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
pm.disablePlugin(this); | pm.disablePlugin(this); | ||
} | } | ||
} | |||
</pre> | </pre> | ||
Now, to actually use the methods that Citizens has to offer, add the following import to your code: | Now, to actually use the methods that Citizens has to offer, add the following import to your code: | ||
<pre>import net.citizensnpcs.api.CitizensManager</pre> | <pre>import net.citizensnpcs.api.CitizensManager;</pre> | ||
For specifics on the methods CitizensManager has, see our JavaDocs. For now, here is a basic example of how to use the class. | For specifics on the methods CitizensManager has, see our JavaDocs. For now, here is a basic example of how to use the class. | ||
Line 34: | Line 35: | ||
</pre> | </pre> | ||
The last step is to make sure Citizens loads before your plugin. If it doesn't your plugin will throw some nasty console errors. | The last step is to make sure Citizens loads before your plugin. If it doesn't, your plugin will throw some nasty console errors. Add this line to your plugin.yml: | ||
<pre>soft-depend: [Citizens]</pre> | <pre>soft-depend: [Citizens]</pre> |
Revision as of 11:52, 2 September 2011
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. Add this line to your plugin.yml:
soft-depend: [Citizens]