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

com.skillw.pouvoir.api.feature.condition.ConditionData.kt Maven / Gradle / Ivy

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

import com.skillw.pouvoir.api.plugin.map.component.Keyable
import org.bukkit.configuration.serialization.ConfigurationSerializable
import org.bukkit.entity.LivingEntity

/**
 * @className ConditionData
 *
 * @author Glom
 * @date 2023/8/2 16:47 Copyright 2024 Glom.
 */
class ConditionData(override val key: Condition) : Keyable, ConfigurationSerializable {
    private val parameters = ArrayList>()

    fun push(map: Map): ConditionData {
        parameters.add(map)
        return this
    }

    fun condition(entity: LivingEntity?): Boolean {
        return parameters.all {
            key.condition(entity, it)
        }
    }

    fun addAll(other: ConditionData): ConditionData {
        if (other.key != key) return this
        other.parameters.forEach(this::push)
        return this
    }

    override fun hashCode(): Int {
        return key.hashCode()
    }

    override fun serialize(): MutableMap {
        return mutableMapOf(key.toString() to parameters)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is ConditionData) return false
        return key == other.key
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy