mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add default for eco enchant enchantments.
This commit is contained in:
parent
1e15bc7ab3
commit
a4dda06602
4 changed files with 57 additions and 4 deletions
|
|
@ -108,7 +108,7 @@ class CustomAnvil : JavaPlugin() {
|
|||
Update_1_21.handleUpdate()
|
||||
|
||||
// Handle custom enchant config
|
||||
DependencyManager.handleConfigChanges()
|
||||
DependencyManager.handleConfigChanges(this)
|
||||
|
||||
// Load gui constants //TODO maybe something better later
|
||||
MainConfigGui.getInstance().init(DependencyManager.packetManager)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package xyz.alexcrea.cuanvil.dependency
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.Plugin
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.NoProtocoLib
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.ProtocoLibWrapper
|
||||
import java.io.File
|
||||
|
||||
object DependencyManager {
|
||||
|
||||
|
|
@ -33,9 +35,11 @@ object DependencyManager {
|
|||
|
||||
}
|
||||
|
||||
fun handleConfigChanges() {
|
||||
fun handleConfigChanges(plugin: Plugin) {
|
||||
val folder = File(plugin.dataFolder, "compatibility")
|
||||
|
||||
enchantmentSquaredCompatibility?.registerPluginConfiguration()
|
||||
ecoEnchantCompatibility?.registerEnchantments()
|
||||
ecoEnchantCompatibility?.registerPluginConfiguration(folder)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,14 @@ package xyz.alexcrea.cuanvil.dependency
|
|||
|
||||
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import org.bukkit.plugin.Plugin
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEcoEnchant
|
||||
import java.io.File
|
||||
|
||||
class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
|
||||
|
||||
|
|
@ -23,9 +26,52 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
|
|||
for (ecoEnchant in EcoEnchants.values()) {
|
||||
val enchantments: CAEnchantment = CAEcoEnchant(ecoEnchant)
|
||||
|
||||
registery.unregister(registery.getByKey(ecoEnchant.enchantment.key)) // As
|
||||
registery.unregister(registery.getByKey(ecoEnchant.enchantment.key)) // As eco enchants are considered real enchantment, we need to unregister it.
|
||||
registery.register(enchantments)
|
||||
}
|
||||
}
|
||||
|
||||
fun registerPluginConfiguration(folder: File){
|
||||
val compatibilityFile = File(folder, "ecoEnchant.yml")
|
||||
|
||||
if(compatibilityFile.exists()){
|
||||
compatibilityFile.createNewFile()
|
||||
}
|
||||
|
||||
val config = YamlConfiguration.loadConfiguration(compatibilityFile)
|
||||
val defaultConfig = ConfigHolder.DEFAULT_CONFIG.config
|
||||
var doSave = false
|
||||
|
||||
for (ecoEnchant in EcoEnchants.values()) {
|
||||
val enchantment = CAEnchantmentRegistry.getInstance().getByKey(ecoEnchant.enchantmentKey)
|
||||
|
||||
if(enchantment == null){
|
||||
CustomAnvil.instance.logger.warning("Could not find " + ecoEnchant.enchantmentKey + "testing compatibility.")
|
||||
continue
|
||||
}
|
||||
|
||||
// Write enchantment value if needed
|
||||
val testPath = "default.${enchantment.key.key}"
|
||||
if(!config.getBoolean(testPath, false)){
|
||||
doSave = true
|
||||
config[testPath] = true
|
||||
|
||||
defaultConfig["enchant_limits.${enchantment.key.key}"] = enchantment.defaultMaxLevel()
|
||||
|
||||
val rarity = enchantment.defaultRarity()
|
||||
defaultConfig["enchant_values.${enchantment.key.key}.item"] = rarity.itemValue
|
||||
defaultConfig["enchant_values.${enchantment.key.key}.book"] = rarity.bookValue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(doSave){
|
||||
config.save(compatibilityFile)
|
||||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true)
|
||||
|
||||
CustomAnvil.instance.logger.info("Saved default for new eco enchant enchantments.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue