Skip to main content

Developer API

Getting the API instance

HMCLeavesAPI.getInstance();

BlockData

There are currently three types of BlockData:

These classes are all immutable.

It is advised to never create these yourself unless you are registering new items. Instead, use the API methods shown below to get the data.


From this point on, it is assumed that the HMCLeavesAPI instance was declared as api. All API methods are annotated with Jetbrains Annotations

Interacting with BlockData in the World:

HMCLeavesApi#getBlockDataAt

Example Usage:

final Location location = new Location(Bukkit.getWorld("world"), 0, 0, 0);
final BlockData blockData = api.getBlockDataAt(location);

This returns the BlockData at a location.

HMCLeavesAPI#isCustomBlock

Example Usage:

final Location location = new Location(Bukkit.getWorld("world"), 0, 0, 0);
final boolean isCustomBlock = api.isCustomBlock(location);

This returns whether the block at a location has custom data.

HMCLeavesAPI#setCustomBlock

Example Usage:

final Location location = new Location(Bukkit.getWorld("world"), 0, 0, 0);
final String blockId = "my_custom_block";
final BlockData blockData = api.setCustomBlock(location, blockId, true);

This sets the block at a location to a custom block. The parameter setBlockInWorld should almost always be set to true, or else the data in the world and stored by HMCLeaves may be incompatible. This returns false if the BlockData was not found, and true if it was and the block was set.

HMCLeavesAPI#removeBlockDataAt

Example Usage:

final Location location = new Location(Bukkit.getWorld("world"), 0, 0, 0);
final BlockData blockData = api.removeBlockDataAt(location, true);

This removes the block data at a location. The parameter setBlockInWorld should almost always be set to true, or else the data in the world and stored by HMCLeaves may be incompatible. This returns true if the block was able to be removed and was in the world, and false if it was not.