From 96986d947e65ca814d0a9be728cc94eafa06d648 Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Sun, 30 Aug 2020 02:52:21 +0200 Subject: [PATCH] Create KSpigotParticles.kt --- .../kspigot/particles/KSpigotParticles.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt diff --git a/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt b/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt new file mode 100644 index 00000000..3d04e2bb --- /dev/null +++ b/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt @@ -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) \ No newline at end of file