diff options
Diffstat (limited to 'src')
6 files changed, 118 insertions, 29 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 75e8e28a8..650f334df 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -8,10 +8,7 @@ import at.hannibal2.skyhanni.data.* import at.hannibal2.skyhanni.data.repo.RepoManager import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.features.anvil.AnvilCombineHelper -import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.features.bazaar.BazaarBestSellMethod -import at.hannibal2.skyhanni.features.bazaar.BazaarCancelledBuyOrderClipboard -import at.hannibal2.skyhanni.features.bazaar.BazaarOrderHelper +import at.hannibal2.skyhanni.features.bazaar.* import at.hannibal2.skyhanni.features.bingo.* import at.hannibal2.skyhanni.features.chat.* import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter @@ -207,6 +204,7 @@ class SkyHanniMod { loadModule(TrophyFishFillet()) loadModule(TrophyFishMessages()) loadModule(BazaarBestSellMethod()) + loadModule(BazaarOpenPriceWebsite()) loadModule(AnvilCombineHelper()) loadModule(SeaCreatureMessageShortener()) // registerEvent(new GriffinBurrowFinder()); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/BazaarConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/BazaarConfig.java index 8d3565765..bfb0b30d6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/BazaarConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/BazaarConfig.java @@ -34,4 +34,10 @@ public class BazaarConfig { @ConfigEditorBoolean @FeatureToggle public boolean cancelledBuyOrderClipboard = false; + + @Expose + @ConfigOption(name = "Price Website", desc = "Adds an item to the bazaar product inventory that will open the item page in §cskyblock.bz§7.") + @ConfigEditorBoolean + @FeatureToggle + public boolean openPriceWebsite = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/events/BazaarOpenedProductEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BazaarOpenedProductEvent.kt new file mode 100644 index 000000000..a746d7468 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/BazaarOpenedProductEvent.kt @@ -0,0 +1,6 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.utils.NEUInternalName + +class BazaarOpenedProductEvent(val openedProduct: NEUInternalName, val inventoryOpenEvent: InventoryFullyOpenedEvent) : + LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt index d17a3dc6b..dfc69dee8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -21,6 +21,8 @@ class BazaarApi { var inBazaarInventory = false private var currentSearchedItem = "" + var currentlyOpenedProduct: NEUInternalName? = null + fun getBazaarDataByName(name: String): BazaarData? = NEUItems.getInternalNameOrNull(name)?.getBazaarData() fun NEUInternalName.getBazaarData() = if (isBazaarItem()) { @@ -45,6 +47,21 @@ class BazaarApi { @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { inBazaarInventory = checkIfInBazaar(event) + if (inBazaarInventory) { + val openedProduct = getOpenedProduct(event.inventoryItems) ?: return + currentlyOpenedProduct = openedProduct + BazaarOpenedProductEvent(openedProduct, event).postAndCatch() + } + } + + private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): NEUInternalName? { + val buyInstantly = inventoryItems[10] ?: return null + + if (buyInstantly.displayName != "§aBuy Instantly") return null + val bazaarItem = inventoryItems[13] ?: return null + + val itemName = bazaarItem.displayName + return NEUItems.getInternalNameOrNull(itemName) } @SubscribeEvent @@ -118,5 +135,6 @@ class BazaarApi { @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { inBazaarInventory = false + currentlyOpenedProduct = null } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt index d6145fb63..b42a331fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt @@ -1,16 +1,18 @@ package at.hannibal2.skyhanni.features.bazaar import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData +import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getNameWithEnchantment import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.inventory.ContainerChest +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import net.minecraft.item.ItemStack import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -18,40 +20,36 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BazaarBestSellMethod { private var display = "" + // Working with the last clicked item manually because + // the open inventory event happen while the recent clicked item in the inventory is not in the inventory or in the cursor slot + private var lastClickedItem: ItemStack? = null + private var nextCloseWillResetItem = false + @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { display = "" + if (lastClickedItem != null) { + if (nextCloseWillResetItem) { + lastClickedItem = null + } + nextCloseWillResetItem = !nextCloseWillResetItem + } } @SubscribeEvent - fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent.Post) { + fun onBazaarOpenedProduct(event: BazaarOpenedProductEvent) { if (!isEnabled()) return - display = getNewText(event) + display = updateDisplay(event.openedProduct) } - private fun getNewText(event: GuiScreenEvent.DrawScreenEvent.Post): String { + private fun updateDisplay(internalName: NEUInternalName): String { try { - if (event.gui !is GuiChest) return "" - val chest = (event.gui as GuiChest).inventorySlots as ContainerChest - - val inv = chest.lowerChestInventory ?: return "" - - val buyInstantly = inv.getStackInSlot(10) - if (buyInstantly == null || buyInstantly.displayName != "§aBuy Instantly") return "" - val bazaarItem = inv.getStackInSlot(13) ?: return "" - - val internalName = NEUItems.getInternalNameOrNull(bazaarItem.displayName) ?: return "" - - var having = 0 - for (slot in chest.inventorySlots) { - if (slot == null) continue - if (slot.slotNumber == slot.slotIndex) continue - val stack = slot.stack ?: continue - if (internalName == stack.getInternalName()) { - having += stack.stackSize + var having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName } + lastClickedItem?.let { + if (it.getInternalName() == internalName) { + having += it.stackSize } } - if (having <= 0) return "" val data = internalName.getBazaarData() ?: return "" @@ -73,5 +71,11 @@ class BazaarBestSellMethod { SkyHanniMod.feature.bazaar.bestSellMethodPos.renderString(display, posLabel = "Bazaar Best Sell Method") } + @SubscribeEvent(priority = EventPriority.HIGH) + fun onStackClick(event: SlotClickEvent) { + lastClickedItem = event.slot?.stack + nextCloseWillResetItem = false + } + private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.bestSellMethod }
\ No newline at end of file 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..92f5ec78f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt @@ -0,0 +1,57 @@ +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 io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class BazaarOpenPriceWebsite { + private val config get() = SkyHanniMod.feature.bazaar + + 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.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 + val name = getSkyBlockBzName(lastItem) + OSUtils.openBrowser("https://www.skyblock.bz/product/$name") + } + } + + 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 |