com.skillw.pouvoir.api.feature.selector.SelectResult.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
package com.skillw.pouvoir.api.feature.selector
import com.skillw.pouvoir.api.feature.selector.target.EntityTarget
import com.skillw.pouvoir.api.feature.selector.target.LocTarget
import org.bukkit.Location
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
/**
* @className SelectResult
*
* 选取结果
*
* @author Glom
* @date 2023/1/9 7:20 Copyright 2024 Glom.
*/
class SelectResult(targets: Collection = LinkedHashSet()) : LinkedHashSet(targets) {
/**
* 遍历
*
* @param consumer
* @param T
* @receiver
*/
inline fun forEach(consumer: T.(Int) -> Unit) =
filterIsInstance().forEachIndexed { index, entity -> entity.run { consumer(index) } }
/**
* 遍历 entity
*
* @param consumer
* @receiver
*/
fun forEachEntity(consumer: Entity.(Int) -> Unit) =
forEach { index -> if (isPresent) consumer(entity, index) }
/**
* 遍历 living entity
*
* @param consumer
* @receiver
*/
fun forEachLivingEntity(consumer: LivingEntity.(Int) -> Unit) =
forEach { index -> if (isPresent) (entity as? LivingEntity?)?.also { consumer(it, index) } }
/**
* 遍历 location
*
* @param consumer
* @receiver
*/
fun forEachLocation(consumer: Location.(Int) -> Unit) =
forEach { index -> if (isPresent) consumer(location, index) }
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy