aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorObsidian <108832807+Obsidianninja11@users.noreply.github.com>2024-03-01 01:23:20 -0900
committerGitHub <noreply@github.com>2024-03-01 11:23:20 +0100
commite249c70d1b0f8f543ae2fb63d71672b981cedcc0 (patch)
treecedae9090e0affb80da1036a2b82f2c57832c032 /src/main/java/at/hannibal2/skyhanni/features/misc
parent498eb136629d3f2b22f217ebec60b60761e1b899 (diff)
downloadskyhanni-e249c70d1b0f8f543ae2fb63d71672b981cedcc0.tar.gz
skyhanni-e249c70d1b0f8f543ae2fb63d71672b981cedcc0.tar.bz2
skyhanni-e249c70d1b0f8f543ae2fb63d71672b981cedcc0.zip
Added Copy Underbid Keybind. (#1052)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt
index 6ebcf08c0..5cfaa558a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt
@@ -1,23 +1,44 @@
package at.hannibal2.skyhanni.features.misc.items
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraft.client.gui.inventory.GuiContainer
+import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class AuctionHouseCopyUnderbidPrice {
- private val config get() = SkyHanniMod.feature.inventory
+ private val config get() = SkyHanniMod.feature.inventory.auctions
+
+ private val patternGroup = RepoPattern.group("auctions.underbid")
+ private val auctionPricePattern by patternGroup.pattern(
+ "price",
+ "^§7(?:Buy it now|Starting bid|Top bid): §6(?<coins>[0-9,]+) coins\$"
+ )
+ private val allowedInventoriesPattern by patternGroup.pattern(
+ "allowedinventories",
+ "^(?:Auctions Browser|Manage Auctions|Auctions: \".*\")$"
+ )
@SubscribeEvent
fun onInventoryUpdated(event: InventoryUpdatedEvent) {
- if (!isEnabled()) return
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.autoCopyUnderbidPrice) return
if (!event.fullyOpenedOnce) return
if (event.inventoryName != "Create BIN Auction") return
val item = event.inventoryItems[13] ?: return
@@ -32,8 +53,31 @@ class AuctionHouseCopyUnderbidPrice {
}
val newPrice = price * item.stackSize - 1
OSUtils.copyToClipboard("$newPrice")
- ChatUtils.chat("Set §e${newPrice.addSeparators()} §eto clipboard. (Copy Underbid Price)")
+ ChatUtils.chat("Copied ${newPrice.addSeparators()} to clipboard. (Copy Underbid Price)")
}
- fun isEnabled() = LorenzUtils.inSkyBlock && config.copyUnderbidPrice
+ @SubscribeEvent
+ fun onKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) {
+ if (!config.copyUnderbidKeybind.isKeyHeld()) return
+ if (!LorenzUtils.inSkyBlock) return
+ if (!allowedInventoriesPattern.matches(InventoryUtils.openInventoryName())) return
+
+ val gui = event.gui as? GuiContainer ?: return
+ val stack = gui.slotUnderMouse?.stack ?: return
+ val lore = stack.getLore()
+
+ for (line in lore) {
+ auctionPricePattern.matchMatcher(line) {
+ val underbid = group("coins").formatNumber() - 1
+ OSUtils.copyToClipboard("$underbid")
+ ChatUtils.chat("Copied ${underbid.addSeparators()} to clipboard.")
+ return
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
+ event.move(25, "inventory.copyUnderbidPrice", "inventory.auctions.autoCopyUnderbidPrice")
+ }
}