For the complete documentation index, see llms.txt. This page is also available as Markdown.

API

Package

The API is in our repository: repo.incredibleplugins.com

Javadoc

The Javadoc can be found here: repo.incredibleplugins.com

Getting the API instance

The API is accessible through an implementation of the ChestProtectAPI interface. Access it after ChestProtect is loaded (e.g. in onEnable):

ChestProtectAPI api = ChestProtectAPI.getInstance();

Calling getInstance() before ChestProtect is loaded throws a NullPointerException. If you used softdepend, guard the call with a null-check on Bukkit.getPluginManager().getPlugin("ChestProtect").


Checking and looking up protections

Is a block or entity protectable?

ProtectionManager manager = api.getProtectionManager();

boolean canProtectBlock  = manager.isProtectableBlock(Material.CHEST);
boolean canProtectEntity = manager.isProtectableEntity(EntityType.ITEM_FRAME);

Look up a block protection

Look up an entity protection


Working with protections

Every BlockProtection and EntityProtection extends Protection, which provides:


Creating protections

You must provide a ProtectionHook that identifies your plugin as the creator. Protections created by a hook are automatically deleted if the owning plugin has not been active for 30 days.

1. Implement ProtectionHook

2. Register the hook on enable

3. Create a protection

createBlockProtection / createEntityProtection throw IllegalArgumentException if the block or entity type is not protectable, and IllegalStateException if the block or entity is already protected.


Player data

Online player

Offline player

Offline player data is fetched asynchronously from the database:

Player flags


Events

Listen to ChestProtect events the same way as any Bukkit event:

Event
Fired when

ProtectionPreCreationEvent

Before a protection is created — cancellable

ProtectionCreatedEvent

After a protection has been created

ProtectionDeletedEvent

After a protection has been deleted

PlayerOpenProtectionEvent

When a player opens a protection — cancellable

ProtectionChunkAddedEvent

A chunk receives its first protection

ProtectionChunkDeletedEvent

The last protection in a chunk is deleted

Last updated