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