Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Dec 25, 2024
1 parent c413299 commit f2625f1
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ object AnitaMedalProfit {

private fun readItem(slot: Int, item: ItemStack, table: MutableList<DisplayTableEntry>) {
val itemName = getItemName(item)
if (itemName == " ") return
if (itemName == "§cClose") return
if (itemName == "§eUnique Gold Medals") return
if (itemName == "§aMedal Trades") return
if (isInvalidItemName(itemName)) return

val requiredItems = getRequiredItems(item)
val additionalMaterials = getAdditionalMaterials(requiredItems)
Expand Down Expand Up @@ -116,11 +113,7 @@ object AnitaMedalProfit {

// TODO add more exact material cost breakdown
add("§7Additional cost: §6${additionalCost.shortFormat()}")

for ((internalName, amount) in additionalMaterials) {
val pricePer = internalName.getPrice() * amount
add(" " + internalName.itemName + " §8${amount}x §7(§6${pricePer.shortFormat()}§7)")
}
addAdditionalMaterials(additionalMaterials)

add("§7Profit per sell: §6$profitPerSellFormat")
add("")
Expand All @@ -139,6 +132,23 @@ object AnitaMedalProfit {
)
}

private fun MutableList<String>.addAdditionalMaterials(additionalMaterials: Map<NEUInternalName, Int>) {
for ((internalName, amount) in additionalMaterials) {
val pricePer = internalName.getPrice() * amount
add(" " + internalName.itemName + " §8${amount}x §7(§6${pricePer.shortFormat()}§7)")
}
}

private fun isInvalidItemName(itemName: String): Boolean = when (itemName) {
" ",
"§cClose",
"§eUnique Gold Medals",
"§aMedal Trades",
-> true

else -> false
}

private fun getItemName(item: ItemStack): String {
val name = item.name
val isEnchantedBook = item.getItemCategoryOrNull() == ItemCategory.ENCHANTED_BOOK
Expand Down

0 comments on commit f2625f1

Please sign in to comment.