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.Bukkit
|
||||||
import org.bukkit.configuration.file.YamlConfiguration
|
import org.bukkit.configuration.file.YamlConfiguration
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
import xyz.alexcrea.command.ReloadExecutor
|
||||||
import xyz.alexcrea.group.EnchantConflictManager
|
import xyz.alexcrea.group.EnchantConflictManager
|
||||||
import xyz.alexcrea.group.ItemGroupManager
|
import xyz.alexcrea.group.ItemGroupManager
|
||||||
import xyz.alexcrea.util.Metrics
|
import xyz.alexcrea.util.Metrics
|
||||||
|
|
@ -27,6 +28,11 @@ class UnsafeEnchants : JavaPlugin() {
|
||||||
const val bypassFusePermission = "ue.bypass.fuse"
|
const val bypassFusePermission = "ue.bypass.fuse"
|
||||||
// Permission string required to bypass enchantment conflicts test
|
// Permission string required to bypass enchantment conflicts test
|
||||||
const val bypassLevelPermission = "ue.bypass.level"
|
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
|
// Item Grouping Configuration file name
|
||||||
const val itemGroupingConfigFilePath = "item_groups.yml"
|
const val itemGroupingConfigFilePath = "item_groups.yml"
|
||||||
|
|
@ -60,10 +66,24 @@ class UnsafeEnchants : JavaPlugin() {
|
||||||
instance = this
|
instance = this
|
||||||
// Load bstats
|
// Load bstats
|
||||||
val metric = Metrics(this, bstatsPluginId)
|
val metric = Metrics(this, bstatsPluginId)
|
||||||
saveDefaultConfig()
|
|
||||||
|
|
||||||
|
reloadAllConfigs()
|
||||||
addCustomMetric(metric)
|
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
|
// Load material grouping config
|
||||||
val itemGroupConfig = reloadResource(itemGroupingConfigFilePath) ?: return
|
val itemGroupConfig = reloadResource(itemGroupingConfigFilePath) ?: return
|
||||||
// Read material groups from config
|
// Read material groups from config
|
||||||
|
|
@ -73,17 +93,15 @@ class UnsafeEnchants : JavaPlugin() {
|
||||||
// Load enchantment conflicts config
|
// Load enchantment conflicts config
|
||||||
val conflictConfig = reloadResource(enchantConflicConfigFilePath) ?: return
|
val conflictConfig = reloadResource(enchantConflicConfigFilePath) ?: return
|
||||||
// Read conflicts from config and material group manager
|
// Read conflicts from config and material group manager
|
||||||
conflictManager = EnchantConflictManager()
|
val conflictManager = EnchantConflictManager()
|
||||||
conflictManager.prepareConflicts(conflictConfig,itemGroupsManager)
|
conflictManager.prepareConflicts(conflictConfig,itemGroupsManager)
|
||||||
|
|
||||||
// Load unit repair config
|
// Load unit repair config
|
||||||
unitRepairConfig = reloadResource(unitRepairFilePath) ?: return
|
val unitRepairConfig = reloadResource(unitRepairFilePath) ?: return
|
||||||
|
|
||||||
server.pluginManager.registerEvents(
|
|
||||||
AnvilEventListener(),
|
|
||||||
this
|
|
||||||
)
|
|
||||||
|
|
||||||
|
// Set the global variable
|
||||||
|
UnsafeEnchants.conflictManager = conflictManager
|
||||||
|
UnsafeEnchants.unitRepairConfig = unitRepairConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addCustomMetric(metric: Metrics) {
|
private fun addCustomMetric(metric: Metrics) {
|
||||||
|
|
@ -96,6 +114,7 @@ class UnsafeEnchants : JavaPlugin() {
|
||||||
metric.addCustomChart(SimplePie("sacrifice_illegal_enchant_cost") {
|
metric.addCustomChart(SimplePie("sacrifice_illegal_enchant_cost") {
|
||||||
ConfigOptions.sacrificeIllegalCost.toString()
|
ConfigOptions.sacrificeIllegalCost.toString()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reloadResource(resourceName: String,
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,10 @@ load: POSTWORLD
|
||||||
authors: [DelilahEve, alexcrea]
|
authors: [DelilahEve, alexcrea]
|
||||||
libraries:
|
libraries:
|
||||||
- org.jetbrains.kotlin:kotlin-stdlib:1.6.21
|
- org.jetbrains.kotlin:kotlin-stdlib:1.6.21
|
||||||
|
commands:
|
||||||
|
reloadunsafeenchants:
|
||||||
|
description: Reload every config of this plugin
|
||||||
|
permission: ue.command.reload
|
||||||
permissions:
|
permissions:
|
||||||
ue.unsafe:
|
ue.unsafe:
|
||||||
default: true
|
default: true
|
||||||
|
|
@ -18,3 +22,6 @@ permissions:
|
||||||
ue.bypass.level:
|
ue.bypass.level:
|
||||||
default: false
|
default: false
|
||||||
description: Allow player to bypass max level limit
|
description: Allow player to bypass max level limit
|
||||||
|
ue.command.reload:
|
||||||
|
default: op
|
||||||
|
description: Allow administrator to reload the plugin's config
|
||||||
Loading…
Add table
Add a link
Reference in a new issue