Added semi_instant roll
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.willfp.ecocrates.crate.roll
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.util.NumberUtils
|
||||
import com.willfp.ecocrates.crate.Crate
|
||||
import com.willfp.ecocrates.reward.Reward
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.entity.Item
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.util.Vector
|
||||
|
||||
class RollSemiInstant private constructor(
|
||||
override val reward: Reward,
|
||||
override val crate: Crate,
|
||||
override val plugin: EcoPlugin,
|
||||
override val player: Player,
|
||||
override val location: Location,
|
||||
override val isReroll: Boolean
|
||||
) : Roll {
|
||||
private val itemLifespan = plugin.configYml.getInt("rolls.semi_instant.item-lifespan")
|
||||
|
||||
private val randomness = plugin.configYml.getDouble("rolls.semi_instant.velocity.randomness")
|
||||
|
||||
private val velocity = Vector(
|
||||
plugin.configYml.getDouble("rolls.semi_instant.velocity.x"),
|
||||
plugin.configYml.getDouble("rolls.semi_instant.velocity.y"),
|
||||
plugin.configYml.getDouble("rolls.semi_instant.velocity.z")
|
||||
).apply {
|
||||
this.x += NumberUtils.randFloat(-randomness, randomness)
|
||||
this.y += NumberUtils.randFloat(-randomness, randomness)
|
||||
this.z += NumberUtils.randFloat(-randomness, randomness)
|
||||
}
|
||||
|
||||
private lateinit var item: Item
|
||||
|
||||
override fun roll() {
|
||||
val world = location.world!!
|
||||
|
||||
item = world.dropItem(location, reward.getDisplay(player, crate))
|
||||
item.pickupDelay = Int.MAX_VALUE
|
||||
item.isCustomNameVisible = true
|
||||
item.customName = reward.displayName
|
||||
|
||||
player.closeInventory()
|
||||
|
||||
item.velocity = velocity
|
||||
}
|
||||
|
||||
override fun tick(tick: Int) {
|
||||
// No tick.
|
||||
}
|
||||
|
||||
override fun shouldContinueTicking(tick: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
plugin.scheduler.runLater(itemLifespan.toLong()) {
|
||||
item.remove()
|
||||
}
|
||||
}
|
||||
|
||||
object Factory : RollFactory<RollSemiInstant>("semi_instant") {
|
||||
override fun create(options: RollOptions): RollSemiInstant =
|
||||
RollSemiInstant(
|
||||
options.reward,
|
||||
options.crate,
|
||||
options.plugin,
|
||||
options.player,
|
||||
options.location,
|
||||
options.isReroll
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ object Rolls {
|
||||
val ENCIRCLE: RollFactory<*> = RollEncircle.Factory
|
||||
val QUICK: RollFactory<*> = RollQuick.Factory
|
||||
val INSTANT: RollFactory<*> = RollInstant.Factory
|
||||
val SEMI_INSTANT: RollFactory<*> = RollSemiInstant.Factory
|
||||
|
||||
/**
|
||||
* Get roll factory matching id.
|
||||
|
||||
@@ -100,4 +100,11 @@ rolls:
|
||||
quick:
|
||||
height: 1.5
|
||||
rise-velocity: 0.05
|
||||
suspend: 10
|
||||
suspend: 10
|
||||
semi_instant:
|
||||
velocity:
|
||||
randomness: 0.2
|
||||
x: 0
|
||||
y: 1
|
||||
z: 0
|
||||
item-lifespan: 30
|
||||
Reference in New Issue
Block a user