mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
disallow use of hex code and minimessage on append
This commit is contained in:
parent
11f7bf8602
commit
517fcf3430
8 changed files with 58 additions and 51 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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? {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue