Added CrateRewardEvent

This commit is contained in:
Auxilor
2022-03-17 10:21:40 +00:00
parent dbf438555a
commit 79b1dbdab4
2 changed files with 29 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import com.willfp.ecocrates.crate.roll.Roll
import com.willfp.ecocrates.crate.roll.RollOptions
import com.willfp.ecocrates.crate.roll.Rolls
import com.willfp.ecocrates.event.CrateOpenEvent
import com.willfp.ecocrates.event.CrateRewardEvent
import com.willfp.ecocrates.reward.Reward
import com.willfp.ecocrates.util.ConfiguredFirework
import com.willfp.ecocrates.util.ConfiguredSound
@@ -219,7 +220,10 @@ class Crate(
}
fun handleFinish(player: Player, roll: Roll, location: Location) {
roll.reward.giveTo(player)
val event = CrateRewardEvent(player, this, roll.reward)
Bukkit.getPluginManager().callEvent(event)
event.reward.giveTo(player)
finishSound.play(location)
finishFireworks.forEach { it.launch(location) }
}

View File

@@ -0,0 +1,24 @@
package com.willfp.ecocrates.event
import com.willfp.ecocrates.crate.Crate
import com.willfp.ecocrates.reward.Reward
import org.bukkit.entity.Player
import org.bukkit.event.HandlerList
import org.bukkit.event.player.PlayerEvent
class CrateRewardEvent(
player: Player,
val crate: Crate,
var reward: Reward
) : PlayerEvent(player) {
override fun getHandlers(): HandlerList {
return Companion.handlers
}
companion object {
private val handlers = HandlerList()
@JvmStatic
fun getHandlerList() = handlers
}
}