Add DeletableResource and made every non default config a DeletableResource.

This commit is contained in:
alexcrea 2024-07-23 02:48:27 +02:00
parent 74b31124fd
commit 5ed365b14d
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
3 changed files with 129 additions and 11 deletions

View file

@ -148,20 +148,34 @@ class CustomAnvil : JavaPlugin() {
if (!file.exists()) {
saveResource(resourceName, false)
}
return reloadResource(file, hardFailSafe)
}
// Unlike above function. this function will not clone default from jar.
fun reloadResource(
resourceFile: File,
hardFailSafe: Boolean = true
): YamlConfiguration? {
// Test if file exist
if (!resourceFile.exists()) {
return null
}
// Load resource
val yamlConfig = YamlConfiguration()
try {
val configReader = FileReader(file)
val configReader = FileReader(resourceFile)
yamlConfig.load(configReader)
} catch (test: Exception) {
if (hardFailSafe) {
// This is important and may impact gameplay if it does not load.
// Failsafe is to stop the plugin
logger.severe("Resource $resourceName Could not be load or reload.")
logger.severe("Resource ${resourceFile.path} Could not be load or reload.")
logger.severe("Disabling plugin.")
Bukkit.getPluginManager().disablePlugin(this)
} else {
logger.warning("Resource $resourceName Could not be load or reload.")
logger.warning("Resource ${resourceFile.path} Could not be load or reload.")
}
return null
}