43 lines
884 B
Kotlin
43 lines
884 B
Kotlin
package club.mcscrims.speedhg.recraft
|
|
|
|
import org.bukkit.Material
|
|
import java.util.concurrent.ConcurrentHashMap
|
|
|
|
class RecraftMaterial(
|
|
val maxSoupAmount: Int,
|
|
val materials: Array<Material>
|
|
): ConcurrentHashMap<Material, Int>() {
|
|
|
|
fun getPoints(): Float
|
|
{
|
|
return getOrDefault( getLowestMaterial(), 0 ).toFloat()
|
|
}
|
|
|
|
fun decrease(
|
|
material: Material,
|
|
amount: Int,
|
|
) {
|
|
put( material, get( material )!! - amount )
|
|
}
|
|
|
|
fun getLowestMaterial(): Material?
|
|
{
|
|
if ( size > 1 )
|
|
{
|
|
if (values.stream().anyMatch { int -> int == 0 })
|
|
return null
|
|
|
|
val materialIntegerEntry = entries.stream().min(Comparator.comparingInt { it.value })
|
|
return materialIntegerEntry.map { it.key }.orElse( null )
|
|
}
|
|
else return keys.stream().findFirst().orElse( null )
|
|
}
|
|
|
|
fun getMaterialValue() = ( maxSoupAmount / size ).toFloat()
|
|
|
|
fun reset()
|
|
{
|
|
replaceAll { _, _ -> 0 }
|
|
}
|
|
|
|
} |