Compare commits

..

6 commits

Author SHA1 Message Date
eb40383068
prepare for v2 2026-06-22 03:44:18 +02:00
c1d67a3821
rebase on new update 2026-06-22 03:21:14 +02:00
f97e3c937d
1.21 cleanup and fix
also random cleanup
2026-06-22 03:21:14 +02:00
2241fbd720
fix from rebase 2026-06-22 03:21:13 +02:00
ef5585fd42
progress on 1.21 transition 2026-06-22 03:21:07 +02:00
922a7a0ed1
initial 1.21 transition 2026-06-22 03:18:00 +02:00
20 changed files with 99 additions and 400 deletions

View file

@ -119,9 +119,6 @@ permission_needed_for_dialog_rename: false
# For practical reason. this only work when dialog rename is enabled
dialog_rename_keep_user_text: true
# Also count left item enchantments for the final price
include_left_enchantment_for_cost: false
# Override limits for specific enchants
#
# Enchantments not listed here will use the value of default_limit
@ -178,8 +175,8 @@ enchant_limits:
# Multipliers used to calculate the enchantment's value in repair/combining
#
# Values here are pulled from the minecraft wiki:
# https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments
# Values here are pulled from the fandom wiki:
# https://minecraft.fandom.com/wiki/Anvil_mechanics#Costs_for_combining_enchantments
#
# If an enchantment is missing values here, or is less than 0, it will default to 0
#
@ -486,8 +483,5 @@ debug_log: false
# Whether to show verbose debug logging
debug_log_verbose: false
# Whether to show inside the console or require to run /ca debug get
display_debug_in_console: false
configVersion: 1.15.5
lowMinecraftVersion: 1.21.11

View file

@ -117,9 +117,6 @@ permission_needed_for_dialog_rename: false
# For practical reason. this only work when dialog rename is enabled
dialog_rename_keep_user_text: true
# Also count left item enchantments for the final price
include_left_enchantment_for_cost: false
# Override limits for specific enchants
#
# Enchantments not listed here will use the value of default_limit
@ -175,8 +172,8 @@ enchant_limits:
# Multipliers used to calculate the enchantment's value in repair/combining
#
# Values here are pulled from the minecraft wiki:
# https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments
# Values here are pulled from the fandom wiki:
# https://minecraft.fandom.com/wiki/Anvil_mechanics#Costs_for_combining_enchantments
#
# If an enchantment is missing values here, or is less than 0, it will default to 0
#
@ -478,8 +475,5 @@ debug_log: false
# Whether to show verbose debug logging
debug_log_verbose: false
# Whether to show inside the console or require to run /ca debug get
display_debug_in_console: false
configVersion: 1.11.0
lowMinecraftVersion: 1.21.9

View file

@ -117,9 +117,6 @@ permission_needed_for_dialog_rename: false
# For practical reason. this only work when dialog rename is enabled
dialog_rename_keep_user_text: true
# Also count left item enchantments for the final price
include_left_enchantment_for_cost: false
# Override limits for specific enchants
#
# Enchantments not listed here will use the value of default_limit
@ -172,8 +169,8 @@ enchant_limits:
# Multipliers used to calculate the enchantment's value in repair/combining
#
# Values here are pulled from the minecraft wiki:
# https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments
# Values here are pulled from the fandom wiki:
# https://minecraft.fandom.com/wiki/Anvil_mechanics#Costs_for_combining_enchantments
#
# If an enchantment is missing values here, or is less than 0, it will default to 0
#
@ -466,7 +463,4 @@ debug_log: false
# Whether to show verbose debug logging
debug_log_verbose: false
# Whether to show inside the console or require to run /ca debug get
display_debug_in_console: false
configVersion: 1.11.0

View file

