From 697d2788967ef2c86328c288799f73a8396ba566 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 4 Aug 2023 21:00:08 +0200 Subject: moving rift classes around for no reason part two --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../features/rift/everywhere/RiftMotesOrb.kt | 93 ---------- .../rift/everywhere/ShowMotesNpcSellPrice.kt | 187 --------------------- .../features/rift/everywhere/motes/RiftMotesOrb.kt | 93 ++++++++++ .../rift/everywhere/motes/ShowMotesNpcSellPrice.kt | 187 +++++++++++++++++++++ 5 files changed, 282 insertions(+), 280 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftMotesOrb.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/ShowMotesNpcSellPrice.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/RiftMotesOrb.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 5d0c30632..91d0e6f46 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -88,6 +88,8 @@ import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonHacking import at.hannibal2.skyhanni.features.rift.area.wyldwoods.RiftOdonata import at.hannibal2.skyhanni.features.rift.area.wyldwoods.ShyCruxWarnings import at.hannibal2.skyhanni.features.rift.everywhere.* +import at.hannibal2.skyhanni.features.rift.everywhere.motes.RiftMotesOrb +import at.hannibal2.skyhanni.features.rift.everywhere.motes.ShowMotesNpcSellPrice import at.hannibal2.skyhanni.features.slayer.* import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerClearView import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerDaggerHelper diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftMotesOrb.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftMotesOrb.kt deleted file mode 100644 index 66d6efaa9..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftMotesOrb.kt +++ /dev/null @@ -1,93 +0,0 @@ -package at.hannibal2.skyhanni.features.rift.everywhere - -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.ReceiveParticleEvent -import at.hannibal2.skyhanni.features.rift.RiftAPI -import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy -import at.hannibal2.skyhanni.utils.LorenzUtils.round -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.client.event.RenderWorldLastEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class RiftMotesOrb { - private val config get() = RiftAPI.config.motesOrbsConfig - private var motesOrbs = emptyList() - private val pattern = "§5§lORB! §r§dPicked up §r§5+.* Motes§r§d.*".toPattern() - - class MotesOrb( - var location: LorenzVec, - var counter: Int = 0, - var startTime: Long = System.currentTimeMillis(), - var lastTime: Long = System.currentTimeMillis(), - var isOrb: Boolean = false, - var pickedUp: Boolean = false, - ) - - @SubscribeEvent - fun onReceiveParticle(event: ReceiveParticleEvent) { - if (!isEnabled()) return - val location = event.location.add(-0.5, 0.0, -0.5) - - if (event.type == EnumParticleTypes.SPELL_MOB) { - val orb = - motesOrbs.find { it.location.distance(location) < 3 } ?: MotesOrb(location).also { - motesOrbs = motesOrbs.editCopy { add(it) } - } - - orb.location = location - orb.lastTime = System.currentTimeMillis() - orb.counter++ - orb.pickedUp = false - if (config.hideParticles && orb.isOrb) { - event.isCanceled = true - } - } - } - - @SubscribeEvent - fun onChatMessage(event: LorenzChatEvent) { - pattern.matchMatcher(event.message) { - motesOrbs.minByOrNull { it.location.distanceToPlayer() }?.let { - it.pickedUp = true - } - } - } - - @SubscribeEvent - fun onRenderWorld(event: RenderWorldLastEvent) { - if (!isEnabled()) return - - motesOrbs = motesOrbs.editCopy { removeIf { System.currentTimeMillis() > it.lastTime + 2000 } } - - for (orb in motesOrbs) { - val ageInSeconds = (System.currentTimeMillis() - orb.startTime).toDouble() / 1000 - if (ageInSeconds < 0.5) continue - - val particlesPerSecond = (orb.counter.toDouble() / ageInSeconds).round(1) - if (particlesPerSecond < 60 || particlesPerSecond > 90) continue - orb.isOrb = true - - if (System.currentTimeMillis() > orb.lastTime + 300) { - orb.pickedUp = true - } - - val location = orb.location - - if (orb.pickedUp) { - event.drawDynamicText(location.add(0.0, 0.5, 0.0), "§7Motes Orb", 1.5, ignoreBlocks = false) - event.drawWaypointFilled(location, LorenzColor.GRAY.toColor()) - } else { - event.drawDynamicText(location.add(0.0, 0.5, 0.0), "§dMotes Orb", 1.5, ignoreBlocks = false) - event.drawWaypointFilled(location, LorenzColor.LIGHT_PURPLE.toColor()) - } - } - } - - fun isEnabled() = RiftAPI.inRift() && config.enabled -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/ShowMotesNpcSellPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/ShowMotesNpcSellPrice.kt deleted file mode 100644 index ce48c62a0..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/ShowMotesNpcSellPrice.kt +++ /dev/null @@ -1,187 +0,0 @@ -package at.hannibal2.skyhanni.features.rift.everywhere - -import at.hannibal2.skyhanni.events.* -import at.hannibal2.skyhanni.features.rift.RiftAPI -import at.hannibal2.skyhanni.features.rift.RiftAPI.motesNpcPrice -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector -import at.hannibal2.skyhanni.utils.LorenzUtils.chat -import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.NumberUtil -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.highlight -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.renderables.Renderable -import net.minecraftforge.event.entity.player.ItemTooltipEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class ShowMotesNpcSellPrice { - private val config get() = RiftAPI.config.motes - private var display = emptyList>() - private val pattern = ".*(?:§\\w)+You have (?:§\\w)+(?\\d) Grubber Stacks.*".toPattern() - private val itemMap = mutableMapOf, Double>>() - private var inInventory = false - private val slotList = mutableListOf() - - @SubscribeEvent - fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) { - if (!isInventoryValueEnabled()) return - if (inInventory) { - config.inventoryValue.position.renderStringsAndItems( - display, - itemScale = 1.3, - posLabel = "Inventory Motes Value" - ) - } - } - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!isInventoryValueEnabled()) return - if (event.isMod(10)) - processItems() - } - - @SubscribeEvent(priority = EventPriority.LOW) - fun onDrawSelectedTemplate(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!isInventoryValueEnabled()) return - val name = InventoryUtils.openInventoryName() - if (!name.contains("Rift Storage")) return - for (slot in InventoryUtils.getItemsInOpenChest()) { - if (slotList.contains(slot.slotIndex)) - slot highlight LorenzColor.GREEN - } - } - - @SubscribeEvent - fun onItemTooltipLow(event: ItemTooltipEvent) { - if (!isShowPriceEnabled()) return - - val itemStack = event.itemStack ?: return - - val baseMotes = itemStack.motesNpcPrice() ?: return - val burgerStacks = config.burgerStacks - val burgerText = if (burgerStacks > 0) "(${burgerStacks}x≡) " else "" - val size = itemStack.stackSize - if (size > 1) { - event.toolTip.add("§6NPC price: $burgerText§d${baseMotes.addSeparators()} Motes §7($size x §d${(baseMotes / size).addSeparators()} Motes§7)") - } else { - event.toolTip.add("§6NPC price: $burgerText§d${baseMotes.addSeparators()} Motes") - } - } - - @SubscribeEvent - fun onInventoryOpen(event: InventoryFullyOpenedEvent) { - reset() - } - - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - reset() - } - - private fun reset() { - if (!isInventoryValueEnabled()) return - itemMap.clear() - slotList.clear() - inInventory = false - } - - private fun processItems() { - val inventoryName = InventoryUtils.openInventoryName() - if (!inventoryName.contains("Rift Storage")) return - val stacks = InventoryUtils.getItemsInOpenChest().map { it.slotIndex to it.stack } - itemMap.clear() - for ((index, stack) in stacks) { - val itemValue = stack.motesNpcPrice() ?: continue - if (itemMap.contains(stack.getInternalName())) { - val (oldIndex, oldValue) = itemMap[stack.getInternalName()] ?: return - oldIndex.add(index) - itemMap[stack.getInternalName()] = Pair(oldIndex, oldValue + itemValue) - } else { - itemMap[stack.getInternalName()] = Pair(mutableListOf(index), itemValue) - } - } - inInventory = true - update() - } - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!RiftAPI.inRift()) return - pattern.matchMatcher(event.message) { - config.burgerStacks = group("amount").toInt() - chat("§6[SkyHanni] Set your McGrubber's burger stacks to ${group("amount")}.") - } - } - - private fun update() { - display = drawDisplay() - } - - private fun drawDisplay() = buildList> { - val newDisplay = mutableListOf>() - newDisplay.addAsSingletonList("§7Item Values:") - val sorted = itemMap.toList().sortedByDescending { it.second.second }.toMap().toMutableMap() - - for ((internalName, pair) in sorted) { - newDisplay.add(buildList { - val (index, value) = pair - val dashColor = if (slotList.containsAll(index)) "§a" else "§7" - add(" $dashColor- ") - val stack = NEUItems.getItemStack(internalName) - add(stack) - val price = value.formatPrice() - val valuePer = stack.motesNpcPrice() ?: continue - val tips = buildList { - add("§eClick to highlight in the chest !") - add("§6Value per: §d$valuePer Motes") - add("§6Total in chest: §d${(value / valuePer).toInt()}") - } - add(Renderable.clickAndHover("§6${stack.displayName}: §b$price", tips) { - for (slot in InventoryUtils.getItemsInOpenChest()) { - if (index.contains(slot.slotIndex)) { - if (slotList.contains(slot.slotIndex)) { - slotList.remove(slot.slotIndex) - } else { - slotList.add(slot.slotIndex) - } - } - } - }) - }) - } - val total = itemMap.values.fold(0.0) { acc, pair -> acc + pair.second }.formatPrice() - newDisplay.addAsSingletonList("§7Total price: §b$total") - val name = FormatType.values()[config.inventoryValue.formatType].type - newDisplay.addAsSingletonList("§7Price format: §c$name") - newDisplay.addSelector(" ", FormatType.values(), - getName = { type -> type.type }, - isCurrent = { it.ordinal == config.inventoryValue.formatType }, - onChange = { - config.inventoryValue.formatType = it.ordinal - update() - }) - return newDisplay - } - - enum class FormatType(val type: String) { - SHORT("Short"), - LONG("Long") - } - - private fun Double.formatPrice(): String = when (config.inventoryValue.formatType) { - 0 -> NumberUtil.format(this) - 1 -> this.addSeparators() - else -> "0" - } - - private fun isShowPriceEnabled() = RiftAPI.inRift() && config.showPrice - - private fun isInventoryValueEnabled() = RiftAPI.inRift() && config.inventoryValue.enabled -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/RiftMotesOrb.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/RiftMotesOrb.kt new file mode 100644 index 000000000..df7e0832d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/RiftMotesOrb.kt @@ -0,0 +1,93 @@ +package at.hannibal2.skyhanni.features.rift.everywhere.motes + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.ReceiveParticleEvent +import at.hannibal2.skyhanni.features.rift.RiftAPI +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class RiftMotesOrb { + private val config get() = RiftAPI.config.motesOrbsConfig + private var motesOrbs = emptyList() + private val pattern = "§5§lORB! §r§dPicked up §r§5+.* Motes§r§d.*".toPattern() + + class MotesOrb( + var location: LorenzVec, + var counter: Int = 0, + var startTime: Long = System.currentTimeMillis(), + var lastTime: Long = System.currentTimeMillis(), + var isOrb: Boolean = false, + var pickedUp: Boolean = false, + ) + + @SubscribeEvent + fun onReceiveParticle(event: ReceiveParticleEvent) { + if (!isEnabled()) return + val location = event.location.add(-0.5, 0.0, -0.5) + + if (event.type == EnumParticleTypes.SPELL_MOB) { + val orb = + motesOrbs.find { it.location.distance(location) < 3 } ?: MotesOrb(location).also { + motesOrbs = motesOrbs.editCopy { add(it) } + } + + orb.location = location + orb.lastTime = System.currentTimeMillis() + orb.counter++ + orb.pickedUp = false + if (config.hideParticles && orb.isOrb) { + event.isCanceled = true + } + } + } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + pattern.matchMatcher(event.message) { + motesOrbs.minByOrNull { it.location.distanceToPlayer() }?.let { + it.pickedUp = true + } + } + } + + @SubscribeEvent + fun onRenderWorld(event: RenderWorldLastEvent) { + if (!isEnabled()) return + + motesOrbs = motesOrbs.editCopy { removeIf { System.currentTimeMillis() > it.lastTime + 2000 } } + + for (orb in motesOrbs) { + val ageInSeconds = (System.currentTimeMillis() - orb.startTime).toDouble() / 1000 + if (ageInSeconds < 0.5) continue + + val particlesPerSecond = (orb.counter.toDouble() / ageInSeconds).round(1) + if (particlesPerSecond < 60 || particlesPerSecond > 90) continue + orb.isOrb = true + + if (System.currentTimeMillis() > orb.lastTime + 300) { + orb.pickedUp = true + } + + val location = orb.location + + if (orb.pickedUp) { + event.drawDynamicText(location.add(0.0, 0.5, 0.0), "§7Motes Orb", 1.5, ignoreBlocks = false) + event.drawWaypointFilled(location, LorenzColor.GRAY.toColor()) + } else { + event.drawDynamicText(location.add(0.0, 0.5, 0.0), "§dMotes Orb", 1.5, ignoreBlocks = false) + event.drawWaypointFilled(location, LorenzColor.LIGHT_PURPLE.toColor()) + } + } + } + + fun isEnabled() = RiftAPI.inRift() && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt new file mode 100644 index 000000000..1f88a4ad1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt @@ -0,0 +1,187 @@ +package at.hannibal2.skyhanni.features.rift.everywhere.motes + +import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.features.rift.RiftAPI +import at.hannibal2.skyhanni.features.rift.RiftAPI.motesNpcPrice +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector +import at.hannibal2.skyhanni.utils.LorenzUtils.chat +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ShowMotesNpcSellPrice { + private val config get() = RiftAPI.config.motes + private var display = emptyList>() + private val pattern = ".*(?:§\\w)+You have (?:§\\w)+(?\\d) Grubber Stacks.*".toPattern() + private val itemMap = mutableMapOf, Double>>() + private var inInventory = false + private val slotList = mutableListOf() + + @SubscribeEvent + fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) { + if (!isInventoryValueEnabled()) return + if (inInventory) { + config.inventoryValue.position.renderStringsAndItems( + display, + itemScale = 1.3, + posLabel = "Inventory Motes Value" + ) + } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isInventoryValueEnabled()) return + if (event.isMod(10)) + processItems() + } + + @SubscribeEvent(priority = EventPriority.LOW) + fun onDrawSelectedTemplate(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!isInventoryValueEnabled()) return + val name = InventoryUtils.openInventoryName() + if (!name.contains("Rift Storage")) return + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (slotList.contains(slot.slotIndex)) + slot highlight LorenzColor.GREEN + } + } + + @SubscribeEvent + fun onItemTooltipLow(event: ItemTooltipEvent) { + if (!isShowPriceEnabled()) return + + val itemStack = event.itemStack ?: return + + val baseMotes = itemStack.motesNpcPrice() ?: return + val burgerStacks = config.burgerStacks + val burgerText = if (burgerStacks > 0) "(${burgerStacks}x≡) " else "" + val size = itemStack.stackSize + if (size > 1) { + event.toolTip.add("§6NPC price: $burgerText§d${baseMotes.addSeparators()} Motes §7($size x §d${(baseMotes / size).addSeparators()} Motes§7)") + } else { + event.toolTip.add("§6NPC price: $burgerText§d${baseMotes.addSeparators()} Motes") + } + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + reset() + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + reset() + } + + private fun reset() { + if (!isInventoryValueEnabled()) return + itemMap.clear() + slotList.clear() + inInventory = false + } + + private fun processItems() { + val inventoryName = InventoryUtils.openInventoryName() + if (!inventoryName.contains("Rift Storage")) return + val stacks = InventoryUtils.getItemsInOpenChest().map { it.slotIndex to it.stack } + itemMap.clear() + for ((index, stack) in stacks) { + val itemValue = stack.motesNpcPrice() ?: continue + if (itemMap.contains(stack.getInternalName())) { + val (oldIndex, oldValue) = itemMap[stack.getInternalName()] ?: return + oldIndex.add(index) + itemMap[stack.getInternalName()] = Pair(oldIndex, oldValue + itemValue) + } else { + itemMap[stack.getInternalName()] = Pair(mutableListOf(index), itemValue) + } + } + inInventory = true + update() + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!RiftAPI.inRift()) return + pattern.matchMatcher(event.message) { + config.burgerStacks = group("amount").toInt() + chat("§6[SkyHanni] Set your McGrubber's burger stacks to ${group("amount")}.") + } + } + + private fun update() { + display = drawDisplay() + } + + private fun drawDisplay() = buildList> { + val newDisplay = mutableListOf>() + newDisplay.addAsSingletonList("§7Item Values:") + val sorted = itemMap.toList().sortedByDescending { it.second.second }.toMap().toMutableMap() + + for ((internalName, pair) in sorted) { + newDisplay.add(buildList { + val (index, value) = pair + val dashColor = if (slotList.containsAll(index)) "§a" else "§7" + add(" $dashColor- ") + val stack = NEUItems.getItemStack(internalName) + add(stack) + val price = value.formatPrice() + val valuePer = stack.motesNpcPrice() ?: continue + val tips = buildList { + add("§eClick to highlight in the chest !") + add("§6Value per: §d$valuePer Motes") + add("§6Total in chest: §d${(value / valuePer).toInt()}") + } + add(Renderable.clickAndHover("§6${stack.displayName}: §b$price", tips) { + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (index.contains(slot.slotIndex)) { + if (slotList.contains(slot.slotIndex)) { + slotList.remove(slot.slotIndex) + } else { + slotList.add(slot.slotIndex) + } + } + } + }) + }) + } + val total = itemMap.values.fold(0.0) { acc, pair -> acc + pair.second }.formatPrice() + newDisplay.addAsSingletonList("§7Total price: §b$total") + val name = FormatType.values()[config.inventoryValue.formatType].type + newDisplay.addAsSingletonList("§7Price format: §c$name") + newDisplay.addSelector(" ", FormatType.values(), + getName = { type -> type.type }, + isCurrent = { it.ordinal == config.inventoryValue.formatType }, + onChange = { + config.inventoryValue.formatType = it.ordinal + update() + }) + return newDisplay + } + + enum class FormatType(val type: String) { + SHORT("Short"), + LONG("Long") + } + + private fun Double.formatPrice(): String = when (config.inventoryValue.formatType) { + 0 -> NumberUtil.format(this) + 1 -> this.addSeparators() + else -> "0" + } + + private fun isShowPriceEnabled() = RiftAPI.inRift() && config.showPrice + + private fun isInventoryValueEnabled() = RiftAPI.inRift() && config.inventoryValue.enabled +} -- cgit