-
Notifications
You must be signed in to change notification settings - Fork 60
Developer's API
Hello developer.
You probably came here because you wanted to implement support for your own plugin with Autorank. Or perhaps you wanted to know how Autorank works? You're at the right place. You'll get to know how Autorank exactly works and what kind of data Autorank can provide you.
If you want to access data of Autorank, you'll need to check if the server is running Autorank and if Autorank is enabled. You can do this as so:
public Autorank getAutorank() {
Plugin plugin = getServer().getPluginManager().getPlugin("Autorank");
// Plugin is not loaded or enabled
if (plugin == null || !(plugin instanceof Autorank)) {
return null; // You could also throw an exception if you want to.
}
return (Autorank) plugin;
}
This method will get check if Autorank is installed on the server and if it's enabled. It will return null if Autorank wasn't present; otherwise it will return the Autorank class.
To make a reference to the Autorank class, you'll have to define an Autorank object in your class and call the getAutorank() (from above) method. An example snippet:
private Autorank autorank;
// Your onEnable method in your main class
public void onEnable() {
autorank = getAutorank();
if (autorank == null) {
this.getLogger().warning("Autorank has not been found! Warning!");
} else {
this.getLogger().info("Autorank has been found and has been hooked into!");
}
// rest of your code
}
This is your basic setup for hooking into Autorank. After you have verified that Autorank is installed on the server (and enabled), you can get the API class and start getting data!
Before we can get data off of Autorank, we need to find its API class. Fortunately, that's really easy. See this snippet below:
private API autorankAPI;
private Autorank autorank;
public API getAutorankAPI() {
// Check whether Autorank has been found earlier on
if (autorank == null || !autorank.isEnabled()) {
// Warning: Autorank is not enabled!
return null;
}
API autorankAPI = autorank.getAPI();
return autorankAPI;
}
We check whether Autorank is found and if it's found, we get the API class of Autorank. This is the basic setup for your plugin. You are now ready to start working with Autorank. Happy coding!
Autorank has its own events.
Currently (as of Beta 2.6), there is 1 event. It's called PlayerPromoteEvent and it's fired when a player is going to be promoted to a new group. It is cancellable.
You would listen to it as any other Bukkit event. An example:
@EventHandler
public void onPlayerPromote(PlayerPromoteEvent event) {
// do fancy stuff here.
}
It's really easy!