跳到主要内容

事件

TreasuresLite 提供以下自定义事件。所有事件均为 TabooLib 代理事件(继承自 BukkitProxyEvent),而非原生 Bukkit 事件。

监听方式:使用 TabooLib 的 @SubscribeEvent 注解,或通过 Bukkit 事件系统监听其生成的代理事件类。

TreasureOpenEvent

玩家右键打开宝箱时触发。可取消 — 取消后玩家无法打开该宝箱。

字段类型说明
chestString宝箱 ID
locationPlaceLocation?宝箱位置(可空)
import taboolib.common.platform.event.SubscribeEvent

@SubscribeEvent
fun onTreasureOpen(event: TreasureOpenEvent) {
val chestId = event.chest
val loc = event.location ?: return

// 禁止在特定世界打开宝箱
if (loc.world == "lobby") {
event.isCancelled = true
}
}

TreasureSpawnEvent

宝箱发包显示(生成)时触发。不可取消allowCancelled = false)。

字段类型说明
chestString宝箱 ID
locationPlaceLocation宝箱生成位置
@SubscribeEvent
fun onTreasureSpawn(event: TreasureSpawnEvent) {
println("宝箱 ${event.chest} 已在 ${event.location} 生成")
}

TreasureDestroyEvent

领取宝箱后,宝箱进行自销毁时触发。不可取消allowCancelled = false)。

字段类型说明
chestString宝箱 ID
locationPlaceLocation宝箱位置
@SubscribeEvent
fun onTreasureDestroy(event: TreasureDestroyEvent) {
println("宝箱 ${event.chest} 已在 ${event.location} 被销毁")
}