mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add DeletableResource and made every non default config a DeletableResource.
This commit is contained in:
parent
74b31124fd
commit
5ed365b14d
3 changed files with 129 additions and 11 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue