diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 692ee2d..2caafe3 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -306,8 +306,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true remove: @@ -336,7 +338,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true paper: @@ -363,8 +365,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true color_use_cost: 0 @@ -392,7 +396,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true # Whether to show debug logging diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index 028c401..2602e56 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -318,8 +318,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true remove: @@ -348,7 +350,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true paper: @@ -375,8 +377,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true color_use_cost: 0 @@ -404,7 +408,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true # Whether to show debug logging diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index fe655c2..139148b 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -306,8 +306,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true remove: @@ -336,7 +338,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true paper: @@ -363,8 +365,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true color_use_cost: 0 @@ -392,7 +396,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true # Whether to show debug logging diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index db2dfb0..bc3afa4 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -26,6 +26,7 @@ import xyz.alexcrea.cuanvil.util.AnvilLoreEditUtil import xyz.alexcrea.cuanvil.util.AnvilUseType import xyz.alexcrea.cuanvil.util.AnvilXpUtil import xyz.alexcrea.cuanvil.util.CustomRecipeUtil +import xyz.alexcrea.cuanvil.util.MiniMessageUtil import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil import xyz.alexcrea.cuanvil.util.config.LoreEditType @@ -412,7 +413,9 @@ class AnvilResultListener : Listener { val bookPage = StringBuilder() lore.forEach { if (bookPage.isNotEmpty()) bookPage.append('\n') - bookPage.append(it) + if(it == null) return@forEach + + bookPage.append(MiniMessageUtil.plain_text_mm.serialize(it)) } val resultPage = bookPage.toString() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index 17d5d0d..f491862 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -195,7 +195,7 @@ class PrepareAnvilListener : Listener { renameText, player, ConfigOptions.permissionNeededForColor, ConfigOptions.allowColorCode, ConfigOptions.allowHexadecimalColor, ConfigOptions.allowMinimessage, - AnvilColorUtil.ColorUseType.RENAME + AnvilColorUtil.ColorUseType.RENAME, true ) if (component != null) { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilColorUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilColorUtil.kt index 0abcaaf..320eef1 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilColorUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilColorUtil.kt @@ -29,7 +29,9 @@ object AnvilColorUtil { allowColorCode: Boolean, allowHexadecimalColor: Boolean, allowMinimessage: Boolean, - useType: ColorUseType): ColorPermissions { + useType: ColorUseType, + isAppend: Boolean = true + ): ColorPermissions { if (!allowColorCode && !allowHexadecimalColor && !allowMinimessage) return ColorPermissions( canUseColorCode = false, @@ -41,15 +43,20 @@ object AnvilColorUtil { allowColorCode && (!usePermission || useType.colorCodePerm == null || player.hasPermission( useType.colorCodePerm )) - val canUseHexColor = - allowHexadecimalColor && (!usePermission || useType.hexColorPerm == null || player.hasPermission( - useType.hexColorPerm - )) + val canUseMinimessage = allowMinimessage && (!usePermission || useType.minimessagePerm == null || player.hasPermission( useType.minimessagePerm )) + // Do not allow minimessage and hex color at the same time when coming from string to component (usually/assumed append) + val minimessageConflict = canUseMinimessage && isAppend + + val canUseHexColor = !minimessageConflict && + allowHexadecimalColor && (!usePermission || useType.hexColorPerm == null || player.hasPermission( + useType.hexColorPerm + )) + return ColorPermissions(canUseColorCode, canUseHexColor, canUseMinimessage) } @@ -64,11 +71,12 @@ object AnvilColorUtil { allowColorCode: Boolean, allowHexadecimalColor: Boolean, allowMinimessage: Boolean, - useType: ColorUseType + useType: ColorUseType, + isAppend: Boolean ): Component? { val permission = calculatePermissions(player, usePermission, allowColorCode, allowHexadecimalColor, allowMinimessage, - useType) + useType, isAppend) return handleColor(textToColorText, permission) } @@ -117,27 +125,6 @@ object AnvilColorUtil { else null } - /** - * Best effort to revert a component to the smallest allowed string - * that would result in it getting closest as possible to handleColor - * with current set of color type, color use type and player permissions - * @return the new component if had any change. null otherwise - */ - fun revertColorSmallest( - component: Component, - player: Permissible, - usePermission: Boolean, - allowColorCode: Boolean, - allowMinimessage: Boolean, - allowHexadecimalColor: Boolean, - useType: ColorUseType - ): String? { - val permission = calculatePermissions(player, usePermission, - allowColorCode, allowHexadecimalColor, allowMinimessage, - useType) - return revertColorSmallest(component, permission) - } - /** * Best effort to revert a component to the smallest allowed string * that would result in it getting closest as possible to handleColor diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilLoreEditUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilLoreEditUtil.kt index 4135df7..943be5f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilLoreEditUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilLoreEditUtil.kt @@ -117,10 +117,10 @@ object AnvilLoreEditUtil { } fun tryLoreEditByBook(player: HumanEntity, first: ItemStack, second: ItemStack, xpCost: AtomicInteger): ItemStack? { - val bookType = bookLoreEditIsAppend(first, second) ?: return null + val isAppend = bookLoreEditIsAppend(first, second) ?: return null val meta = second.itemMeta as BookMeta - return if (bookType) handleLoreAppendByBook(player, first, meta, xpCost) + return if (isAppend) handleLoreAppendByBook(player, first, meta, xpCost) else handleLoreRemoveByBook(player, first, xpCost) } @@ -225,9 +225,9 @@ object AnvilLoreEditUtil { second: ItemStack, xpCost: AtomicInteger ): ItemStack? { - val bookType = paperLoreEditIsAppend(first, second) ?: return null + val isAppend = paperLoreEditIsAppend(first, second) ?: return null - return if (bookType) handleLoreAppendByPaper(player, first, second, xpCost) + return if (isAppend) handleLoreAppendByPaper(player, first, second, xpCost) else handleLoreRemoveByPaper(player, first, xpCost) } @@ -248,7 +248,8 @@ object AnvilLoreEditUtil { editType.allowColorCode, editType.allowHexColor, editType.allowMinimessage, - AnvilColorUtil.ColorUseType.LORE_EDIT) + AnvilColorUtil.ColorUseType.LORE_EDIT, + editType.isAppend) } private fun colorLine(line: String, permission: AnvilColorUtil.ColorPermissions): Component? { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b645b55..79c4278 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -308,8 +308,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true remove: @@ -338,7 +340,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true paper: @@ -365,8 +367,10 @@ lore_edit: # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release + # + # Note that currently minimessage would disable hex code when adding color allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true color_use_cost: 0 @@ -394,7 +398,7 @@ lore_edit: # Note that only color and decoration tags are allowed for minimisage in the v1 version of this plugin # but any global tag will be allowed later when v2 release allow_color_code: true - allow_hexadecimal_color: true + allow_hexadecimal_color: false allow_minimessage: true # Whether to show debug logging