基础操作

创建上下文

Player player = Bukkit.getPlayer("player");
Context<Player> context = Context.player(player);

// 可以用 null 创建,但注意不要在需要玩家的地方使用(如检查权限、发送消息)
Context<Player> context = Context.player(null);

获取插件实例

BukkitCustomFishingPlugin api = BukkitCustomFishingPlugin.getInstance()

构建物品实例

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

获取效果修改器

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

创建新效果实例

Effect effect = Effect.newInstance();

应用修改器

// 总共有三个阶段
// CAST: 决定可用的钓鱼机制(如熔岩钓鱼)
// LOOT: 影响下一个战利品的权重
// FISHING: 决定战利品相关属性,如大小、分数和游戏难度
modifier.apply(effect, FishingEffectApplyEvent.Stage.CAST, context);

获取特定位置的战利品

context.arg(ContextKeys.LOCATION, player.getLocation()); // 设置玩家位置
context.arg(ContextKeys.OTHER_LOCATION, custom_location); // 设置自定义位置,通常是鱼钩位置
context.arg(ContextKeys.SURROUNDING, "water");
Loot loot = api.getLootManager().getNextLoot(effect, context); 

将战利品转换为 itemStack

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

从 FishingLootSpawnEvent 获取 itemStack

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

最后更新于

这有帮助吗?