mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add per item enchant count limit
This commit is contained in:
parent
b095cd5316
commit
65d6af7672
3 changed files with 54 additions and 4 deletions
|
|
@ -2,10 +2,12 @@ package io.delilaheve.util
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
||||||
|
import org.bukkit.Material
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType
|
import xyz.alexcrea.cuanvil.config.WorkPenaltyType
|
||||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart
|
import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart
|
||||||
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
@ -46,6 +48,11 @@ object ConfigOptions {
|
||||||
const val EXCLUSIVE_WORK_PENALTY_INCREASE = "exclusive_increase"
|
const val EXCLUSIVE_WORK_PENALTY_INCREASE = "exclusive_increase"
|
||||||
const val EXCLUSIVE_WORK_PENALTY_ADDITIVE = "exclusive_additive"
|
const val EXCLUSIVE_WORK_PENALTY_ADDITIVE = "exclusive_additive"
|
||||||
|
|
||||||
|
// Enchant limit config
|
||||||
|
const val ENCHANT_COUNT_LIMIT_ROOT = "enchantment_count_limit"
|
||||||
|
const val ENCHANT_COUNT_LIMIT_DEFAULT = "$ENCHANT_COUNT_LIMIT_ROOT.default"
|
||||||
|
const val ENCHANT_COUNT_LIMIT_ITEMS = "$ENCHANT_COUNT_LIMIT_ROOT.items"
|
||||||
|
|
||||||
const val DEFAULT_LIMIT_PATH = "default_limit"
|
const val DEFAULT_LIMIT_PATH = "default_limit"
|
||||||
|
|
||||||
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||||
|
|
@ -55,6 +62,7 @@ object ConfigOptions {
|
||||||
|
|
||||||
const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments"
|
const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments"
|
||||||
|
|
||||||
|
|
||||||
// Keys for specific enchantment values
|
// Keys for specific enchantment values
|
||||||
private const val KEY_BOOK = "book"
|
private const val KEY_BOOK = "book"
|
||||||
private const val KEY_ITEM = "item"
|
private const val KEY_ITEM = "item"
|
||||||
|
|
@ -81,6 +89,8 @@ object ConfigOptions {
|
||||||
const val DEFAULT_SACRIFICE_ILLEGAL_COST = 1
|
const val DEFAULT_SACRIFICE_ILLEGAL_COST = 1
|
||||||
const val DEFAULT_ADD_BOOK_ENCHANTMENT_AS_STORED_ENCHANTMENT = false;
|
const val DEFAULT_ADD_BOOK_ENCHANTMENT_AS_STORED_ENCHANTMENT = false;
|
||||||
|
|
||||||
|
const val DEFAULT_ENCHANT_COUNT_LIMIT = -1
|
||||||
|
|
||||||
// Color related config
|
// Color related config
|
||||||
const val DEFAULT_ALLOW_COLOR_CODE = false
|
const val DEFAULT_ALLOW_COLOR_CODE = false
|
||||||
const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false
|
const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false
|
||||||
|
|
@ -121,6 +131,10 @@ object ConfigOptions {
|
||||||
@JvmField
|
@JvmField
|
||||||
val ENCHANT_LIMIT_RANGE = 1..255
|
val ENCHANT_LIMIT_RANGE = 1..255
|
||||||
|
|
||||||
|
// Valid range for an enchantment count limit
|
||||||
|
@JvmField
|
||||||
|
val ENCHANT_COUNT_LIMIT_RANGE = -1..255
|
||||||
|
|
||||||
// --------------
|
// --------------
|
||||||
// Other defaults
|
// Other defaults
|
||||||
// --------------
|
// --------------
|
||||||
|
|
@ -329,6 +343,43 @@ object ConfigOptions {
|
||||||
.getInt(DEFAULT_LIMIT_PATH, DEFAULT_ENCHANT_LIMIT)
|
.getInt(DEFAULT_LIMIT_PATH, DEFAULT_ENCHANT_LIMIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get material enchantment count limit
|
||||||
|
*
|
||||||
|
* @return the current enchantment limit. -1 if none
|
||||||
|
*/
|
||||||
|
fun getEnchantCountLimit(type: Material): Int? {
|
||||||
|
val limit = materialEnchantCountLimit(type)
|
||||||
|
|
||||||
|
if(limit >= 0) return limit
|
||||||
|
if(defaultEnchantCountLimit >= 0) return defaultEnchantCountLimit
|
||||||
|
|
||||||
|
return DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the material enchantment count limit.
|
||||||
|
*
|
||||||
|
* @return The current enchantment limit. -1 if none
|
||||||
|
*/
|
||||||
|
private fun materialEnchantCountLimit(type: Material): Int {
|
||||||
|
return ConfigHolder.DEFAULT_CONFIG.config
|
||||||
|
.getInt(ENCHANT_COUNT_LIMIT_ITEMS, DEFAULT_ENCHANT_COUNT_LIMIT)
|
||||||
|
.takeIf { it in ENCHANT_COUNT_LIMIT_RANGE }
|
||||||
|
?: DEFAULT_ENCHANT_COUNT_LIMIT
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* User configured default enchantment count limit
|
||||||
|
*/
|
||||||
|
val defaultEnchantCountLimit: Int
|
||||||
|
get() {
|
||||||
|
return ConfigHolder.DEFAULT_CONFIG
|
||||||
|
.config
|
||||||
|
.getInt(ENCHANT_COUNT_LIMIT_DEFAULT, DEFAULT_ENCHANT_COUNT_LIMIT)
|
||||||
|
.takeIf { it in ENCHANT_COUNT_LIMIT_RANGE }
|
||||||
|
?: DEFAULT_ENCHANT_COUNT_LIMIT
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to show debug logging
|
* Whether to show debug logging
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,8 @@ object EnchantmentUtil {
|
||||||
val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission)
|
val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission)
|
||||||
val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission)
|
val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission)
|
||||||
|
|
||||||
// TODO add custom anvil maximum enchant count per item and globally too
|
var maxEnchantCount = ConfigOptions.getEnchantCountLimit(item.type)
|
||||||
var maxEnchantCount = DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit()
|
if(maxEnchantCount == null || maxEnchantCount < 0) maxEnchantCount = Int.MAX_VALUE
|
||||||
if(maxEnchantCount == null || maxEnchantCount < 0) maxEnchantCount = Int.MAX_VALUE;
|
|
||||||
|
|
||||||
other.forEach { (enchantment, level) ->
|
other.forEach { (enchantment, level) ->
|
||||||
if(!enchantment.isAllowed(player)) return@forEach
|
if(!enchantment.isAllowed(player)) return@forEach
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ disable-merge-over:
|
||||||
|
|
||||||
# The maximum number of enchantment an item can get. -1 for infinity
|
# The maximum number of enchantment an item can get. -1 for infinity
|
||||||
# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1
|
# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1
|
||||||
enchantment_limit:
|
enchantment_count_limit:
|
||||||
default: -1
|
default: -1
|
||||||
# Limit for specific items. example bellow is an example with stick
|
# Limit for specific items. example bellow is an example with stick
|
||||||
# Per item enchantment limit override eco enchant enchant_limit and default limit
|
# Per item enchantment limit override eco enchant enchant_limit and default limit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue