Api Examples

HuskTowns provides a range of methods for getting, deleting and updating claims and town data.

This page assumes you've read the API introduction and have imported the HuskTowns API into your repository.

Project setup

Creating a class to interface with the API

  • Unless your plugin completely relies on HuskTowns, you shouldn't put HuskTowns API calls into your main class, otherwise if HuskTowns is not installed you'll encounter ClassNotFoundExceptions
Creating a hook class
public class HuskTownsAPIHook {

    public HuskTownsAPIHook() {
        // Ready to do stuff with the API
    }

}

Checking if HuskTowns is present and creating the hook

  • Check to make sure the HuskTowns plugin is present before instantiating the API hook class
Instantiating your hook
public class MyPlugin extends JavaPlugin {

    public HuskTownsAPIHook huskTownsHook;

    @Override
    public void onEnable() {
        if (Bukkit.getPluginManager().getPlugin("HuskTowns") != null) {
            this.huskTownsHook = new HuskTownsAPIHook();
        }
    }
}

Getting an instance of the API

  • You can now get the API instance by calling HuskTownsAPI#getInstance()
Getting an API instance
import net.william278.husktowns.api.HuskTownsAPI;

public class HuskTownsAPIHook {

    private final HuskTownsAPI huskTownsAPI;

    public HuskTownsAPIHook() {
        this.huskTownsAPI = HuskTownsAPI.getInstance();
    }

}

(Documentation forthcoming...)