mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
add config holder.
This commit is contained in:
parent
3afe786b38
commit
643487e1a9
9 changed files with 271 additions and 69 deletions
|
|
@ -23,6 +23,7 @@ import org.bukkit.inventory.AnvilInventory
|
|||
import org.bukkit.inventory.InventoryView.Property.REPAIR_COST
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.Repairable
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import kotlin.math.min
|
||||
|
|
@ -320,7 +321,7 @@ class AnvilEventListener : Listener {
|
|||
// count enchant as illegal enchant if it conflicts with another enchant or not in result
|
||||
if((enchantment.key !in resultEnchsKeys)){
|
||||
resultEnchsKeys.add(enchantment.key)
|
||||
val conflictType = CustomAnvil.conflictManager.isConflicting(resultEnchsKeys,result.type,enchantment.key)
|
||||
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(resultEnchsKeys,result.type,enchantment.key)
|
||||
resultEnchsKeys.remove(enchantment.key)
|
||||
|
||||
if(ConflictType.BIG_CONFLICT == conflictType){
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@ import org.bukkit.configuration.file.YamlConfiguration
|
|||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
||||
import xyz.alexcrea.cuanvil.command.TestExecutor
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.util.Metrics
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager
|
||||
import xyz.alexcrea.cuanvil.group.ItemGroupManager
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
|
@ -37,17 +36,8 @@ class CustomAnvil : JavaPlugin() {
|
|||
// Test command name
|
||||
const val commandTestName = "test"
|
||||
|
||||
// Item Grouping Configuration file name
|
||||
const val itemGroupingConfigFilePath = "item_groups.yml"
|
||||
// Conflict Configuration file name
|
||||
const val enchantConflicConfigFilePath = "enchant_conflict.yml"
|
||||
// Unit Repair Configuration file name
|
||||
const val unitRepairFilePath = "unit_repair_item.yml"
|
||||
|
||||
// Current plugin instance
|
||||
lateinit var instance: CustomAnvil
|
||||
// Current item grouping configuration instance
|
||||
lateinit var conflictManager: EnchantConflictManager
|
||||
|
||||
// Configuration for unit repair
|
||||
lateinit var unitRepairConfig: YamlConfiguration
|
||||
|
|
@ -76,7 +66,9 @@ class CustomAnvil : JavaPlugin() {
|
|||
logger.warning("Please note CustomAnvil is a more recent version of UnsafeEnchantsPlus")
|
||||
}
|
||||
|
||||
val success = reloadAllConfigs(true)
|
||||
// Load config
|
||||
|
||||
val success = ConfigHolder.loadConfig();
|
||||
if(!success) return
|
||||
|
||||
// Load metrics
|
||||
|
|
@ -92,36 +84,8 @@ class CustomAnvil : JavaPlugin() {
|
|||
)
|
||||
}
|
||||
|
||||
fun reloadAllConfigs(hardFailSafe: Boolean): Boolean{
|
||||
saveDefaultConfig()
|
||||
reloadConfig()
|
||||
|
||||
// Load material grouping config
|
||||
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, 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, hardFailSafe) ?: return false
|
||||
|
||||
// Set the global variable
|
||||
CustomAnvil.conflictManager = conflictManager
|
||||
CustomAnvil.unitRepairConfig = unitRepairConfig
|
||||
|
||||
// Test if is default config
|
||||
MetricsUtil.testIfConfigIsDefault(config, itemGroupConfig, conflictConfig, unitRepairConfig)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun reloadResource(resourceName: String,
|
||||
hardFailSafe:Boolean = true): YamlConfiguration?{
|
||||
fun reloadResource(resourceName: String,
|
||||
hardFailSafe:Boolean = true): YamlConfiguration?{
|
||||
// Save default resource
|
||||
val file = File(dataFolder,resourceName)
|
||||
if(!file.exists()){
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package io.delilaheve.util
|
|||
import io.delilaheve.CustomAnvil
|
||||
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
|
||||
/**
|
||||
* Config option accessors
|
||||
|
|
@ -71,7 +72,7 @@ object ConfigOptions {
|
|||
*/
|
||||
private val defaultEnchantLimit: Int
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getInt(DEFAULT_LIMIT_PATH, DEFAULT_ENCHANT_LIMIT)
|
||||
}
|
||||
|
|
@ -81,7 +82,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val limitRepairCost: Boolean
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getBoolean(LIMIT_REPAIR_COST, DEFAULT_LIMIT_REPAIR)
|
||||
}
|
||||
|
|
@ -91,7 +92,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val limitRepairValue: Int
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getInt(LIMIT_REPAIR_VALUE, DEFAULT_LIMIT_REPAIR_VALUE)
|
||||
.takeIf { it in REPAIR_LIMIT_RANGE }
|
||||
|
|
@ -103,7 +104,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val itemRepairCost: Int
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getInt(ITEM_REPAIR_COST, DEFAULT_ITEM_REPAIR_COST)
|
||||
.takeIf { it in REPAIR_COST_RANGE }
|
||||
|
|
@ -115,7 +116,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val unitRepairCost: Int
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getInt(UNIT_REPAIR_COST, DEFAULT_UNIT_REPAIR_COST)
|
||||
.takeIf { it in REPAIR_COST_RANGE }
|
||||
|
|
@ -127,7 +128,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val itemRenameCost: Int
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getInt(ITEM_RENAME_COST, DEFAULT_ITEM_RENAME_COST)
|
||||
.takeIf { it in ITEM_RENAME_COST_RANGE }
|
||||
|
|
@ -139,7 +140,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val sacrificeIllegalCost: Int
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getInt(SACRIFICE_ILLEGAL_COST, DEFAULT_SACRIFICE_ILLEGAL_COST)
|
||||
.takeIf { it in SACRIFICE_ILLEGAL_COST_RANGE }
|
||||
|
|
@ -150,7 +151,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val removeRepairLimit: Boolean
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getBoolean(REMOVE_REPAIR_LIMIT, DEFAULT_REMOVE_LIMIT)
|
||||
}
|
||||
|
|
@ -160,7 +161,7 @@ object ConfigOptions {
|
|||
*/
|
||||
val debugLog: Boolean
|
||||
get() {
|
||||
return CustomAnvil.instance
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getBoolean(DEBUG_LOGGING, DEFAULT_DEBUG_LOG)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil
|
|||
import org.bukkit.Material
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
|
@ -34,7 +35,7 @@ object EnchantmentUtil {
|
|||
// Add the enchantment if it doesn't have conflicts, or, if player is allowed to bypass enchantment restrictions
|
||||
this[enchantment] = level
|
||||
if(!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
||||
(CustomAnvil.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)){
|
||||
(ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)){
|
||||
this.remove(enchantment)
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ object EnchantmentUtil {
|
|||
// Enchantment already in result list
|
||||
else{
|
||||
// ... and they are conflicting
|
||||
if((CustomAnvil.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)
|
||||
if((ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)
|
||||
&& !player.hasPermission(CustomAnvil.bypassFusePermission)){
|
||||
return@forEach
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue