Skip to content

API Examples

William edited this page Sep 2, 2022 · 14 revisions

HuskHomes banner

API Examples

HuskHomes provides API for getting Homes and Warps, getting UserData and information about Users, teleporting OnlineUsers and letting you provide custom RandomTeleportEngines for extending the /rtp command's functionality.

1. Creating a class to interface with the API

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

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

}

2. Checking if HuskHomes is present and creating the hook

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

    public HuskHomesAPIHook huskHomesAPIHook;

    @Override
    public void onEnable() {
        if (Bukkit.getPluginManager().getPlugin("HuskHomes") != null) {
            this.huskHomesAPIHook = new HuskHomesAPIHook();
        }
    }
}

3. Getting an instance of the API

  • You can now get the API instance by calling HuskHomesAPI#getInstance()
import net.william278.huskhomes.api.HuskHomesAPI;

public class HuskHomesAPIHook {

    private final HuskHomesAPI huskHomesAPI;

    public HuskHomesAPIHook() {
        this.huskHomesAPI = HuskHomesAPI.getInstance();
    }

}

Guides

Documentation

Links

Clone this wiki locally