All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.carcadex.kotlinbukkitkit.extensions.ExEntity.kt Maven / Gradle / Ivy

There is a newer version: 1.0.1.0
Show newest version
/*
ORIGINAL PACKAGE: package br.com.devsrsouza.kotlinbukkitapi.extensions
ORIGINAL REPOSITORY: https://github.com/DevSrSouza/KotlinBukkitAPI
AUTHOR: https://github.com/DevSrSouza

Thanks DevSrSouza for KotlinBukkitAPI
 */

package tech.carcadex.kotlinbukkitkit.extensions

import org.bukkit.Location
import org.bukkit.entity.Entity
import org.bukkit.entity.EntityType
import org.bukkit.entity.Firework
import org.bukkit.entity.Player
import org.bukkit.entity.Projectile
import org.bukkit.inventory.meta.FireworkMeta
import org.bukkit.projectiles.ProjectileSource
import org.bukkit.util.Vector
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
public fun Entity.isPlayer(): Boolean {
    contract { returns(true) implies (this@isPlayer is Player) }

    return type == EntityType.PLAYER
}

//  firework

public inline fun firework(location: Location, block: FireworkMeta.() -> Unit): Firework {
    return location.spawn().apply { meta(block) }
}

public inline fun Firework.meta(block: FireworkMeta.() -> Unit): Firework = apply {
    fireworkMeta = fireworkMeta.apply(block)
}

public inline fun  ProjectileSource.launchProjectile(): T = launchProjectile(T::class.java)
public inline fun  ProjectileSource.launchProjectile(vector: Vector): T = launchProjectile(T::class.java, vector)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy