-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: cofl ah search item (#1743)
Co-authored-by: Äkwav <16632490+Ekwav@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
1 parent
e65a4c1
commit c7b6a06
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ava/at/hannibal2/skyhanni/features/inventory/auctionhouse/AuctionHouseOpenPriceWebsite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |