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

com.skillw.pouvoir.internal.feature.selector.Range.kt Maven / Gradle / Ivy

There is a newer version: 1.6.7-beta-6
Show newest version
package com.skillw.pouvoir.internal.feature.selector

import com.skillw.asahi.util.castSafely
import com.skillw.pouvoir.api.feature.selector.SimpleSelector
import com.skillw.pouvoir.api.feature.selector.Target
import com.skillw.pouvoir.api.feature.selector.toTarget
import com.skillw.pouvoir.api.plugin.annotation.AutoRegister
import com.skillw.pouvoir.api.plugin.map.DataMap
import com.skillw.pouvoir.util.getNearByEntities

/**
 * Range
 *
 * @constructor Create empty Range
 */
@AutoRegister
object Range : SimpleSelector("range") {
    override fun SelectorContext.getTargets(caster: Target): Collection {
        val x = get("x", 10.0)
        val y = get("y", x)
        val z = get("z", x)
        return caster.location.getNearByEntities(x, y, z).map { it.toTarget() }
    }


    override fun addParameter(dataMap: DataMap, vararg args: Any?) {
        dataMap["x"] = args.getOrNull(0).castSafely() ?: 10.0
        dataMap["y"] = args.getOrNull(1).castSafely() ?: 10.0
        dataMap["z"] = args.getOrNull(2).castSafely() ?: 10.0
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy