mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
fix hard fail on reload command
This commit is contained in:
parent
db1bfd957e
commit
729b3535bd
2 changed files with 16 additions and 10 deletions
|
|
@ -73,7 +73,9 @@ class CustomAnvil : JavaPlugin() {
|
|||
logger.warning("Please note CustomAnvil is a more recent version of UnsafeEnchantsPlus")
|
||||
}
|
||||
|
||||
reloadAllConfigs()
|
||||
val success = reloadAllConfigs(true)
|
||||
if(!success) return
|
||||
|
||||
// Load metrics
|
||||
val metric = Metrics(this, bstatsPluginId)
|
||||
MetricsUtil.addCustomMetric(metric)
|
||||
|
|
@ -88,30 +90,31 @@ class CustomAnvil : JavaPlugin() {
|
|||
)
|
||||
}
|
||||
|
||||
fun reloadAllConfigs(){
|
||||
fun reloadAllConfigs(hardFailSafe: Boolean): Boolean{
|
||||
saveDefaultConfig()
|
||||
|
||||
// Load material grouping config
|
||||
val itemGroupConfig = reloadResource(itemGroupingConfigFilePath) ?: return
|
||||
val itemGroupConfig = reloadResource(itemGroupingConfigFilePath, hardFailSafe) ?: return false
|
||||
// Read material groups from config
|
||||
val itemGroupsManager = ItemGroupManager()
|
||||
itemGroupsManager.prepareGroups(itemGroupConfig)
|
||||
|
||||
// Load enchantment conflicts config
|
||||
val conflictConfig = reloadResource(enchantConflicConfigFilePath) ?: return
|
||||
val conflictConfig = reloadResource(enchantConflicConfigFilePath, hardFailSafe) ?: return false
|
||||
// Read conflicts from config and material group manager
|
||||
val conflictManager = EnchantConflictManager()
|
||||
conflictManager.prepareConflicts(conflictConfig,itemGroupsManager)
|
||||
|
||||
// Load unit repair config
|
||||
val unitRepairConfig = reloadResource(unitRepairFilePath) ?: return
|
||||
val unitRepairConfig = reloadResource(unitRepairFilePath, hardFailSafe) ?: return false
|
||||
|
||||
// Set the global variable
|
||||
CustomAnvil.conflictManager = conflictManager
|
||||
CustomAnvil.unitRepairConfig = unitRepairConfig
|
||||
|
||||
// Test if default config
|
||||
// Test if is default config
|
||||
MetricsUtil.testIfConfigIsDefault(config, itemGroupConfig, conflictConfig, unitRepairConfig)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun reloadResource(resourceName: String,
|
||||
|
|
|
|||
|
|
@ -12,11 +12,15 @@ class ReloadExecutor : CommandExecutor {
|
|||
return false
|
||||
}
|
||||
sender.sendMessage("§eReloading config...")
|
||||
val commandSuccess = commandBody()
|
||||
val hardfail = args.isNotEmpty() && ("hard".equals(args[0],true))
|
||||
val commandSuccess = commandBody(hardfail)
|
||||
if(commandSuccess){
|
||||
sender.sendMessage("§aConfig reloaded !")
|
||||
}else{
|
||||
sender.sendMessage("§cConfig was not able to be reloaded...")
|
||||
if(hardfail){
|
||||
sender.sendMessage("§4Hard fail, plugin disabled")
|
||||
}
|
||||
}
|
||||
return commandSuccess
|
||||
}
|
||||
|
|
@ -24,10 +28,9 @@ class ReloadExecutor : CommandExecutor {
|
|||
/**
|
||||
* Execute the command, return true if success or false otherwise
|
||||
*/
|
||||
private fun commandBody(): Boolean{
|
||||
private fun commandBody(hardfail: Boolean): Boolean{
|
||||
try {
|
||||
CustomAnvil.instance.reloadAllConfigs()
|
||||
return true
|
||||
return CustomAnvil.instance.reloadAllConfigs(hardfail)
|
||||
}catch (e: Exception){
|
||||
e.printStackTrace()
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue