Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: cofl ah search item #1743

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -268,6 +268,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 @@ -360,7 +362,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 @@ -628,6 +629,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 §ccoflnet.com§7.")
hannibal002 marked this conversation as resolved.
Show resolved Hide resolved
hannibal002 marked this conversation as resolved.
Show resolved Hide resolved
@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 cookieDurationPattern by patternGroup.pattern(
"title.search",
"Auctions: \"(?<searchTerm>.*)\""
hannibal002 marked this conversation as resolved.
Show resolved Hide resolved
)

private var searchTerm = ""
private var displayItem: ItemStack? = null

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
cookieDurationPattern.matchMatcher(event.inventoryName) {
hannibal002 marked this conversation as resolved.
Show resolved Hide resolved
searchTerm = group("searchTerm")
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
}
Loading