Create KSpigotParticles.kt

This commit is contained in:
bluefireoly
2020-08-30 02:52:21 +02:00
parent a31f0a4c41
commit 96986d947e

View File

@@ -0,0 +1,53 @@
package net.axay.kspigot.particles
import org.bukkit.Location
import org.bukkit.Particle
import org.bukkit.entity.Player
import org.bukkit.util.Vector
data class KSpigotParticle(
val particle: Particle,
var amount: Int = 1,
var offset: Vector? = null,
var extra: Number = 1.0,
var data: Any? = null,
var force: Boolean = false
) {
fun spawnAt(loc: Location) {
loc.world?.spawnParticle(
particle,
loc,
amount,
offset?.x ?: 0.0,
offset?.y ?: 0.0,
offset?.z ?: 0.0,
extra.toDouble(),
data,
force
) ?: throw IllegalArgumentException("The world of the given location is null!")
}
fun spawnFor(player: Player) {
player.spawnParticle(
particle,
player.location,
amount,
offset?.x ?: 0.0,
offset?.y ?: 0.0,
offset?.z ?: 0.0,
extra.toDouble(),
data
)
}
}
fun particle(particle: Particle, builder: KSpigotParticle.() -> Unit)
= KSpigotParticle(particle).apply(builder)
fun Player.particle(particle: Particle, builder: KSpigotParticle.() -> Unit)
= KSpigotParticle(particle).apply(builder).spawnFor(this)
fun Location.particle(particle: Particle, builder: KSpigotParticle.() -> Unit)
= KSpigotParticle(particle).apply(builder).spawnAt(this)