@ -5,7 +5,6 @@ import io.delilaheve.util.ConfigOptions;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
@ -144,7 +143,6 @@ public class EnchantmentApi {
/**
* Get every registered custom anvil enchantments.
*
* @return An immutable map of enchantment key as map key and custom anvil enchantment as value.
*/
@NotNull
@ -154,7 +152,6 @@ public class EnchantmentApi {
/**
* Write the default level and rarity configuration of the enchantment.
*
* @param enchantment The enchantment to write default configuration
* @param override If it should override old configuration
* @return Return false if override is false and a configuration exist. true otherwise.
@ -207,10 +204,7 @@ public class EnchantmentApi {
}
/**
* Add a bulk get operator. (not needed for proper "bukkit" enchantments)
* <p>
* Do not forget to mark your enchantments as {@link CAEnchantment#isGetOptimised() Get Optimized}
*
* Add a bulk get operator.
* @param operation An optimised get enchantments operation
*/
public static void addBulkGet(@NotNull BulkGetEnchantOperation operation){
@ -219,60 +213,10 @@ public class EnchantmentApi {
/**
* Add a bulk clean operator.
*
* @param operation An optimised clean enchantments operation (not needed for proper "bukkit" enchantments)
* <p>
* Do not forget to mark your enchantments as {@link CAEnchantment#isCleanOptimised() Clean Optimized}
* @param operation An optimised clean enchantments operation
*/
public static void addBulkClean(@NotNull BulkCleanEnchantOperation operation){
CAEnchantmentRegistry.getInstance().getOptimisedCleanOperators().add(operation);
}
/**
* Get all the enchantments of an item
*
* @param item The item to get the enchantment from
* @return A map of key of enchantment, value the level of all the enchantments of the item
* @since 1.17.6
*/
public static Map<CAEnchantment, Integer> getEnchantments(@NotNull ItemStack item) {
return CAEnchantment.getEnchants(item);
}
/**
* Set all the enchantments to an item. Clearing previous enchantments
*
* @param item The item to get the enchantment from
* @param enchants A map of key of enchantment, value the level of all the enchantments
* @since 1.17.6
*/
public static void setEnchantments(@NotNull ItemStack item, @NotNull Map<CAEnchantment, Integer> enchants) {
clearEnchantments(item);
addEnchantments(item, enchants);
}
/**
* Add enchantment with there respective level.
* If the enchantment is already present it will be overridden to the new level
*
* @param item The item to get the enchantment from
* @param enchants A map of key of enchantment, value the level of the new enchantments
* @since 1.17.6
*/
public static void addEnchantments(@NotNull ItemStack item, @NotNull Map<CAEnchantment, Integer> enchants) {
enchants.forEach((enchantment, level) ->
enchantment.addEnchantmentUnsafe(item, level)
);
}
/**
* Clear all the enchantments
*
* @param item The item to clear the enchantments from
* @since 1.17.6
*/
public static void clearEnchantments(@NotNull ItemStack item) {
CAEnchantment.clearEnchants(item);
}
}

View file

@ -41,7 +41,7 @@ public class SuperEnchantBulkOperation implements BulkGetEnchantOperation, BulkC
@Override
public void bulkClear(@NotNull ItemStack item, @NotNull ItemMeta meta) {
// item meta is not preferred for super enchant
// item meta is not preferred for enchantment squared clear
}
}

View file

@ -73,14 +73,4 @@ public class CASuperEnchantEnchantment extends CAEnchantmentBase implements Addi
return !enchant.canApplyTo(item.getType());
}
@Override
public boolean isCleanOptimised() {
return true;
}
@Override
public boolean isGetOptimised() {
return true;
}
}

View file

