disallow use of hex code and minimessage on append

This commit is contained in:
alexcrea 2025-10-23 15:34:04 +02:00
parent 11f7bf8602
commit 517fcf3430
Signed by: alexcrea
GPG key ID: E346CD16413450E3
8 changed files with 58 additions and 51 deletions

View file

@ -306,8 +306,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
remove: 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
paper: paper:
@ -363,8 +365,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
color_use_cost: 0 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
# Whether to show debug logging # Whether to show debug logging

View file

@ -318,8 +318,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
remove: 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
paper: paper:
@ -375,8 +377,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
color_use_cost: 0 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
# Whether to show debug logging # Whether to show debug logging

View file

@ -306,8 +306,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
remove: 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
paper: paper:
@ -363,8 +365,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
color_use_cost: 0 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
# Whether to show debug logging # Whether to show debug logging

View file

@ -26,6 +26,7 @@ import xyz.alexcrea.cuanvil.util.AnvilLoreEditUtil
import xyz.alexcrea.cuanvil.util.AnvilUseType import xyz.alexcrea.cuanvil.util.AnvilUseType
import xyz.alexcrea.cuanvil.util.AnvilXpUtil import xyz.alexcrea.cuanvil.util.AnvilXpUtil
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil
import xyz.alexcrea.cuanvil.util.config.LoreEditType import xyz.alexcrea.cuanvil.util.config.LoreEditType
@ -412,7 +413,9 @@ class AnvilResultListener : Listener {
val bookPage = StringBuilder() val bookPage = StringBuilder()
lore.forEach { lore.forEach {
if (bookPage.isNotEmpty()) bookPage.append('\n') 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() val resultPage = bookPage.toString()

View file

@ -195,7 +195,7 @@ class PrepareAnvilListener : Listener {
renameText, player, renameText, player,
ConfigOptions.permissionNeededForColor, ConfigOptions.permissionNeededForColor,
ConfigOptions.allowColorCode, ConfigOptions.allowHexadecimalColor, ConfigOptions.allowMinimessage, ConfigOptions.allowColorCode, ConfigOptions.allowHexadecimalColor, ConfigOptions.allowMinimessage,
AnvilColorUtil.ColorUseType.RENAME AnvilColorUtil.ColorUseType.RENAME, true
) )
if (component != null) { if (component != null) {

View file

@ -29,7 +29,9 @@ object AnvilColorUtil {
allowColorCode: Boolean, allowColorCode: Boolean,
allowHexadecimalColor: Boolean, allowHexadecimalColor: Boolean,
allowMinimessage: Boolean, allowMinimessage: Boolean,
useType: ColorUseType): ColorPermissions { useType: ColorUseType,
isAppend: Boolean = true
): ColorPermissions {
if (!allowColorCode && !allowHexadecimalColor && !allowMinimessage) if (!allowColorCode && !allowHexadecimalColor && !allowMinimessage)
return ColorPermissions( return ColorPermissions(
canUseColorCode = false, canUseColorCode = false,
@ -41,15 +43,20 @@ object AnvilColorUtil {
allowColorCode && (!usePermission || useType.colorCodePerm == null || player.hasPermission( allowColorCode && (!usePermission || useType.colorCodePerm == null || player.hasPermission(
useType.colorCodePerm useType.colorCodePerm
)) ))
val canUseHexColor =
allowHexadecimalColor && (!usePermission || useType.hexColorPerm == null || player.hasPermission(
useType.hexColorPerm
))
val canUseMinimessage = val canUseMinimessage =
allowMinimessage && (!usePermission || useType.minimessagePerm == null || player.hasPermission( allowMinimessage && (!usePermission || useType.minimessagePerm == null || player.hasPermission(
useType.minimessagePerm 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) return ColorPermissions(canUseColorCode, canUseHexColor, canUseMinimessage)
} }
@ -64,11 +71,12 @@ object AnvilColorUtil {
allowColorCode: Boolean, allowColorCode: Boolean,
allowHexadecimalColor: Boolean, allowHexadecimalColor: Boolean,
allowMinimessage: Boolean, allowMinimessage: Boolean,
useType: ColorUseType useType: ColorUseType,
isAppend: Boolean
): Component? { ): Component? {
val permission = calculatePermissions(player, usePermission, val permission = calculatePermissions(player, usePermission,
allowColorCode, allowHexadecimalColor, allowMinimessage, allowColorCode, allowHexadecimalColor, allowMinimessage,
useType) useType, isAppend)
return handleColor(textToColorText, permission) return handleColor(textToColorText, permission)
} }
@ -117,27 +125,6 @@ object AnvilColorUtil {
else null 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 * Best effort to revert a component to the smallest allowed string
* that would result in it getting closest as possible to handleColor * that would result in it getting closest as possible to handleColor

View file

@ -117,10 +117,10 @@ object AnvilLoreEditUtil {
} }
fun tryLoreEditByBook(player: HumanEntity, first: ItemStack, second: ItemStack, xpCost: AtomicInteger): ItemStack? { 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 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) else handleLoreRemoveByBook(player, first, xpCost)
} }
@ -225,9 +225,9 @@ object AnvilLoreEditUtil {
second: ItemStack, second: ItemStack,
xpCost: AtomicInteger xpCost: AtomicInteger
): ItemStack? { ): 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) else handleLoreRemoveByPaper(player, first, xpCost)
} }
@ -248,7 +248,8 @@ object AnvilLoreEditUtil {
editType.allowColorCode, editType.allowColorCode,
editType.allowHexColor, editType.allowHexColor,
editType.allowMinimessage, editType.allowMinimessage,
AnvilColorUtil.ColorUseType.LORE_EDIT) AnvilColorUtil.ColorUseType.LORE_EDIT,
editType.isAppend)
} }
private fun colorLine(line: String, permission: AnvilColorUtil.ColorPermissions): Component? { private fun colorLine(line: String, permission: AnvilColorUtil.ColorPermissions): Component? {

View file

@ -308,8 +308,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
remove: 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
paper: paper:
@ -365,8 +367,10 @@ lore_edit:
# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ # 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 # 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 # 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_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
color_use_cost: 0 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 # 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 # but any global tag will be allowed later when v2 release
allow_color_code: true allow_color_code: true
allow_hexadecimal_color: true allow_hexadecimal_color: false
allow_minimessage: true allow_minimessage: true
# Whether to show debug logging # Whether to show debug logging