diff --git a/src/main/kotlin/net/axay/kspigot/kotlinextensions/GeneralExtensions.kt b/src/main/kotlin/net/axay/kspigot/kotlinextensions/GeneralExtensions.kt index 762c4d86..7f3505f7 100644 --- a/src/main/kotlin/net/axay/kspigot/kotlinextensions/GeneralExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/kotlinextensions/GeneralExtensions.kt @@ -16,7 +16,7 @@ internal class MinMaxPair>(a: T, b: T) { } } -internal fun T.apply(block: (T.() -> Unit)?): T { +internal fun T.applyIfNotNull(block: (T.() -> Unit)?): T { if (block != null) apply(block) return this diff --git a/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt b/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt index 6189bf60..521be771 100644 --- a/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt +++ b/src/main/kotlin/net/axay/kspigot/particles/KSpigotParticles.kt @@ -1,7 +1,7 @@ package net.axay.kspigot.particles import net.axay.kspigot.extensions.bukkit.worldOrException -import net.axay.kspigot.kotlinextensions.apply +import net.axay.kspigot.kotlinextensions.applyIfNotNull import org.bukkit.Location import org.bukkit.Particle import org.bukkit.entity.Player @@ -74,7 +74,7 @@ fun particle(particle: Particle, builder: KSpigotParticle.() -> Unit) * @see KSpigotParticle */ fun Location.particle(particle: Particle, builder: (KSpigotParticle.() -> Unit)? = null) - = KSpigotParticle(particle).apply(builder).spawnAt(this) + = KSpigotParticle(particle).applyIfNotNull(builder).spawnAt(this) /** * Accesses the particle builder and then immediately @@ -82,4 +82,4 @@ fun Location.particle(particle: Particle, builder: (KSpigotParticle.() -> Unit)? * @see KSpigotParticle */ fun Player.particle(particle: Particle, builder: (KSpigotParticle.() -> Unit)? = null) - = KSpigotParticle(particle).apply(builder).spawnFor(this) \ No newline at end of file + = KSpigotParticle(particle).applyIfNotNull(builder).spawnFor(this) \ No newline at end of file diff --git a/src/main/kotlin/net/axay/kspigot/sound/KSpigotSound.kt b/src/main/kotlin/net/axay/kspigot/sound/KSpigotSound.kt index e1304c26..bcd761aa 100644 --- a/src/main/kotlin/net/axay/kspigot/sound/KSpigotSound.kt +++ b/src/main/kotlin/net/axay/kspigot/sound/KSpigotSound.kt @@ -1,7 +1,7 @@ package net.axay.kspigot.sound import net.axay.kspigot.extensions.bukkit.worldOrException -import net.axay.kspigot.kotlinextensions.apply +import net.axay.kspigot.kotlinextensions.applyIfNotNull import org.bukkit.Location import org.bukkit.Sound import org.bukkit.SoundCategory @@ -53,7 +53,7 @@ fun sound(sound: Sound, builder: KSpigotSound.() -> Unit) * @see KSpigotSound */ fun Location.sound(sound: Sound, builder: (KSpigotSound.() -> Unit)? = null) - = KSpigotSound(sound).apply(builder).playAt(this) + = KSpigotSound(sound).applyIfNotNull(builder).playAt(this) /** * Accesses the sound builder and then immediately @@ -61,4 +61,4 @@ fun Location.sound(sound: Sound, builder: (KSpigotSound.() -> Unit)? = null) * @see KSpigotSound */ fun Player.sound(sound: Sound, builder: (KSpigotSound.() -> Unit)? = null) - = KSpigotSound(sound).apply(builder).playFor(this) + = KSpigotSound(sound).applyIfNotNull(builder).playFor(this)