Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Move more events to SkyHanniEvent #3174

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.lang.reflect.Method

@SkyHanniModule
Expand Down Expand Up @@ -46,8 +45,8 @@ object SkyHanniEvents {
.addListener(method, instance, options)
}

@SubscribeEvent
fun onRepoLoad(event: RepositoryReloadEvent) {
@HandleEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<DisabledEventsJson>("DisabledEvents")
disabledHandlers = data.disabledHandlers
disabledHandlerInvokers = data.disabledInvokers
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
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/FameRanks.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.FameRankJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object FameRanks {
Expand All @@ -12,7 +12,7 @@ object FameRanks {

fun getFameRankByNameOrNull(name: String) = fameRanks[name]

@SubscribeEvent
@HandleEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val ranks = event.getConstant<FameRankJson>("FameRank")
fameRanks = ranks.fameRank.values.map { FameRank(it.name, it.fameRequired, it.bitsMultiplier, it.votes) }
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 All @@ -15,7 +16,6 @@ import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.SoundUtils.playSound
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object GardenCropMilestones {
Expand Down Expand Up @@ -49,8 +49,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 Expand Up @@ -192,7 +192,7 @@ object GardenCropMilestones {
return (progress - startCrops).toDouble() / (end - startCrops)
}

@SubscribeEvent
@HandleEvent
fun onRepoReload(event: RepositoryReloadEvent) {
cropMilestoneData = event.getConstant<GardenJson>("Garden").cropMilestones
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
Expand All @@ -24,7 +25,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import kotlinx.coroutines.launch
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object GardenCropMilestonesCommunityFix {
Expand All @@ -40,7 +40,7 @@ object GardenCropMilestonesCommunityFix {
private var showWrongData = false
private var showWhenAllCorrect = false

@SubscribeEvent
@HandleEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<GardenJson>("Garden")
val map = data.cropMilestoneCommunityHelp
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
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ object IslandGraphs {
"Glacite Tunnels|Dwarven Base Camp|Great Glacite Lake|Fossil Research Center",
)

@SubscribeEvent
@HandleEvent
fun onRepoReload(event: RepositoryReloadEvent) {
if (!LorenzUtils.inSkyBlock) 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
5 changes: 2 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.LocationFixJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside
import net.minecraft.util.AxisAlignedBB
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object LocationFixData {
Expand All @@ -16,7 +15,7 @@ object LocationFixData {
private data class LocationFix(val area: AxisAlignedBB, val realLocation: String)

// priority set to low so that IslandType can load their island names from repo earlier
@SubscribeEvent(priority = EventPriority.LOW)
@HandleEvent(priority = HandleEvent.LOW)
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<LocationFixJson>("LocationFix")
locationFixes.clear()
Expand Down
6 changes: 3 additions & 3 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 Expand Up @@ -335,7 +335,7 @@ object MaxwellAPI {
private fun isEnabled() = LorenzUtils.inSkyBlock && !LorenzUtils.isOnAlphaServer && storage != null

// Load powers from repo
@SubscribeEvent
@HandleEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<MaxwellPowersJson>("MaxwellPowers")
powers = data.powers
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
Loading
Loading