mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add and fix expected price for tests
todo add test for handling work penalty
This commit is contained in:
parent
79f05d0f82
commit
335bca0335
7 changed files with 47 additions and 44 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue