diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:34:18 +0200 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:34:18 +0200 |
| commit | 4293cfd919c3c93d4532534f722c407d7ad1370d (patch) | |
| tree | f9f612f021ef7f4283d74312edfaca30badc6749 /src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt | |
| parent | 538e3ceb76f8e0b590291ce9aa90aa94896cdcb6 (diff) | |
| parent | 024ba52fb69b6cd44b4e31542867f802de656f15 (diff) | |
| download | SkyHanni-cum.tar.gz SkyHanni-cum.tar.bz2 SkyHanni-cum.zip | |
Merge branch 'beta' into cumcum
# Conflicts:
# src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
# src/main/java/at/hannibal2/skyhanni/config/features/AshfangConfig.java
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt new file mode 100644 index 000000000..b39809125 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt @@ -0,0 +1,65 @@ +package at.hannibal2.skyhanni.features.bazaar + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.entity.player.InventoryPlayer +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class BazaarOpenPriceWebsite { + private val config get() = SkyHanniMod.feature.bazaar + private var lastClick = SimpleTimeMark.farPast() + + private val item by lazy { + val neuItem = NEUItems.getItemStack("PAPER", true) + Utils.createItemStack( + neuItem.item, + "§bPrice History", + "§7Click here to open", + "§7the price history", + "§7on §cskyblock.bz" + ) + } + + @SubscribeEvent + fun replaceItem(event: ReplaceItemEvent) { + if (!isEnabled()) return + BazaarApi.currentlyOpenedProduct ?: return + if (event.inventory is InventoryPlayer) return + + if (event.slotNumber == 22) { + event.replaceWith(item) + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onStackClick(event: SlotClickEvent) { + if (!isEnabled()) return + val lastItem = BazaarApi.currentlyOpenedProduct ?: return + + if (event.slotId == 22) { + event.isCanceled = true + if (lastClick.passedSince() > 0.3.seconds) { + val name = getSkyBlockBzName(lastItem) + OSUtils.openBrowser("https://www.skyblock.bz/product/$name") + lastClick = SimpleTimeMark.now() + } + } + } + + private fun getSkyBlockBzName(internalName: NEUInternalName): String { + val name = internalName.asString() + return if (name.contains(";")) { + "ENCHANTMENT_" + name.replace(";", "_") + } else name + } + + fun isEnabled() = config.openPriceWebsite +}
\ No newline at end of file |
