Skip to content

Commit

Permalink
Feature: cofl ah search item (#1743)
Browse files Browse the repository at this point in the history
Co-authored-by: Äkwav <16632490+Ekwav@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
3 people authored May 16, 2024
1 parent e65a4c1 commit c7b6a06
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -632,6 +633,7 @@ class SkyHanniMod {
loadModule(ShiftClickBrewing())
loadModule(BazaarOpenPriceWebsite())
loadModule(AuctionHouseCopyUnderbidPrice())
loadModule(AuctionHouseOpenPriceWebsite())
loadModule(AnvilCombineHelper())
loadModule(SeaCreatureMessageShortener())
loadModule(AshfangFreezeCooldown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.hannibal2.skyhanni.features.misc.items
package at.hannibal2.skyhanni.features.inventory.auctionhouse

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
Expand Down Expand Up @@ -31,7 +31,7 @@ class AuctionHouseCopyUnderbidPrice {
)
private val allowedInventoriesPattern by patternGroup.pattern(
"allowedinventories",
"(?:Auctions Browser|Manage Auctions|Auctions: \".*\"?)"
"Auctions Browser|Manage Auctions|Auctions: \".*\"?"
)

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -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: \"(?<searchTerm>.*)\"?"
)

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
}

0 comments on commit c7b6a06

Please sign in to comment.