Developer API
The static API other plugins can call, and the event they can listen to.
DeluxePouches exposes a small static API plus a Bukkit event. Everything lives under
fun.lewisdev.deluxepouches.
There is no public Maven repository for the plugin. Add the jar as a local dependency
and mark it provided, or drop it in your IDE's library list.
Setting up
Add DeluxePouches to your plugin.yml so it loads first:
softdepend: [DeluxePouches]Use depend instead if your plugin cannot work without it.
DeluxePouchesAPI
import fun.lewisdev.deluxepouches.api.DeluxePouchesAPI;| Method | Returns | Does |
|---|---|---|
getPouch(String id) | Optional<Pouch> | Looks a pouch up by id |
getPouches() | Map<String, Pouch> | Every registered pouch, keyed by id |
givePouch(Player player, String id, int amount) | boolean | Puts pouches in a player's inventory. false if the id is unknown |
getAnimation(String name) | Optional<PouchAnimation> | Looks an animation up by name |
getEffect(String name) | Optional<PouchEffect> | Looks an effect up by name |
registerAnimation(PouchAnimation animation) | void | Registers your own animation |
registerEffect(PouchEffect effect) | void | Registers your own effect |
createPouch(String id, ItemStack item, List<Reward> rewards, int rewardAmount, String animation, String effect) | Pouch | Builds a pouch at runtime and registers it |
getPlugin() | DeluxePouchesPlugin | The plugin instance |
Giving a pouch
if (!DeluxePouchesAPI.givePouch(player, "legendary", 3)) {
getLogger().warning("No pouch called legendary");
}Reading a pouch
DeluxePouchesAPI.getPouch("legendary").ifPresent(pouch -> {
getLogger().info(pouch.getIdentifier() + " has " + pouch.getRewards().size() + " rewards");
});Pouches created with createPouch live in memory only. They are gone after a reload
or a restart unless you create them again. For anything permanent, write to
pouches.yml.
PouchOpenEvent
Fired when a player opens a pouch, before the animation starts and before the pouch is taken out of the inventory. Cancel it to stop the opening.
import fun.lewisdev.deluxepouches.events.PouchOpenEvent;
@EventHandler
public void onPouchOpen(PouchOpenEvent event) {
if (event.getPlayer().getWorld().getName().equals("minigames")) {
event.setCancelled(true);
event.getPlayer().sendMessage("Not in here.");
}
}| Method | Returns | Meaning |
|---|---|---|
getPlayer() | Player | Who is opening it |
getPouch() | Pouch | Which pouch |
getLocation() | Location | Where the animation will play |
getBlock() | Block | The block the pouch was placed on, or null when it was right-clicked |
isCooldown() | boolean | true when the pouch was placed as a block |
isCancelled() / setCancelled(boolean) | boolean / void | Standard cancel handling |
Opening a stack with shift fires one event per pouch in the stack, and cancelling any of them stops the whole batch.
Watch your priority
DeluxePouches listens to its own event to run the animation. Cancel at
EventPriority.HIGH or earlier so your decision is in before that listener runs.
Pouch
The parts of Pouch you are most likely to touch:
| Method | Returns |
|---|---|
getIdentifier() | The pouch id |
getItem() | A fresh copy of the pouch item, tagged and ready to give |
getRewards() | A copy of the reward list |
getRewardAmount() | How many rewards are drawn per opening |
getAnimation() / getEffect() | The configured names |
getPermission() | The pouch's own permission, or an empty string |
isSimilar(ItemStack item) | Whether an item is this pouch |
randomRewards(int amount) | Draws rewards using the configured weights |
Pouch.removePouchFromPlayer(player, pouch) takes one pouch out of an inventory if you
need that yourself.
Version note
The API is small and has stayed stable, but it is not versioned separately from the plugin. Pin the jar you build against, and re-test after a plugin update.