Add use of color cost.

This commit is contained in:
alexcrea 2024-07-26 18:28:06 +02:00
parent 794a440d33
commit f72d3622ca
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
2 changed files with 18 additions and 4 deletions

View file

@ -169,21 +169,29 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
val displayName = ChatColor.stripColor(it.displayName) val displayName = ChatColor.stripColor(it.displayName)
var inventoryName = ChatColor.stripColor(inventory.renameText) var inventoryName = ChatColor.stripColor(inventory.renameText)
var sumCost = 0
var useColor = false var useColor = false
if(ConfigOptions.renameColorPossible){ if(ConfigOptions.renameColorPossible){
val resultString = StringBuilder(inventoryName) val resultString = StringBuilder(inventoryName)
useColor = handleRenamingColor(resultString, player) useColor = handleRenamingColor(resultString, player)
if(useColor) inventoryName = resultString.toString() if(useColor) {
inventoryName = resultString.toString()
sumCost+= ConfigOptions.useOfColorCost
}
} }
if ((!useColor && !displayName.contentEquals(inventoryName)) || (useColor && !(it.displayName).contentEquals(inventoryName))) { if ((!useColor && (!displayName.contentEquals(inventoryName))) || (useColor && !(it.displayName).contentEquals(inventoryName))) {
it.setDisplayName(inventoryName) it.setDisplayName(inventoryName)
resultItem.itemMeta = it resultItem.itemMeta = it
return ConfigOptions.itemRenameCost sumCost+= ConfigOptions.itemRenameCost
} }
return sumCost
} }
return 0 return 0
} }
@ -415,8 +423,14 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
leftItem.itemMeta?.let { leftMeta -> leftItem.itemMeta?.let { leftMeta ->
val leftName = leftMeta.displayName val leftName = leftMeta.displayName
output.itemMeta?.let { output.itemMeta?.let {
// Rename cost
if (!leftName.contentEquals(it.displayName)) { if (!leftName.contentEquals(it.displayName)) {
repairCost += ConfigOptions.itemRenameCost repairCost += ConfigOptions.itemRenameCost
// Color cost
if(it.displayName.contains('§')){
repairCost += ConfigOptions.useOfColorCost
}
} }
} }
} }

View file

@ -239,7 +239,7 @@ object ConfigOptions {
/** /**
* How many xp should use of color should cost * How many xp should use of color should cost
*/ */
private val useOfColorCost: Int val useOfColorCost: Int
get() { get() {
return ConfigHolder.DEFAULT_CONFIG return ConfigHolder.DEFAULT_CONFIG
.config .config