mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add enchant limit (#80)
This commit is contained in:
commit
78ce6a8f42
8 changed files with 102 additions and 10 deletions
|
|
@ -18,7 +18,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.13.1"
|
version = "1.14.0"
|
||||||
|
|
||||||
val effectiveVersion = "$version" +
|
val effectiveVersion = "$version" +
|
||||||
(if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "")
|
(if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "")
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,15 @@ disable-merge-over:
|
||||||
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
||||||
#minecraft:unbreaking: 2
|
#minecraft:unbreaking: 2
|
||||||
|
|
||||||
|
# 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
|
||||||
|
enchantment_count_limit:
|
||||||
|
default: -1
|
||||||
|
# Limit for specific items. example bellow is an example with stick
|
||||||
|
# Per item enchantment limit override eco enchant enchant_limit and default limit
|
||||||
|
items:
|
||||||
|
stick: -1
|
||||||
|
|
||||||
# Settings for lore modification
|
# Settings for lore modification
|
||||||
lore_edit:
|
lore_edit:
|
||||||
book_and_quil:
|
book_and_quil:
|
||||||
|
|
@ -318,7 +327,7 @@ lore_edit:
|
||||||
# Permission is ca.lore_edit.paper
|
# Permission is ca.lore_edit.paper
|
||||||
use_permission: true
|
use_permission: true
|
||||||
# what order should the lines should get added/removed (start/end, if invalid or not present will be end)
|
# what order should the lines should get added/removed (start/end, if invalid or not present will be end)
|
||||||
order: "end"
|
order: end
|
||||||
|
|
||||||
append_line:
|
append_line:
|
||||||
# If adding lore line using paper is enabled
|
# If adding lore line using paper is enabled
|
||||||
|
|
@ -338,6 +347,7 @@ lore_edit:
|
||||||
allow_color_code: true
|
allow_color_code: true
|
||||||
allow_hexadecimal_color: true
|
allow_hexadecimal_color: true
|
||||||
color_use_cost: 0
|
color_use_cost: 0
|
||||||
|
use_cost: 0
|
||||||
|
|
||||||
remove_line:
|
remove_line:
|
||||||
# If removing lore line using paper is enabled
|
# If removing lore line using paper is enabled
|
||||||
|
|
@ -367,4 +377,4 @@ debug_log_verbose: false
|
||||||
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
||||||
force_protocolib: false
|
force_protocolib: false
|
||||||
|
|
||||||
configVersion: 1.8.0
|
configVersion: 1.11.0
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,15 @@ disable-merge-over:
|
||||||
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
||||||
# minecraft:unbreaking: 2
|
# minecraft:unbreaking: 2
|
||||||
|
|
||||||
|
# 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
|
||||||
|
enchantment_count_limit:
|
||||||
|
default: -1
|
||||||
|
# Limit for specific items. example bellow is an example with stick
|
||||||
|
# Per item enchantment limit override eco enchant enchant_limit and default limit
|
||||||
|
items:
|
||||||
|
stick: -1
|
||||||
|
|
||||||
# Settings for lore modification
|
# Settings for lore modification
|
||||||
lore_edit:
|
lore_edit:
|
||||||
book_and_quil:
|
book_and_quil:
|
||||||
|
|
@ -318,7 +327,7 @@ lore_edit:
|
||||||
# Permission is ca.lore_edit.paper
|
# Permission is ca.lore_edit.paper
|
||||||
use_permission: true
|
use_permission: true
|
||||||
# what order should the lines should get added/removed (start/end, if invalid or not present will be end)
|
# what order should the lines should get added/removed (start/end, if invalid or not present will be end)
|
||||||
order: "end"
|
order: end
|
||||||
|
|
||||||
append_line:
|
append_line:
|
||||||
# If adding lore line using paper is enabled
|
# If adding lore line using paper is enabled
|
||||||
|
|
@ -338,6 +347,7 @@ lore_edit:
|
||||||
allow_color_code: true
|
allow_color_code: true
|
||||||
allow_hexadecimal_color: true
|
allow_hexadecimal_color: true
|
||||||
color_use_cost: 0
|
color_use_cost: 0
|
||||||
|
use_cost: 0
|
||||||
|
|
||||||
remove_line:
|
remove_line:
|
||||||
# If removing lore line using paper is enabled
|
# If removing lore line using paper is enabled
|
||||||
|
|
@ -367,4 +377,4 @@ debug_log_verbose: false
|
||||||
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
||||||
force_protocolib: false
|
force_protocolib: false
|
||||||
|
|
||||||
configVersion: 1.8.0
|
configVersion: 1.11.0
|
||||||
|
|
@ -52,8 +52,8 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
// Command Name to reload the config
|
// Command Name to reload the config
|
||||||
const val commandReloadName = "anvilconfigreload"
|
const val commandReloadName = "anvilconfigreload"
|
||||||
|
|
||||||
// Test command name
|
// Config command name
|
||||||
const val commandTestName = "customanvilconfig"
|
const val commandConfigName = "customanvilconfig"
|
||||||
|
|
||||||
// Current plugin instance
|
// Current plugin instance
|
||||||
lateinit var instance: CustomAnvil
|
lateinit var instance: CustomAnvil
|
||||||
|
|
@ -208,7 +208,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
var command = getCommand(commandReloadName)
|
var command = getCommand(commandReloadName)
|
||||||
command?.setExecutor(ReloadExecutor())
|
command?.setExecutor(ReloadExecutor())
|
||||||
|
|
||||||
command = getCommand(commandTestName)
|
command = getCommand(commandConfigName)
|
||||||
command?.setExecutor(EditConfigExecutor())
|
command?.setExecutor(EditConfigExecutor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,42 @@ 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 != null) 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.${type.key.key.lowercase()}", DEFAULT_ENCHANT_COUNT_LIMIT)
|
||||||
|
.takeIf { it in ENCHANT_COUNT_LIMIT_RANGE }
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
@ -33,6 +34,9 @@ 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)
|
||||||
|
|
||||||
|
var maxEnchantCount = ConfigOptions.getEnchantCountLimit(item.type)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
@ -45,6 +49,9 @@ object EnchantmentUtil {
|
||||||
|
|
||||||
// Enchantment not yet in result list
|
// Enchantment not yet in result list
|
||||||
if (!containsKey(enchantment)) {
|
if (!containsKey(enchantment)) {
|
||||||
|
// Do not allow new enchantment if above maximum
|
||||||
|
if(this.size >= maxEnchantCount) return@forEach
|
||||||
|
|
||||||
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
||||||
this[enchantment] = cappedLevel
|
this[enchantment] = cappedLevel
|
||||||
if(bypassFuse){
|
if(bypassFuse){
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package xyz.alexcrea.cuanvil.dependency.plugins
|
package xyz.alexcrea.cuanvil.dependency.plugins
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.ecoenchants.enchant.EcoEnchant
|
import com.willfp.ecoenchants.enchant.EcoEnchant
|
||||||
import com.willfp.ecoenchants.enchant.EcoEnchants
|
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||||
|
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||||
import org.bukkit.plugin.Plugin
|
import org.bukkit.plugin.Plugin
|
||||||
|
|
@ -32,6 +34,10 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun getEcoLevelLimit(): Int {
|
||||||
|
return (ecoEnchantPlugin as EcoPlugin).configYml.getInt("anvil.enchant-limit").infiniteIfNegative()
|
||||||
|
}
|
||||||
|
|
||||||
fun disableAnvilListener() {
|
fun disableAnvilListener() {
|
||||||
PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin)
|
PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,15 @@ disable-merge-over:
|
||||||
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
||||||
#minecraft:unbreaking: 2
|
#minecraft:unbreaking: 2
|
||||||
|
|
||||||
|
# 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
|
||||||
|
enchantment_count_limit:
|
||||||
|
default: -1
|
||||||
|
# Limit for specific items. example bellow is an example with stick
|
||||||
|
# Per item enchantment limit override eco enchant enchant_limit and default limit
|
||||||
|
items:
|
||||||
|
stick: -1
|
||||||
|
|
||||||
# Settings for lore modification
|
# Settings for lore modification
|
||||||
lore_edit:
|
lore_edit:
|
||||||
book_and_quil:
|
book_and_quil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue