Add and fix expected price for tests

todo add test for handling work penalty
This commit is contained in:
alexcrea 2025-03-10 22:59:31 +01:00
parent 79f05d0f82
commit 335bca0335
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
7 changed files with 47 additions and 44 deletions

View file

@ -142,15 +142,16 @@ class PrepareAnvilListener : Listener {
// Rename item and add renaming cost
resultItem.itemMeta?.let {
val displayName =
if (useColor) it.displayName
else ChatColor.stripColor(it.displayName)
val hasDisplayName = it.hasDisplayName()
val displayName = if (!hasDisplayName) null
else if (useColor) it.displayName
else ChatColor.stripColor(it.displayName)
if (!displayName.contentEquals(inventoryName)) {
it.setDisplayName(inventoryName)
resultItem.itemMeta = it
sumCost+= ConfigOptions.itemRenameCost
sumCost += ConfigOptions.itemRenameCost
}
return sumCost

View file

@ -45,35 +45,42 @@ object AnvilXpUtil {
anvilCost
}
val maximumRepairCost =
if (ConfigOptions.doRemoveCostLimit || ignoreRules) {
Int.MAX_VALUE
} else {
ConfigOptions.maxAnvilCost + 1
}
// Try first just in case another plugin, or the test need this
inventory.maximumRepairCost = maximumRepairCost
inventory.repairCost = finalAnvilCost
// TODO for 2.x.x use anvil view & set directly there
/* Because Minecraft likes to have the final say in the repair cost displayed
* we need to wait for the event to end before overriding it, this ensures that
* we have the final say in the process. */
DependencyManager.scheduler.scheduleOnEntity(
CustomAnvil.instance, player,
Runnable {
inventory.maximumRepairCost =
if (ConfigOptions.doRemoveCostLimit || ignoreRules) {
Int.MAX_VALUE
} else {
ConfigOptions.maxAnvilCost + 1
}
CustomAnvil.instance, player
) {
// retry after a tick
inventory.maximumRepairCost = maximumRepairCost
inventory.repairCost = finalAnvilCost
// TODO for 2.x.x use anvil view & set directly there
inventory.repairCost = finalAnvilCost
view.setProperty(REPAIR_COST, finalAnvilCost)
player.openInventory.setProperty(REPAIR_COST, finalAnvilCost)
if (player !is Player) return@scheduleOnEntity
if (player is Player) {
if (player.gameMode != GameMode.CREATIVE) {
val bypassToExpensive = (ConfigOptions.doReplaceTooExpensive) &&
(finalAnvilCost >= 40) &&
finalAnvilCost < inventory.maximumRepairCost
if (player.gameMode != GameMode.CREATIVE) {
val bypassToExpensive = (ConfigOptions.doReplaceTooExpensive) &&
(finalAnvilCost >= 40) &&
finalAnvilCost < inventory.maximumRepairCost
DependencyManager.packetManager.setInstantBuild(player, bypassToExpensive)
}
DependencyManager.packetManager.setInstantBuild(player, bypassToExpensive)
}
player.updateInventory()
}
})
player.updateInventory()
}
}
/**