API Documentation/Example 01: Getting the API

This page describes how to detect PlayerHeads on a server and get an instance of the API.

Checking for PlayerHeads

Plugins can easily check if PlayerHeads is present using Bukkit-standard methods. The following example plugin class shows this capability.


public class ExamplePlugin extends JavaPlugin {
    private boolean PHEnabled=false;
    public boolean hasPlayerheads(){return PHEnabled;} //quick later check
    private boolean isPlayerHeadsLoaded(){ //slower, first-time check
        return (this.getServer().getPluginManager().getPlugin("PlayerHeads") != null);
    public void onEnable(){
            getLogger().info("PlayerHeads support detected.");
			//do PlayerHeads related things here, register listeners, etc.

In addition to detecting PlayerHeads it is also possible to get the version string of the plugin after retrieving it with getPlugin(). (for example:  playerheadsinstance.getDescription​().getVersion() )  This may allow you to better confirm that the PlayerHeads version will support the API you use.

Getting an API instance to work with

Once you've confirmed that PlayerHeads exists, it should be possible to retieve an instance of the API.  In your onEnable method, or at a time after your plugin has already enabled:

import com.github.crashdemons.playerheads.api.PlayerHeads;
import com.github.crashdemons.playerheads.api.PlayerHeadsAPI;
//... and in some method: ...
PlayerHeadsAPI ph_api = PlayerHeads.getApiInstance();

This returns an object implementing all the methods documented in the PlayerHeadsAPI interface, including head operations, plugin information, and access to the underlying compatibility layer.


Be sure that whenever you reference PlayerHeads classes that you have checked that PlayerHeads exists on the server as above, otherwise you will encounter errors.


Posts Quoted:
Clear All Quotes