Skip to content

How to use the API

CC007 edited this page Dec 23, 2023 · 19 revisions

Provided functionality

The api provides a multitude of functionalities. These can be accessed through the HeadsPluginApi.getHeadsPluginServices() method. You can get an instance of this class like so:

Optional<HeadsPluginServices> optionalServices = HeadsPluginApi.getHeadsPluginServices();
HeadsPluginServices services = optionalServices.orElseThrow(IllegalStateException::new);

Once the plugin is loaded, this optional will always be loaded, but only once the plugin's onEnable() method has completed.

This API provides the following services:

Service name HeadsPluginApi method Description
CategorySearcher services.categorySearcher() Used for retrieving heads from categories
CategoryUpdater services.categoryUpdater() Used for updating categories
HeadCreator services.headCreator() Used for uploading a player's head to the MineSkin.org website
HeadPlacer services.headPlacer() Used for placing a head in the Minecraft world
HeadSearcher services.headSearcher() Used for retrieving heads based on a search term or UUID
HeadToItemstackMapper services.headToItemstackMapper() Used to turn a Head object into a Bukkit Itemstack object

For a more in depth description, you can check the API docs

Events (since 3.3.0)

This API provides 2 events:

  • CategoryUpdatedEvent, an event that is fired whenever every individual category is done updating. This event provides the following fields:
    • categoryName (String)
    • duration (Double, how long it took to update this category in seconds)
    • endTime (Instant, the time that the update was done)
  • CategoriesUpdatedEvent, an event that is fired whenever all (necessary) categories are done updating. This event provides the following fields:
    • categoryNames (Collection<String>, the category names of the categories that were actually scheduled to be updated)
    • duration (Double, how long it took to update this category in seconds)
    • endTime (Instant, the time that the update was done)