tech.carcadex.kotlinbukkitkit.extensions.ExConfiguration.kt Maven / Gradle / Ivy
The newest version!
/*
ORIGINAL PACKAGE: package br.com.devsrsouza.kotlinbukkitapi.extensions
ORIGINAL REPOSITORY: https://github.com/DevSrSouza/KotlinBukkitAPI
AUTHOR: https://github.com/DevSrSouza
Thanks DevSrSouza for KotlinBukkitAPI
*/
package tech.carcadex.kotlinbukkitkit.extensions
import org.bukkit.configuration.ConfigurationSection
public fun ConfigurationSection.putAll(map: Map) {
for ((key, value) in map) {
if (value is Map<*, *>) {
set(key, null)
(getConfigurationSection(key) ?: createSection(key)).putAll(value as Map)
} else {
set(key, value)
}
}
}
/**
* @returns the count of absent values that was set, if returns 0, no values was set to the Configuration
*/
public fun ConfigurationSection.putAllIfAbsent(map: Map): Int {
var missing = 0
for ((key, value) in map) {
if (value is Map<*, *>) {
missing += (getConfigurationSection(key) ?: createSection(key)).putAllIfAbsent(value as Map)
} else if (!contains(key)) {
missing++
}
}
return missing
}
public fun ConfigurationSection.toMap(): Map {
return getValues(false).apply {
forEach { k, v ->
if (v is ConfigurationSection) {
set(k, v.toMap())
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy