diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandSet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandSet.kt index d31a707..49d480f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandSet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandSet.kt @@ -36,6 +36,7 @@ class CommandSet(plugin: EcoPlugin) : Subcommand( return } + PlacedCrates.removeCrate(block.location) PlacedCrates.setAsCrate(block.location, crate) player.sendMessage(plugin.langYml.getMessage("set-block-as-crate")) 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 eb4615d..746d550 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 @@ -44,6 +44,14 @@ class Crate( val hologramHeight = config.getDouble("placed.hologram.height") + val showRandomReward = config.getBool("placed.random-reward.enabled") + + val randomRewardHeight = config.getDouble("placed.random-reward.height") + + val randomRewardDelay = config.getInt("placed.random-reward.delay") + + val randomRewardName = config.getFormattedString("placed.random-reward.name") + val particles = config.getSubsections("placed.particles").map { ParticleData( Particle.valueOf(it.getString("particle").uppercase()), diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/placed/PlacedCrate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/placed/PlacedCrate.kt index 46730a0..06405ad 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/placed/PlacedCrate.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/placed/PlacedCrate.kt @@ -4,6 +4,9 @@ import com.willfp.eco.core.integrations.hologram.HologramManager import com.willfp.ecocrates.EcoCratesPlugin import com.willfp.ecocrates.crate.Crate import org.bukkit.Location +import org.bukkit.entity.Item +import org.bukkit.util.Vector +import java.util.* class PlacedCrate( val crate: Crate, @@ -18,12 +21,29 @@ class PlacedCrate( z += 0.5 } - private val hologram = HologramManager.createHologram(location.clone().apply { - y += crate.hologramHeight - }, crate.hologramLines) + private val world = location.world!! + + private val hologram = HologramManager.createHologram( + location.clone().add(0.0, crate.hologramHeight, 0.0), + crate.hologramLines + ) + + private val item: Item? = if (crate.showRandomReward) { + val entity = world.dropItem( + location.clone().add(0.0, crate.randomRewardHeight, 0.0), + crate.rewards.first().display + ) + entity.velocity = Vector(0.0, 0.0, 0.0) + entity.pickupDelay = Int.MAX_VALUE + entity.setGravity(false) + entity.isCustomNameVisible = true + entity.customName = crate.randomRewardName + entity.owner = UUID(0, 0) + entity + } else null internal fun tick(tick: Int) { - tick.toLong() // Just shut up, compiler + tickRandomReward(tick) } internal fun tickAsync(tick: Int) { @@ -32,6 +52,14 @@ class PlacedCrate( internal fun onRemove() { hologram.remove() + item?.remove() + } + + private fun tickRandomReward(tick: Int) { + if (tick % crate.randomRewardDelay == 0) { + item?.itemStack = crate.rewards.random().display + item?.teleport(location.clone().add(0.0, crate.randomRewardHeight, 0.0)) + } } private fun tickParticles(tick: Int) { diff --git a/eco-core/core-plugin/src/main/resources/crates.yml b/eco-core/core-plugin/src/main/resources/crates.yml index b1402d9..2ae04e2 100644 --- a/eco-core/core-plugin/src/main/resources/crates.yml +++ b/eco-core/core-plugin/src/main/resources/crates.yml @@ -35,6 +35,11 @@ crates: left-click-opens: true placed: + random-reward: + enabled: true + height: 2 + delay: 30 + name: "&fYou could win:" particles: - particle: flame animation: spiral