io.github.ZeronDev.config.ConfigHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ZeronLib Show documentation
Show all versions of ZeronLib Show documentation
Minecraft Plugin Developer
package io.github.ZeronDev.config
import com.google.gson.Gson
import org.bukkit.configuration.file.YamlConfiguration
import java.io.File
object ConfigHandler {
fun newConfigFile(file: File) : YamlConfiguration? {
try {
file.createNewFile()
val config = YamlConfiguration.loadConfiguration(file)
config.save(file)
return config
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
fun getConfigFile(file: File) : YamlConfiguration? {
try {
return YamlConfiguration.loadConfiguration(file)
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
fun deleteConfigFile(file: File) {
try {
file.delete()
} catch (e: Exception) {
e.printStackTrace()
}
}
fun saveConfigFile(file: File) {
try {
YamlConfiguration.loadConfiguration(file).save(file)
} catch (e: Exception) {
e.printStackTrace()
}
}
fun Any.serializeToString() : String {
return Gson().toJson(this)
}
fun String.toObject(type: Class) : T {
return Gson().fromJson(this, type)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy