From c7b6a0683c5e578c3018b413c307c800b33b3943 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 17 May 2024 00:48:44 +0200 Subject: Feature: cofl ah search item (#1743) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Äkwav <16632490+Ekwav@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../features/inventory/AuctionHouseConfig.java | 6 ++ .../auctionhouse/AuctionHouseCopyUnderbidPrice.kt | 76 ++++++++++++++++++ .../auctionhouse/AuctionHouseOpenPriceWebsite.kt | 89 ++++++++++++++++++++++ .../misc/items/AuctionHouseCopyUnderbidPrice.kt | 76 ------------------ 5 files changed, 174 insertions(+), 77 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseCopyUnderbidPrice.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 4ae9ed824..2f3920a18 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -270,6 +270,8 @@ import at.hannibal2.skyhanni.features.inventory.ShiftClickNPCSell import at.hannibal2.skyhanni.features.inventory.SkyblockGuideHighlightFeature import at.hannibal2.skyhanni.features.inventory.StatsTuning import at.hannibal2.skyhanni.features.inventory.SuperCraftFeatures +import at.hannibal2.skyhanni.features.inventory.auctionhouse.AuctionHouseCopyUnderbidPrice +import at.hannibal2.skyhanni.features.inventory.auctionhouse.AuctionHouseOpenPriceWebsite import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarBestSellMethod import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarCancelledBuyOrderClipboard @@ -362,7 +364,6 @@ import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList import at.hannibal2.skyhanni.features.misc.compacttablist.TabListReader import at.hannibal2.skyhanni.features.misc.compacttablist.TabListRenderer import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager -import at.hannibal2.skyhanni.features.misc.items.AuctionHouseCopyUnderbidPrice import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValue import at.hannibal2.skyhanni.features.misc.items.EstimatedWardrobePrice import at.hannibal2.skyhanni.features.misc.items.GlowingDroppedItems @@ -632,6 +633,7 @@ class SkyHanniMod { loadModule(ShiftClickBrewing()) loadModule(BazaarOpenPriceWebsite()) loadModule(AuctionHouseCopyUnderbidPrice()) + loadModule(AuctionHouseOpenPriceWebsite()) loadModule(AnvilCombineHelper()) loadModule(SeaCreatureMessageShortener()) loadModule(AshfangFreezeCooldown) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHouseConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHouseConfig.java index 3725eeb1c..21108095b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHouseConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHouseConfig.java @@ -49,4 +49,10 @@ public class AuctionHouseConfig { ) @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) public int copyUnderbidKeybind = Keyboard.KEY_NONE; + + @Expose + @ConfigOption(name = "Price Website", desc = "Adds a button to the Auction House that will open the item page in §csky.coflnet.com§7.") + @ConfigEditorBoolean + @FeatureToggle + public boolean openPriceWebsite = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseCopyUnderbidPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseCopyUnderbidPrice.kt new file mode 100644 index 000000000..9b7cab11a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseCopyUnderbidPrice.kt @@ -0,0 +1,76 @@ +package at.hannibal2.skyhanni.features.inventory.auctionhouse + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.GuiKeyPressEvent +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.formatLong +import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class AuctionHouseCopyUnderbidPrice { + + 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(?[0-9,]+) coins" + ) + private val allowedInventoriesPattern by patternGroup.pattern( + "allowedinventories", + "Auctions Browser|Manage Auctions|Auctions: \".*\"?" + ) + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + 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 + + val internalName = item.getInternalName() + if (internalName == NEUInternalName.NONE) return + + val price = internalName.getPrice().toLong() + if (price <= 0) { + OSUtils.copyToClipboard("") + return + } + val newPrice = price * item.stackSize - 1 + OSUtils.copyToClipboard("$newPrice") + ChatUtils.chat("Copied ${newPrice.addSeparators()} to clipboard. (Copy Underbid Price)") + } + + @SubscribeEvent + fun onKeybind(event: GuiKeyPressEvent) { + if (!config.copyUnderbidKeybind.isKeyHeld()) return + if (!LorenzUtils.inSkyBlock) return + if (!allowedInventoriesPattern.matches(InventoryUtils.openInventoryName())) return + val stack = event.guiContainer.slotUnderMouse?.stack ?: return + + stack.getLore().matchFirst(auctionPricePattern) { + val underbid = group("coins").formatLong() - 1 + OSUtils.copyToClipboard("$underbid") + ChatUtils.chat("Copied ${underbid.addSeparators()} to clipboard.") + } + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(25, "inventory.copyUnderbidPrice", "inventory.auctions.autoCopyUnderbidPrice") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt new file mode 100644 index 000000000..9f1cce065 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt @@ -0,0 +1,89 @@ +package at.hannibal2.skyhanni.features.inventory.auctionhouse + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.entity.player.InventoryPlayer +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class AuctionHouseOpenPriceWebsite { + + private val config get() = SkyHanniMod.feature.inventory.auctions + private var lastClick = SimpleTimeMark.farPast() + + private val patternGroup = RepoPattern.group("inventory.auctionhouse") + + /** + * REGEX-TEST: Auctions: "hyperion" + */ + private val ahSearchPattern by patternGroup.pattern( + "title.search", + "Auctions: \"(?.*)\"?" + ) + + private var searchTerm = "" + private var displayItem: ItemStack? = null + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!isEnabled()) return + ahSearchPattern.matchMatcher(event.inventoryName) { + searchTerm = group("searchTerm").removeSuffix("\"").replace(" ", "%20") + displayItem = createDisplayItem() + } + } + + private fun createDisplayItem() = Utils.createItemStack( + "PAPER".asInternalName().getItemStack().item, + "§bPrice History", + "§7Click here to open", + "§7the price history", + "§7of §e$searchTerm", + "§7on §csky.coflnet.com" + ) + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + displayItem = null + } + + @SubscribeEvent + fun replaceItem(event: ReplaceItemEvent) { + if (!isEnabled()) return + if (event.inventory is InventoryPlayer) return + + if (event.slotNumber == 8) { + displayItem?.let { + event.replaceWith(it) + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!isEnabled()) return + displayItem ?: return + if (event.slotId != 8) return + event.isCanceled = true + if (lastClick.passedSince() > 0.3.seconds) { + val url = "https://sky.coflnet.com/api/mod/open/$searchTerm" + OSUtils.openBrowser(url) + lastClick = SimpleTimeMark.now() + } + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.openPriceWebsite +} 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 deleted file mode 100644 index 43ca734fc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt +++ /dev/null @@ -1,76 +0,0 @@ -package at.hannibal2.skyhanni.features.misc.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.GuiKeyPressEvent -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.formatLong -import at.hannibal2.skyhanni.utils.OSUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchFirst -import at.hannibal2.skyhanni.utils.StringUtils.matches -import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class AuctionHouseCopyUnderbidPrice { - - 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(?[0-9,]+) coins" - ) - private val allowedInventoriesPattern by patternGroup.pattern( - "allowedinventories", - "(?:Auctions Browser|Manage Auctions|Auctions: \".*\"?)" - ) - - @SubscribeEvent - fun onInventoryUpdated(event: InventoryUpdatedEvent) { - 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 - - val internalName = item.getInternalName() - if (internalName == NEUInternalName.NONE) return - - val price = internalName.getPrice().toLong() - if (price <= 0) { - OSUtils.copyToClipboard("") - return - } - val newPrice = price * item.stackSize - 1 - OSUtils.copyToClipboard("$newPrice") - ChatUtils.chat("Copied ${newPrice.addSeparators()} to clipboard. (Copy Underbid Price)") - } - - @SubscribeEvent - fun onKeybind(event: GuiKeyPressEvent) { - if (!config.copyUnderbidKeybind.isKeyHeld()) return - if (!LorenzUtils.inSkyBlock) return - if (!allowedInventoriesPattern.matches(InventoryUtils.openInventoryName())) return - val stack = event.guiContainer.slotUnderMouse?.stack ?: return - - stack.getLore().matchFirst(auctionPricePattern) { - val underbid = group("coins").formatLong() - 1 - OSUtils.copyToClipboard("$underbid") - ChatUtils.chat("Copied ${underbid.addSeparators()} to clipboard.") - } - } - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(25, "inventory.copyUnderbidPrice", "inventory.auctions.autoCopyUnderbidPrice") - } -} -- cgit