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

com.tealcube.minecraft.bukkit.mythicdrops.tiers.MythicTierCustomModelData.kt Maven / Gradle / Ivy

There is a newer version: 9.0.4
Show newest version
package com.tealcube.minecraft.bukkit.mythicdrops.tiers

import com.tealcube.minecraft.bukkit.mythicdrops.api.tiers.TierCustomModelData
import dev.mythicdrops.Either
import dev.mythicdrops.Either.Companion.left
import dev.mythicdrops.Either.Companion.right
import io.pixeloutlaw.minecraft.spigot.mythicdrops.enumValueOrNull
import io.pixeloutlaw.minecraft.spigot.mythicdrops.getOrDefaultAsDefaultValueType
import org.bukkit.Material

internal data class MythicTierCustomModelData(
    override val modelData: Int = 0,
    override val weight: Double = 0.0,
    override val material: Material? = null
) : TierCustomModelData {
    companion object {
        fun fromMap(
            map: Map
        ): Either {
            val material = enumValueOrNull(map.getOrDefaultAsDefaultValueType("material", ""))
            if (map.containsKey("material") && material == null) {
                return left("material was present and invalid: ${map["material"]}")
            }
            return right(
                MythicTierCustomModelData(
                    modelData = map.getOrDefaultAsDefaultValueType("model-data", 0),
                    weight = map.getOrDefaultAsDefaultValueType("weight", 0.0 as Number).toDouble(),
                    material = enumValueOrNull(map.getOrDefaultAsDefaultValueType("material", ""))
                )
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy