diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt index d2ad1cd..982caf1 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt @@ -20,14 +20,12 @@ import com.willfp.ecocrates.crate.placed.particle.ParticleData 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.reward.Reward import com.willfp.ecocrates.util.ConfiguredFirework import com.willfp.ecocrates.util.ConfiguredSound import com.willfp.ecocrates.util.PlayableSound -import org.bukkit.Location -import org.bukkit.Material -import org.bukkit.OfflinePlayer -import org.bukkit.Particle +import org.bukkit.* import org.bukkit.entity.Player import java.util.* @@ -105,7 +103,7 @@ class Crate( ) { getKeys(it).toString() }.register() } - private fun makeRoll(player: Player, location: Location): Roll { + private fun makeRoll(player: Player, location: Location, reward: Reward): Roll { val display = mutableListOf() // Add three to the scroll times so that it lines up @@ -115,7 +113,7 @@ class Crate( return rollFactory.create( RollOptions( - getRandomReward(), + reward, this, this.plugin, player, @@ -205,11 +203,15 @@ class Crate( adjustKeys(player, -1) } - open(player, location) + open(player, location, physicalKey) } - fun open(player: Player, location: Location? = null) { - makeRoll(player, location ?: player.location).roll() + fun open(player: Player, location: Location? = null, physicalKey: Boolean = false) { + val event = CrateOpenEvent(player, this, physicalKey, getRandomReward()) + Bukkit.getPluginManager().callEvent(event) + + val roll = makeRoll(player, location ?: player.location, event.reward) + roll.roll() } fun previewForPlayer(player: Player) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/event/CrateOpenEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/event/CrateOpenEvent.kt new file mode 100644 index 0000000..690c8cf --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/event/CrateOpenEvent.kt @@ -0,0 +1,25 @@ +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 CrateOpenEvent( + player: Player, + val crate: Crate, + val isPhysicalKey: Boolean, + var reward: Reward +) : PlayerEvent(player) { + override fun getHandlers(): HandlerList { + return Companion.handlers + } + + companion object { + private val handlers = HandlerList() + + @JvmStatic + fun getHandlerList() = handlers + } +}