add config holder.

This commit is contained in:
alexcrea 2024-02-29 16:34:52 +01:00 committed by alexcrea
parent 3afe786b38
commit 643487e1a9
9 changed files with 271 additions and 69 deletions

View file

@ -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)
}

View file

@ -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
}