Added semi_instant roll

This commit is contained in:
Auxilor
2022-03-20 12:49:18 +00:00
parent 1d57d951ad
commit c4705975fa
3 changed files with 83 additions and 1 deletions

View File

@@ -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
)
}
}

View File

@@ -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.

View File

@@ -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