diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-04-05 10:56:09 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 10:56:09 +1100 |
commit | 940b961edc0bea93fafa99764454196b0d47e42b (patch) | |
tree | c26528128271c5a008cc55d8387231862efec622 /src/main/java | |
parent | d991a496edc2181806e56dd5aea07161349a4e87 (diff) | |
download | skyhanni-940b961edc0bea93fafa99764454196b0d47e42b.tar.gz skyhanni-940b961edc0bea93fafa99764454196b0d47e42b.tar.bz2 skyhanni-940b961edc0bea93fafa99764454196b0d47e42b.zip |
Backend: Use only one inventory close event (#1184)
* use only one inventory close event
* fix InventoryCloseEvent not getting called when closing player inventory, not fully opened inventories, and sometimes leaving inventories by opening other mod menus
* used event in minion collection, and renamed functions
---------
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
11 files changed, 15 insertions, 41 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt index 601fafb12..498d87d10 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.data -import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -42,7 +42,7 @@ class ItemAddManager { } @SubscribeEvent - fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) { + fun onInventoryClose(event: InventoryCloseEvent) { if (inSackInventory) { inSackInventory = false lastSackInventoryLeave = SimpleTimeMark.now() diff --git a/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt index 72395b4fc..cfe08927e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt @@ -24,10 +24,8 @@ object OtherInventoryData { } fun close(reopenSameName: Boolean = false) { - currentInventory?.let { - InventoryCloseEvent(it, reopenSameName).postAndCatch() - currentInventory = null - } + InventoryCloseEvent(reopenSameName).postAndCatch() + currentInventory = null } @SubscribeEvent @@ -50,8 +48,7 @@ object OtherInventoryData { val windowId = packet.windowId val title = packet.windowTitle.unformattedText val slotCount = packet.slotCount - val reopenSameName = title == currentInventory?.title - close(reopenSameName) + close(reopenSameName = title == currentInventory?.title) currentInventory = Inventory(windowId, title, slotCount) acceptItems = true diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt index edc07287a..759254ff6 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent @@ -106,7 +107,7 @@ class OwnInventoryData { } @SubscribeEvent - fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) { + fun onInventoryClose(event: InventoryCloseEvent) { val item = Minecraft.getMinecraft().thePlayer.inventory.itemStack ?: return val internalNameOrNull = item.getInternalNameOrNull() ?: return ignoreItem(500.milliseconds) { it == internalNameOrNull } diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt index 7b94efd55..70e87a53e 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt @@ -1,12 +1,3 @@ package at.hannibal2.skyhanni.events -import at.hannibal2.skyhanni.data.OtherInventoryData -import net.minecraft.item.ItemStack - -class InventoryCloseEvent(val inventory: OtherInventoryData.Inventory, val reopenSameName: Boolean) : LorenzEvent() { - - val inventoryId: Int by lazy { inventory.windowId } - val inventoryName: String by lazy { inventory.title } - val inventorySize: Int by lazy { inventory.slotCount } - val inventoryItems: Map<Int, ItemStack> by lazy { inventory.items } -} +class InventoryCloseEvent(val reopenSameName: Boolean) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index db00be611..8f44e5caa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.CropClickEvent import at.hannibal2.skyhanni.events.GardenToolChangeEvent -import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PacketEvent @@ -87,7 +87,7 @@ object GardenAPI { } @SubscribeEvent - fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + fun onInventoryClose(event: InventoryCloseEvent) { if (!inGarden()) return checkItemInHand() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index 36a2779a2..e1a939d08 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.garden.contest import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.FarmingContestEvent -import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent @@ -102,11 +101,6 @@ object FarmingContestAPI { } @SubscribeEvent - fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) { - inInventory = false - } - - @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { inInventory = false } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt index abd29aee6..7fb3439f7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.features.garden.farming -import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ChatUtils @@ -20,7 +20,7 @@ class WildStrawberryDyeNotification { val item by lazy { "DYE_WILD_STRAWBERRY".asInternalName() } @SubscribeEvent - fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + fun onInventoryClose(event: InventoryCloseEvent) { lastCloseTime = System.currentTimeMillis() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt index cb409afdb..767ed6d33 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt @@ -94,7 +94,7 @@ class LogBookStats { } @SubscribeEvent - fun onInventoryClosed(event: InventoryCloseEvent) { + fun onInventoryClose(event: InventoryCloseEvent) { inInventory = false } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt index bdc438fce..8401b7f30 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt @@ -45,11 +45,6 @@ class PowerStoneGuideFeatures { } @SubscribeEvent - fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) { - inInventory = false - } - - @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { if (!isEnabled()) return if (!inInventory) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt index 204fc9dd9..b6a1bbc7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SkyblockGuideHighlightFeature.kt @@ -86,9 +86,6 @@ class SkyblockGuideHighlightFeature private constructor( fun onInventoryClose(event: InventoryCloseEvent) = close() @SubscribeEvent - fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) = close() - - @SubscribeEvent fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { if (!isEnabled()) return val current = activeObject ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt index 310b67ebb..858e6d0dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.features.minion -import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.MinionOpenEvent import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent import at.hannibal2.skyhanni.utils.InventoryUtils @@ -30,9 +30,8 @@ class MinionCollectLogic { return map } - // hypixel opens a new inventory after clicking on an item in minion inventory, InventoryCloseEvent isn't usable here @SubscribeEvent - fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + fun onInventoryClose(event: InventoryCloseEvent) { closeMinion() } |