Skip to content

Commit

Permalink
Backend: Move more events to SkyHanniEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Jan 7, 2025
1 parent 2797533 commit bf4f2fa
Show file tree
Hide file tree
Showing 134 changed files with 342 additions and 323 deletions.
5 changes: 2 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object CollectionAPI {
Expand Down Expand Up @@ -63,8 +62,8 @@ object CollectionAPI {
collectionValue.clear()
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
val inventoryName = event.inventoryName
if (inventoryName.endsWith(" Collection")) {
val stack = event.inventoryItems[4] ?: return
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object GetFromSackAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
inventoryMap.clear()
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ object SkillAPI {
}
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (event.inventoryName != "Your Skills") return
for (stack in event.inventoryItems.values) {
val lore = stack.getLore()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ object BitsAPI {

fun bitsPerCookie(): Int = (defaultCookieBits * (currentFameRank?.bitsMultiplier ?: 1.0)).toInt()

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return

val stacks = event.inventoryItems
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ object CropAccessoryData {
accessoryInInventory = CropAccessory.NONE
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryUpdatedEvent) {
@HandleEvent
fun onInventoryUpdated(event: InventoryUpdatedEvent) {
if (!accessoryBagNamePattern.matches(event.inventoryName)) return

val items = event.inventoryItems.mapNotNull { it.value }
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/ElectionAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ object ElectionAPI {
}
}

@SubscribeEvent
fun onInventory(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return

if (!calendarGuiPattern.matches(event.inventoryName)) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.model.ComposterUpgrade
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
Expand All @@ -8,13 +9,12 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object GardenComposterUpgradesData {

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!GardenAPI.inGarden()) return
if (event.inventoryName != "Composter Upgrades") return
for (item in event.inventoryItems.values) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
Expand Down Expand Up @@ -49,8 +50,8 @@ object GardenCropMilestones {
return null
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (event.inventoryName != "Crop Milestones") return

for ((_, stack) in event.inventoryItems) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.garden.CropType
Expand Down Expand Up @@ -48,8 +49,8 @@ object GardenCropUpgrades {
}
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!GardenAPI.inGarden()) return
if (event.inventoryName != "Crop Upgrades") return

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object GuiData {
if (preDrawEventCancelled) event.isCanceled = true
}

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
DelayedRun.runNextTick {
if (Minecraft.getMinecraft().currentScreen !is GuiChest) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
Expand All @@ -15,12 +16,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object HighlightOnHoverSlot {
val currentSlots = mutableMapOf<Pair<Int, Int>, List<Int>>()

@SubscribeEvent
@HandleEvent
fun onInventoryOpen(event: InventoryOpenEvent) {
currentSlots.clear()
}

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
currentSlots.clear()
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,16 @@ enum class HotmData(
}
}

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
if (!inInventory) return
inInventory = false
entries.forEach { it.slot = null }
heartItem = null
}

@SubscribeEvent
fun onInventoryFullyOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return
inInventory = inventoryPattern.matches(event.inventoryName)
if (!inInventory) return
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ object ItemAddManager {
private var inSackInventory = false
private var lastSackInventoryLeave = SimpleTimeMark.farPast()

@SubscribeEvent
@HandleEvent
fun onInventoryOpen(event: InventoryOpenEvent) {
if (event.inventoryName.contains("Sack")) {
inSackInventory = true
}
}

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
if (inSackInventory) {
inSackInventory = false
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.MaxwellPowersJson
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
Expand All @@ -24,7 +25,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpace
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.annotations.Expose
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern

Expand Down Expand Up @@ -189,7 +189,7 @@ object MaxwellAPI {
}

// load earlier, so that other features can already use the api in this event
@SubscribeEvent(priority = EventPriority.HIGH)
@HandleEvent(priority = HandleEvent.HIGH)
fun onInventoryOpen(event: InventoryOpenEvent) {
if (!isEnabled()) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ object OtherInventoryData {
}

fun close(reopenSameName: Boolean = false) {
InventoryCloseEvent(reopenSameName).postAndCatch()
InventoryCloseEvent(reopenSameName).post()
currentInventory = null
}

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
lateEvent?.let {
it.postAndCatch()
it.post()
lateEvent = null
}
}
Expand Down Expand Up @@ -95,9 +95,9 @@ object OtherInventoryData {
}

private fun done(inventory: Inventory) {
InventoryFullyOpenedEvent(inventory).postAndCatch()
InventoryFullyOpenedEvent(inventory).post()
inventory.fullyOpenedOnce = true
InventoryUpdatedEvent(inventory).postAndCatch()
InventoryUpdatedEvent(inventory).post()
acceptItems = false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object OwnInventoryData {
}
}

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
val item = Minecraft.getMinecraft().thePlayer.inventory.itemStack ?: return
val internalNameOrNull = item.getInternalNameOrNull() ?: return
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
Expand Down Expand Up @@ -40,7 +39,7 @@ object PurseAPI {
var currentPurse = 0.0
private set

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
inventoryCloseTime = SimpleTimeMark.now()
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.QuiverAPI.currentArrow
import at.hannibal2.skyhanni.data.jsonobjects.repo.ArrowTypeJson
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
Expand Down Expand Up @@ -210,8 +209,8 @@ object QuiverAPI {
return
}

@SubscribeEvent
fun onInventoryFullyLoaded(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
if (!quiverInventoryNamePattern.matches(event.inventoryName)) return

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object SackAPI {
var sackListNames = emptySet<String>()
private set

@SubscribeEvent
@HandleEvent
fun onInventoryClose(event: InventoryCloseEvent) {
inSackInventory = false
isRuneSack = false
Expand All @@ -114,8 +114,8 @@ object SackAPI {
stackList.clear()
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
val inventoryName = event.inventoryName
val isNewInventory = inventoryName != lastOpenedInventory
lastOpenedInventory = inventoryName
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/ScreenData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object ScreenData {
if (wasOpen == isOpen) return
wasOpen = isOpen
if (!wasOpen) {
InventoryCloseEvent(false).postAndCatch()
InventoryCloseEvent(false).post()
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object SkillExperience {
Expand Down Expand Up @@ -47,8 +46,8 @@ object SkillExperience {
}
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (event.inventoryName != "Your Skills") return

for ((_, stack) in event.inventoryItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.intellij.lang.annotations.Language
import java.util.EnumMap
import java.util.regex.Pattern
Expand Down Expand Up @@ -128,8 +127,8 @@ enum class SkyblockStat(
}
}

@SubscribeEvent
fun onInventory(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return
onSkyblockMenu(event)
onStatsMenu(event)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package at.hannibal2.skyhanni.events

class InventoryCloseEvent(val reopenSameName: Boolean) : LorenzEvent()
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

class InventoryCloseEvent(val reopenSameName: Boolean) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.data.OtherInventoryData
import at.hannibal2.skyhanni.utils.PrimitiveItemStack
import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.toPrimitiveStackOrNull
import net.minecraft.item.ItemStack

open class InventoryOpenEvent(private val inventory: OtherInventoryData.Inventory) : LorenzEvent() {
open class InventoryOpenEvent(private val inventory: OtherInventoryData.Inventory) : SkyHanniEvent() {

val inventoryId: Int get() = inventory.windowId
val inventoryName: String get() = inventory.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ object MinionCraftHelper {

private fun isMinionName(itemName: String) = itemName.contains(" Minion ") && !itemName.contains(" Minion Skin")

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
@HandleEvent
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.isBingoProfile) return
if (event.inventoryName != "Crafted Minions") return

Expand Down
Loading

0 comments on commit bf4f2fa

Please sign in to comment.