@ -66,12 +66,6 @@ public class PluginSetDefault {
nbSet += trySetDefault(config, DIALOG_RENAME_USE_PERMISSION, DEFAULT_DIALOG_RENAME_USE_PERMISSION);
nbSet += trySetDefault(config, DIALOG_KEEP_USER_TEXT, DEFAULT_DIALOG_KEEP_USER_TEXT);
nbSet += trySetDefault(config, INCLUDE_LEFT_ENCHANTMENT_FOR_COST, DEFAULT_INCLUDE_LEFT_ENCHANTMENT_FOR_COST);
nbSet += trySetDefault(config, DEBUG_LOGGING, DEFAULT_DEBUG_LOG);
nbSet += trySetDefault(config, VERBOSE_DEBUG_LOGGING, DEFAULT_VERBOSE_DEBUG_LOG);
nbSet += trySetDefault(config, SHOW_CONSOLE_DEBUG_LOGGING, DEFAULT_SHOW_CONSOLE_DEBUG_LOGGING);
if (nbSet > 0) {
CustomAnvil.instance.getLogger().info("Adding " + nbSet + " absent default config values.");
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);

View file

@ -71,37 +71,21 @@ open class CustomAnvil : JavaPlugin() {
var latestVer: String? = null
// Debug
val debugStorageQueue = ArrayDeque<String>()
private fun addToLogQueue(message: String) {
if(debugStorageQueue.size >= 200) {
// Let not store infinite debug logs
debugStorageQueue.removeFirst()
}
debugStorageQueue.addLast(message)
}
/**
* Logging handler
*/
@JvmStatic fun log(message: String) {
if (ConfigOptions.debugLog) {
if(ConfigOptions.showDebugLogInConsole)
instance.logger.info(message)
addToLogQueue(message)
}
}
/**
* Vebose Logging handler
*/
@JvmStatic fun verboseLog(message: String) {
fun verboseLog(message: String) {
if (ConfigOptions.verboseDebugLog) {
if(ConfigOptions.showDebugLogInConsole)
instance.logger.info(message)
addToLogQueue(message)
}
}

View file

@ -76,8 +76,6 @@ object ConfigOptions {
const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments"
const val INCLUDE_LEFT_ENCHANTMENT_FOR_COST = "include_left_enchantment_for_cost"
// Monetary configs
const val MONETARY_USAGE_ROOT = "monetary_cost"
const val SHOULD_USE_MONEY = "$MONETARY_USAGE_ROOT.enabled"
@ -91,7 +89,6 @@ object ConfigOptions {
// Debug flag
const val DEBUG_LOGGING = "debug_log"
const val VERBOSE_DEBUG_LOGGING = "debug_log_verbose"
const val SHOW_CONSOLE_DEBUG_LOGGING = "display_debug_in_console"
// ----------------------
// Default config values
@ -113,8 +110,6 @@ object ConfigOptions {
const val DEFAULT_ENCHANT_COUNT_LIMIT = -1
const val DEFAULT_INCLUDE_LEFT_ENCHANTMENT_FOR_COST = false
// Color related config
const val DEFAULT_ALLOW_COLOR_CODE = false
const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false
@ -130,12 +125,8 @@ object ConfigOptions {
const val DEFAULT_MONEY_MULTIPLIER = 1.0
// Debug flag
const val DEFAULT_DEBUG_LOG = false
const val DEFAULT_VERBOSE_DEBUG_LOG = false
const val DEFAULT_SHOW_CONSOLE_DEBUG_LOGGING = false
var OVERRIDE_DEBUG_LOG: Boolean? = null
var OVERRIDE_VERBOSE_DEBUG_LOG: Boolean? = null
private const val DEFAULT_DEBUG_LOG = false
private const val DEFAULT_VERBOSE_DEBUG_LOG = false
// Dialog menu rename
const val DEFAULT_DIALOG_RENAME_ENABLED = false
@ -440,21 +431,11 @@ object ConfigOptions {
?: DEFAULT_ENCHANT_COUNT_LIMIT
}
val includeLeftEnchantmentForCost: Boolean
get() {
return ConfigHolder.DEFAULT_CONFIG
.config
.getBoolean(INCLUDE_LEFT_ENCHANTMENT_FOR_COST, DEFAULT_INCLUDE_LEFT_ENCHANTMENT_FOR_COST)
}
/**
* Whether to show debug logging
*/
val debugLog: Boolean
get() {
val overrider = OVERRIDE_DEBUG_LOG
if(overrider != null) return overrider
return ConfigHolder.DEFAULT_CONFIG
.config
.getBoolean(DEBUG_LOGGING, DEFAULT_DEBUG_LOG)
@ -465,27 +446,11 @@ object ConfigOptions {
*/
val verboseDebugLog: Boolean
get() {
val overrider = OVERRIDE_VERBOSE_DEBUG_LOG
if(overrider != null) return overrider
return ConfigHolder.DEFAULT_CONFIG
.config
.getBoolean(VERBOSE_DEBUG_LOGGING, DEFAULT_VERBOSE_DEBUG_LOG)
}
/**
* Whether to show debug in console
*/
val showDebugLogInConsole: Boolean
get() {
val overrider = OVERRIDE_VERBOSE_DEBUG_LOG
if(overrider != null) return overrider
return ConfigHolder.DEFAULT_CONFIG
.config
.getBoolean(SHOW_CONSOLE_DEBUG_LOGGING, DEFAULT_SHOW_CONSOLE_DEBUG_LOGGING)
}
/**
* Is the dialog menu for rename enabled
*/

View file

@ -19,6 +19,23 @@ object ItemUtil {
*/
fun ItemStack.isEnchantedBook() = type == ENCHANTED_BOOK
/**
* Find the enchantment map for this [ItemStack] and return it as a [MutableMap]
*/
fun ItemStack.findEnchantments(): MutableMap<CAEnchantment, Int> = CAEnchantment.getEnchants(this)
/**
* Apply an [enchantments] map to this [ItemStack]
*/
fun ItemStack.setEnchantmentsUnsafe(enchantments: Map<CAEnchantment, Int>) {
CAEnchantment.clearEnchants(this)
enchantments.forEach { (enchantment, level) ->
enchantment.addEnchantmentUnsafe(this, level)
}
}
/**
* Set this [ItemStack]s durability from a combination of the
* [first] and [second] item's durability values

View file

@ -3,8 +3,10 @@ package xyz.alexcrea.cuanvil.anvil
import io.delilaheve.CustomAnvil
import io.delilaheve.util.ConfigOptions
import io.delilaheve.util.EnchantmentUtil.combineWith
import io.delilaheve.util.ItemUtil.findEnchantments
import io.delilaheve.util.ItemUtil.isEnchantedBook
import io.delilaheve.util.ItemUtil.repairFrom
import io.delilaheve.util.ItemUtil.setEnchantmentsUnsafe
import io.delilaheve.util.ItemUtil.unitRepair
import org.bukkit.ChatColor
import org.bukkit.Material
@ -14,7 +16,6 @@ import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta
import org.bukkit.inventory.view.AnvilView
import org.bukkit.persistence.PersistentDataType
import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.dialog.AnvilRenameDialog
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
@ -186,21 +187,16 @@ object AnvilMergeLogic {
player: Player,
first: ItemStack, second: ItemStack
): AnvilResult {
val firstEnchants = EnchantmentApi.getEnchantments(first)
val secondEnchants = EnchantmentApi.getEnchantments(second)
// newEnchants will be mutated by combineWith
val newEnchants = HashMap(firstEnchants)
newEnchants.combineWith(secondEnchants, first, player)
var hasChanged = !isIdentical(firstEnchants, newEnchants)
val newEnchants = first.findEnchantments()
.combineWith(second.findEnchantments(), first, player)
var hasChanged = !isIdentical(first.findEnchantments(), newEnchants)
val resultItem = DependencyManager.cloneItem(player, first)
val cost = AnvilCost()
if (hasChanged) {
EnchantmentApi.setEnchantments(resultItem, newEnchants)
resultItem.setEnchantmentsUnsafe(newEnchants)
// Calculate enchantment cost
AnvilXpUtil.getRightValues(first, second, resultItem, cost)
AnvilXpUtil.getRightValues(second, resultItem, cost)
}
// Calculate repair cost

View file

@ -21,7 +21,6 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
"gui", editConfigCommand,
"reload", ReloadExecutor(),
"diagnostic", DiagnosticExecutor(),
"debug", DebugToggleExecutor(),
"help", helpCommand,
)

View file

@ -1,119 +0,0 @@
package xyz.alexcrea.cuanvil.command
import io.delilaheve.CustomAnvil
import io.delilaheve.util.ConfigOptions
import net.md_5.bungee.api.chat.ClickEvent
import net.md_5.bungee.api.chat.HoverEvent
import net.md_5.bungee.api.chat.TextComponent
import net.md_5.bungee.api.chat.hover.content.Text
import org.bukkit.ChatColor
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import xyz.alexcrea.cuanvil.command.DiagnosticExecutor.Companion.NO_DIAG_PERM
class DebugToggleExecutor : CASubCommand() {
override fun description(): String {
return "Used to toggle debug logs and retrieve it"
}
override fun allowed(sender: CommandSender): Boolean {
return sender.hasPermission(CustomAnvil.diagnosticPermission)
}
override fun executeCommand(
sender: CommandSender,
cmd: Command,
cmdstr: String,
args: Array<out String>
): Boolean {
if (!allowed(sender)) {
sender.sendMessage(NO_DIAG_PERM)
return false
}
if (args.isEmpty()) {
sender.sendMessage("Need to specify a subcommand: \"toggle\" or \"get\"")
return true
}
when (args[0].lowercase()) {
"toggle" -> executeToggle(sender, args)
"get" -> executeGet(sender)
"get-and-clear" -> {
executeGet(sender)
CustomAnvil.debugStorageQueue.clear()
}
"clear" -> {
CustomAnvil.debugStorageQueue.clear()
sender.sendMessage("Log Cleared")
}
else -> return false
}
return true
}
private fun executeToggle(sender: CommandSender, args: Array<out String>) {
if (args.size < 2) {
sender.sendMessage("Need to specify which type of debug to toggle: \"default\" or \"verbose\"")
return
}
when (args[1].lowercase()) {
"default" -> {
ConfigOptions.OVERRIDE_DEBUG_LOG = !ConfigOptions.debugLog
sender.sendMessage("Debug toggle to: ${ConfigOptions.debugLog}")
}
"verbose" -> {
ConfigOptions.OVERRIDE_VERBOSE_DEBUG_LOG = !ConfigOptions.verboseDebugLog
sender.sendMessage("Debug toggle to: ${ConfigOptions.verboseDebugLog}")
}
else -> sender.sendMessage("Invalid debug type: ${args[1]}")
}
}
private fun executeGet(sender: CommandSender) {
val stb = StringBuilder("Debug Log data:")
if (CustomAnvil.debugStorageQueue.isEmpty()) {
sender.sendMessage("No log to show ? make sure you tried with debug log toggled (/ca debug toggle)")
return
}
stb.append("\nFound ${CustomAnvil.debugStorageQueue.size} lines\n")
for (log in CustomAnvil.debugStorageQueue) {
stb.append('\n').append(log)
}
if (sender is Player) {
val message = TextComponent(ChatColor.GREEN.toString() + "Click to copy log data")
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("§7Click to copy"))
sender.spigot().sendMessage(message);
} else {
sender.sendMessage(stb.toString())
}
}
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
if (!allowed(sender)) return
list.addAll(
when (args.size) {
1 -> listOf("toggle", "get", "get-and-clear", "clear")
2 -> when (args[0].lowercase()) {
"toggle" -> listOf("default", "verbose")
else -> listOf()
}
else -> listOf()
}
)
}
}

View file

@ -34,7 +34,7 @@ import java.util.stream.Collectors
class DiagnosticExecutor : CASubCommand() {
companion object {
const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
private const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
fun fetchNMSType(): String {
val packetManager = DependencyManager.packetManager

View file

@ -5,7 +5,6 @@ import org.bukkit.NamespacedKey
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemStack
import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
@ -263,8 +262,7 @@ class EnchantConflictManager {
}
if ((result != ConflictType.ITEM_CONFLICT) && (newEnchant is AdditionalTestEnchantment)) {
val partialItem = item.clone()
EnchantmentApi.setEnchantments(partialItem, immutableEnchants)
val partialItem = createPartialResult(item, immutableEnchants)
if (newEnchant.isItemConflict(immutableEnchants, type, partialItem)) {
return ConflictType.ITEM_CONFLICT
@ -275,6 +273,17 @@ class EnchantConflictManager {
return result
}
private fun createPartialResult(item: ItemStack, enchantments: Map<CAEnchantment, Int>): ItemStack {
val newItem = item.clone()
CAEnchantment.clearEnchants(newItem)
enchantments.forEach { enchantment ->
enchantment.key.addEnchantmentUnsafe(newItem, enchantment.value)
}
return newItem
}
}
/**

View file

@ -106,17 +106,12 @@ class AnvilResultListener : Listener {
if (canMerge) {
val result = AnvilMergeLogic.doMerge(view, player, leftItem, rightItem)
val worked = extractAnvilResult(
extractAnvilResult(
event, player, view,
null, 0,
null, 0,
result
)
if(!worked) {
CustomAnvil.verboseLog("Merge extract failed. reset the displayed price")
// Reset the price
AnvilXpUtil.setAnvilResult(inventory, view, player, result)
}
return
}
@ -276,20 +271,11 @@ class AnvilResultListener : Listener {
val cost = result.cost
if (cost.isMonetary) {
val result = EconomyManager.economy!!.remove(player, cost.asMonetaryCost())
if (!result) {
CustomAnvil.verboseLog("Could not remove monetary cost ${cost.asMonetaryCost()}")
return false
}
if (!result) return false
} else {
val xpCost = cost.filteredXpCost()
if (xpCost > AnvilXpUtil.maximumXpCost(result.ignoreXpRules)) {
CustomAnvil.verboseLog("Cost above maximum $xpCost > ${AnvilXpUtil.maximumXpCost(result.ignoreXpRules)}")
return false
}
if (player.level < xpCost) {
CustomAnvil.verboseLog("Player do not have enough xp ${player.level} < $xpCost")
return false
}
if (xpCost > AnvilXpUtil.maximumXpCost(result.ignoreXpRules)) return false
if (player.level < xpCost) return false
player.level -= xpCost
}
@ -307,10 +293,7 @@ class AnvilResultListener : Listener {
rightRemoveCount: Int,
result: AnvilResult
): Boolean {
if (result.isEmpty()) {
CustomAnvil.verboseLog("Merge result is empty")
return false
}
if (result.isEmpty()) return false
// To avoid vanilla, we cancel the event
event.result = Event.Result.DENY
@ -318,10 +301,7 @@ class AnvilResultListener : Listener {
val cost = result.cost
processCost(view, player, cost)
if (!cost.valid && player.gameMode != GameMode.CREATIVE) {
CustomAnvil.verboseLog("Player cannot afford the cost")
return false
}
if (!cost.valid && player.gameMode != GameMode.CREATIVE) return false
// Where should we get the item
val slotDestination = getActionSlot(event, player)

View file

@ -168,7 +168,11 @@ class PrepareAnvilListener : Listener {
private fun applyResult(event: PrepareAnvilEvent, player: Player, result: AnvilResult) {
event.result = result.item
AnvilXpUtil.setAnvilResult(event.view, player, result)
if (result.item == null) {
AnvilXpUtil.onNoResult(player, event.view)
return
}
AnvilXpUtil.setAnvilInvCost(event.view, player, result.cost, result.ignoreXpRules)
}
}

View file

@ -3,6 +3,7 @@ package xyz.alexcrea.cuanvil.util.anvil
import io.delilaheve.CustomAnvil
import io.delilaheve.util.ConfigOptions
import io.delilaheve.util.EnchantmentUtil.enchantmentName
import io.delilaheve.util.ItemUtil.findEnchantments
import io.delilaheve.util.ItemUtil.isEnchantedBook
import org.bukkit.GameMode
import org.bukkit.NamespacedKey
@ -13,9 +14,7 @@ import org.bukkit.inventory.meta.Repairable
import org.bukkit.inventory.view.AnvilView
import org.bukkit.persistence.PersistentDataType
import xyz.alexcrea.cuanvil.anvil.AnvilCost
import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult
import xyz.alexcrea.cuanvil.anvil.AnvilUseType
import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager
@ -29,23 +28,7 @@ object AnvilXpUtil {
const val EXCLUSIVE_PENALTY_PREFIX = "repair_cost"
/**
* Display the required cost (either as xp or as money) or reset anvil price depending on result
*/
fun setAnvilResult(
inventory: AnvilInventory,
view: InventoryView,
player: Player,
result: AnvilResult) {
if(result.item == null) {
onNoResult(player, view)
return
}
setAnvilInvCost(inventory, view, player, result.cost, result.ignoreXpRules)
}
/**
* Display the required cost (either as xp or as money)
* Display the required cost (either as xp or as )
*/
fun setAnvilInvCost(
view: AnvilView,
@ -233,21 +216,17 @@ object AnvilXpUtil {
}
/**
* Function to calculate enchantments values
* Function to calculate right enchantment values
* it include enchantment placed on final item and conflicting enchantment
*/
fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) {
fun getRightValues(right: ItemStack, result: ItemStack, cost: AnvilCost) {
// Calculate right value and illegal enchant penalty
val rightIsFormBook = right.isEnchantedBook()
val rightEnchs = EnchantmentApi.getEnchantments(right)
val resultEnchs = EnchantmentApi.getEnchantments(result)
val resultEnchs = result.findEnchantments()
val resultEnchsKeys = HashMap(resultEnchs)
var rightValue = 0
var leftValue = 0
for (enchantment in rightEnchs) {
for (enchantment in right.findEnchantments()) {
// count enchant as illegal enchant if it conflicts with another enchant or not in result
if ((enchantment.key !in resultEnchsKeys)) {
resultEnchsKeys[enchantment.key] = enchantment.value
@ -269,31 +248,13 @@ object AnvilXpUtil {
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
val value = resultLevel * enchantmentMultiplier
CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
rightValue += value
CustomAnvil.log("Value for ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
cost.enchantment += value
}
if(ConfigOptions.includeLeftEnchantmentForCost) {
val leftIsFormBook = left.isEnchantedBook()
val leftEnchs = EnchantmentApi.getEnchantments(left)
for (enchantment in leftEnchs) {
// Do not process enchantment that are present on the sacrifice
if(rightEnchs.contains(enchantment.key)) continue
val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0)
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, leftIsFormBook)
val value = resultLevel * enchantmentMultiplier
CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
leftValue += value
}
}
cost.enchantment = rightValue + leftValue
CustomAnvil.log(
"Calculated right values: " +
"rightValue: ${rightValue}, " +
"leftValue: ${leftValue}, " +
"rightValue: ${cost.enchantment}, " +
"illegalPenalty: ${cost.illegalPenalty}"
)
}

View file

@ -119,9 +119,6 @@ permission_needed_for_dialog_rename: false
# For practical reason. this only work when dialog rename is enabled
dialog_rename_keep_user_text: true
# Also count left item enchantments for the final price
include_left_enchantment_for_cost: false
# Override limits for specific enchants
#
# Enchantments not listed here will use the value of default_limit
@ -174,8 +171,8 @@ enchant_limits:
# Multipliers used to calculate the enchantment's value in repair/combining
#
# Values here are pulled from the minecraft wiki:
# https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments
# Values here are pulled from the fandom wiki:
# https://minecraft.fandom.com/wiki/Anvil_mechanics#Costs_for_combining_enchantments
#
# If an enchantment is missing values here, or is less than 0, it will default to 0
#
@ -469,7 +466,4 @@ debug_log: false
# Whether to show verbose debug logging
debug_log_verbose: false
# Whether to show inside the console or require to run /ca debug get
display_debug_in_console: false
configVersion: 1.11.0

View file

@ -13,7 +13,6 @@ import org.bukkit.inventory.meta.Repairable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Assertions;
import xyz.alexcrea.cuanvil.api.EnchantmentApi;
import xyz.alexcrea.cuanvil.data.AnvilClickTestData;
import xyz.alexcrea.cuanvil.data.AnvilFuseTestData;
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
@ -48,7 +47,7 @@ public class AnvilFuseTestUtil {
}
ItemStack item = new ItemStack(material);
EnchantmentApi.setEnchantments(item, enchantmentMap);
ItemUtil.INSTANCE.setEnchantmentsUnsafe(item, enchantmentMap);
ItemMeta meta = item.getItemMeta();
((Repairable) meta).setRepairCost(repairCost);