Basic Operations

Create context

Player player = Bukkit.getPlayer("player");
Context<Player> context = Context.player(player);
// You can create it with null, but please be careful not to use it in any place 
// where a player is needed, such as checking permissions, sending messages
Context<Player> context = Context.player(null);

Get plugin instance

BukkitCustomFishingPlugin api = BukkitCustomFishingPlugin.getInstance()

Build an item instance

ItemStack itemStack = api.getItemManager().buildInternal(context, "rubbish");

Get effect modifier

Optional<EffectModifier> optional = api.getEffectManager().getEffectModifier("beginner_rod", MechanicType.ROD);
if (optional.isPresent()) {
    EffectModifier modifier = optional.get();
}

Create new effect instance

Effect effect = Effect.newInstance();

Apply the modifier

// There are three stages in total
// CAST: Determines what fishing mechanics are available (such as lava fishing)
// LOOT: Affects the weight of the next loot
// FISHING: Determines loot-related properties, such as size, score, and game difficulty
modifier.apply(effect, FishingEffectApplyEvent.Stage.CAST, context);

Get the loot at a certain location

context.arg(ContextKeys.LOCATION, player.getLocation()); // sets the player location
context.arg(ContextKeys.OTHER_LOCATION, custom_location); // sets the custom location
Loot loot = api.getLootManager().getNextLoot(effect, context); 

Convert loot into an itemStack

if (loot.type() == LootType.ITEM) {
    ItemStack itemStack = api.getItemManager().buildInternal(context, loot.id());
}

Get the itemStack from FishingLootSpawnEvent

@EventHandler
public void onLootSpawn(FishingLootSpawnEvent event) {
    if (event.getEntity() instanceof Item item) {
        ItemStack itemStack = item.getItemStack();
    }
}

Last updated