AlphaRewardsDocs v2.0.0
AlphaRewardsGuidesDeveloper API

Developer API

Listen to claims, cancel them, and see streaks break from your own plugin.

On this page

AlphaRewards fires four standard Bukkit events. Any plugin can listen to them, cancel a claim before it happens, or react once it is done. All of them live in dev.alphastudio.alpharewards.api.events.

There is no Maven artifact. Add the AlphaRewards jar to your project as a compileOnly dependency, and declare softdepend: [AlphaRewards] or depend: [AlphaRewards] in your own plugin.yml.

Events

EventCancellableFires
AlphaRewardPreClaimEventYesAfter the claim is validated and before it is recorded. Cancel it to block the claim entirely.
AlphaRewardClaimEventNoAfter a claim has succeeded: it is recorded in the player's data and the reward commands have run. The save to disk is queued right after the event.
AlphaRewardStreakBreakEventNoWhenever a streak resets, on join or at claim time. The streak is already reset when it fires.
AutoClaimEventNoAfter a successful auto-claim on join. It fires in addition to the claim event, not instead of it.

What each event carries

EventGetters
AlphaRewardPreClaimEventgetPlayer(), getDay(), getMode() (DAILY or STREAK), isCancelled(), setCancelled(boolean)
AlphaRewardClaimEventgetPlayer(), getDay(), getMode()
AlphaRewardStreakBreakEventgetPlayer()
AutoClaimEventgetPlayer(), getDay()

Example listener

This blocks claims in a world where rewards should not be collected, and logs every successful claim:

public final class RewardListener implements Listener {

    @EventHandler
    public void onPreClaim(AlphaRewardPreClaimEvent event) {
        if (event.getPlayer().getWorld().getName().equals("minigames")) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onClaim(AlphaRewardClaimEvent event) {
        getLogger().info(event.getPlayer().getName()
            + " claimed day " + event.getDay() + " (" + event.getMode() + ")");
    }
}
A cancelled claim ends silently, with no message to the player. If you cancel one, tell the player why yourself.