RegenZones logoRegenZones

Developer API

Listen for right-click harvests and look up regen state from your own plugin.

RegenZones has a small, read-only API for other plugins, a battle pass or quest plugin counting harvests say. Add softdepend: [RegenZones] to your plugin.yml and compile against the RegenZones jar as provided.

RegenHarvestEvent

cc.arrowtan.regenzones.api.event.RegenHarvestEvent fires when a player right-click harvests a block in a regen region. A right-click harvest of a vanilla block fires no BlockBreakEvent, so without this event other plugins never see it.

GetterReturns
Player getPlayer()Who harvested
Block getBlock()Where, already showing the first placeholder stage
String getBlockKey()The material name, WHEAT, or itemsadder:namespace:id for an ItemsAdder block
String getRegionName()The region it happened in

It fires once the harvest has gone through, so it cannot be cancelled and never fires for a refused one (wrong tool, another plugin cancelling the break).

@EventHandler
public void onHarvest(RegenHarvestEvent event) {
    if (event.getBlockKey().equals("WHEAT")) {
        // count it
    }
}

An ItemsAdder harvest without harvest-drops breaks the block for real, so it also fires a BlockBreakEvent. RegenZonesAPI.get().isHarvesting(block) is true during that one, skip it there to avoid counting the harvest twice.

RegenZonesAPI

cc.arrowtan.regenzones.api.RegenZonesAPI.get() returns the API while RegenZones is enabled, and throws otherwise. RegenZonesAPI.isAvailable() checks first. Main thread only.

MethodReturns
boolean isPending(Block)True while the block is a placeholder waiting to regenerate
String regionAt(Location)The enabled region handling that spot, or null
boolean isHarvesting(Block)True during the BlockBreakEvent a harvest fires itself

isPending is the guard for counting breaks: a placeholder broken by a bypass player, or with strict-lock off, is not a real resource and should not count.

On this page