mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add reload config command
This commit is contained in:
parent
d9c7a9376b
commit
2f051a93e3
3 changed files with 70 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ import io.delilaheve.util.ConfigOptions
|
|||
import org.bukkit.Bukkit
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.alexcrea.command.ReloadExecutor
|
||||
import xyz.alexcrea.group.EnchantConflictManager
|
||||
import xyz.alexcrea.group.ItemGroupManager
|
||||
import xyz.alexcrea.util.Metrics
|
||||
|
|
@ -27,6 +28,11 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
const val bypassFusePermission = "ue.bypass.fuse"
|
||||
// Permission string required to bypass enchantment conflicts test
|
||||
const val bypassLevelPermission = "ue.bypass.level"
|
||||
// Permission string required to reload the config
|
||||
const val commandReloadPermission = "ue.command.reload"
|
||||
|
||||
// Command Name to reload the config
|
||||
const val commandReloadName = "reloadunsafeenchants"
|
||||
|
||||
// Item Grouping Configuration file name
|
||||
const val itemGroupingConfigFilePath = "item_groups.yml"
|
||||
|
|
@ -60,10 +66,24 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
instance = this
|
||||
// Load bstats
|
||||
val metric = Metrics(this, bstatsPluginId)
|
||||
saveDefaultConfig()
|
||||
|
||||
reloadAllConfigs()
|
||||
addCustomMetric(metric)
|
||||
|
||||
// Add command to reload the plugin
|
||||
val command = getCommand(commandReloadName)
|
||||
command?.setExecutor(ReloadExecutor())
|
||||
|
||||
server.pluginManager.registerEvents(
|
||||
AnvilEventListener(),
|
||||
this
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
fun reloadAllConfigs(){
|
||||
saveDefaultConfig()
|
||||
|
||||
// Load material grouping config
|
||||
val itemGroupConfig = reloadResource(itemGroupingConfigFilePath) ?: return
|
||||
// Read material groups from config
|
||||
|
|
@ -73,17 +93,15 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
// Load enchantment conflicts config
|
||||
val conflictConfig = reloadResource(enchantConflicConfigFilePath) ?: return
|
||||
// Read conflicts from config and material group manager
|
||||
conflictManager = EnchantConflictManager()
|
||||
val conflictManager = EnchantConflictManager()
|
||||
conflictManager.prepareConflicts(conflictConfig,itemGroupsManager)
|
||||
|
||||
// Load unit repair config
|
||||
unitRepairConfig = reloadResource(unitRepairFilePath) ?: return
|
||||
|
||||
server.pluginManager.registerEvents(
|
||||
AnvilEventListener(),
|
||||
this
|
||||
)
|
||||
val unitRepairConfig = reloadResource(unitRepairFilePath) ?: return
|
||||
|
||||
// Set the global variable
|
||||
UnsafeEnchants.conflictManager = conflictManager
|
||||
UnsafeEnchants.unitRepairConfig = unitRepairConfig
|
||||
}
|
||||
|
||||
private fun addCustomMetric(metric: Metrics) {
|
||||
|
|
@ -96,6 +114,7 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
metric.addCustomChart(SimplePie("sacrifice_illegal_enchant_cost") {
|
||||
ConfigOptions.sacrificeIllegalCost.toString()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun reloadResource(resourceName: String,
|
||||
|
|
|
|||
35
src/main/kotlin/xyz/alexcrea/command/ReloadExecutor.kt
Normal file
35
src/main/kotlin/xyz/alexcrea/command/ReloadExecutor.kt
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package xyz.alexcrea.command
|
||||
|
||||
import io.delilaheve.UnsafeEnchants
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||
if(!sender.hasPermission(UnsafeEnchants.commandReloadPermission)) {
|
||||
sender.sendMessage("§cYou do not have permission to reload the config")
|
||||
return false
|
||||
}
|
||||
sender.sendMessage("§eReloading config...")
|
||||
val commandSuccess = commandBody()
|
||||
if(commandSuccess){
|
||||
sender.sendMessage("§aConfig reloaded !")
|
||||
}else{
|
||||
sender.sendMessage("§cConfig was not able to be reloaded...")
|
||||
}
|
||||
return commandSuccess
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command, return true if success or false otherwise
|
||||
*/
|
||||
private fun commandBody(): Boolean{
|
||||
try {
|
||||
UnsafeEnchants.instance.reloadAllConfigs()
|
||||
return true
|
||||
}catch (ignored: Exception){
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue