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

com.skillw.pouvoir.internal.feature.selector.Amount.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.BaseSelector
import com.skillw.pouvoir.api.feature.selector.Target
import com.skillw.pouvoir.api.plugin.annotation.AutoRegister
import com.skillw.pouvoir.api.plugin.map.DataMap

/**
 * Amount
 *
 * @constructor Create empty Amount
 */
@AutoRegister
object Amount : BaseSelector("amount") {
    override fun SelectorContext.select(caster: Target) {
        val amount = get("amount", 1)
        with(result) {
            while (size > amount) {
                remove(first())
            }
        }
    }

    override fun SelectorContext.filter(caster: Target) {
        select(caster)
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy