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: Migrate to skyhanni events #1 #3025

Merged
merged 2 commits into from
Dec 6, 2024
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
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.api

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.events.CollectionUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
Expand Down Expand Up @@ -99,7 +100,7 @@ object CollectionAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onItemAdd(event: ItemAddEvent) {
if (event.source == ItemAddManager.Source.COMMAND) return
val internalName = event.internalName
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.api

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuSkillLevelJson
import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
Expand Down Expand Up @@ -104,7 +105,7 @@ object SkillAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onActionBarUpdate(event: ActionBarUpdateEvent) {
val actionBar = event.actionBar.removeColor()
val components = SPACE_SPLITTER.splitToList(actionBar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package at.hannibal2.skyhanni.api.event
*/
abstract class SkyHanniEvent protected constructor() {

// TODO: This should only be accessible in the cancellable interface
var isCancelled: Boolean = false
private set

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/ActionBarData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object ActionBarData {
val message = original.formattedText.stripHypixelMessage()
actionBar = message
val actionBarEvent = ActionBarUpdateEvent(actionBar, event.message)
actionBarEvent.postAndCatch()
actionBarEvent.post()
if (event.message.formattedText != actionBarEvent.chatComponent.formattedText) {
event.message = actionBarEvent.chatComponent
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.ActionBarValueUpdateEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.intellij.lang.annotations.Language

enum class ActionBarStatsData(@Language("RegExp") rawPattern: String) {
Expand Down Expand Up @@ -45,7 +45,7 @@ enum class ActionBarStatsData(@Language("RegExp") rawPattern: String) {
entries.forEach { it.pattern }
}

@SubscribeEvent
@HandleEvent
fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!LorenzUtils.inSkyBlock) return

Expand All @@ -57,7 +57,7 @@ enum class ActionBarStatsData(@Language("RegExp") rawPattern: String) {
ActionBarValueUpdateEvent(data)
} else null
}
}.forEach { it.postAndCatch() }
}.forEach { it.post() }
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ object BitsAPI {
fun hasCookieBuff() = cookieBuffTime?.isInFuture() ?: false

private fun sendBitsGainEvent(difference: Int) =
BitsUpdateEvent.BitsGain(bits, bitsAvailable, difference).postAndCatch()
BitsUpdateEvent.BitsGain(bits, bitsAvailable, difference).post()

private fun sendBitsSpentEvent() = BitsUpdateEvent.BitsSpent(bits, bitsAvailable).postAndCatch()
private fun sendBitsAvailableGainedEvent() = BitsUpdateEvent.BitsAvailableGained(bits, bitsAvailable).postAndCatch()
private fun sendBitsSpentEvent() = BitsUpdateEvent.BitsSpent(bits, bitsAvailable).post()
private fun sendBitsAvailableGainedEvent() = BitsUpdateEvent.BitsAvailableGained(bits, bitsAvailable).post()

fun isEnabled() = LorenzUtils.inSkyBlock && !LorenzUtils.isOnAlphaServer && profileStorage != null

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/BossbarData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ object BossbarData {
if (previousServerBossbar.isNotEmpty()) previousServerBossbar = ""

bossbar = bossbarLine
BossbarUpdateEvent(bossbarLine).postAndCatch()
BossbarUpdateEvent(bossbarLine).post()
}
}
6 changes: 3 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object EntityData {
val oldMaxHealth = maxHealthMap.getOrDefault(id, -1)
if (oldMaxHealth != maxHealth) {
maxHealthMap[id] = maxHealth
EntityMaxHealthUpdateEvent(entity, maxHealth.derpy()).postAndCatch()
EntityMaxHealthUpdateEvent(entity, maxHealth.derpy()).post()
}
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ object EntityData {
val health = (it.`object` as Float).toInt()
if (entity is EntityWither && health == 300 && entityId < 0) return
if (entity is EntityLivingBase) {
EntityHealthUpdateEvent(entity, health.derpy()).postAndCatch()
EntityHealthUpdateEvent(entity, health.derpy()).post()
}
}
}
Expand All @@ -107,7 +107,7 @@ object EntityData {
@JvmStatic
fun getHealthDisplay(text: String) = healthDisplayCache.getOrPut(text) {
val event = EntityHealthDisplayEvent(text)
event.postAndCatch()
event.post()
event.text
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt
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.ConfigFileType
import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson.PlayerFriends.Friend
Expand Down Expand Up @@ -74,7 +75,7 @@ object FriendAPI {
FriendsJson.PlayerFriends().also { it.friends = mutableMapOf() }
}.friends

@SubscribeEvent
@HandleEvent
fun onHypixelJoin(event: HypixelJoinEvent) {
if (SkyHanniMod.friendsData.players == null) {
SkyHanniMod.friendsData.players = mutableMapOf()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object GuiEditManager {
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
lastMovedGui?.let {
GuiPositionMovedEvent(it).postAndCatch()
GuiPositionMovedEvent(it).post()
lastMovedGui = null
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ object HypixelData {
if (!LorenzUtils.onHypixel) {
checkHypixel()
if (LorenzUtils.onHypixel) {
HypixelJoinEvent().postAndCatch()
HypixelJoinEvent.post()
SkyHanniMod.repo.displayRepoStatus(true)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.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.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.ItemAddEvent
Expand Down Expand Up @@ -54,7 +55,7 @@ object ItemAddManager {
}
}

@SubscribeEvent
@HandleEvent
fun onSackChange(event: SackChangeEvent) {
if (!LorenzUtils.inSkyBlock) return

Expand All @@ -70,7 +71,7 @@ object ItemAddManager {
superCraftedItems.clear()
}

@SubscribeEvent
@HandleEvent
fun onItemAdd(event: ItemAddInInventoryEvent) {
if (!LorenzUtils.inSkyBlock) return

Expand All @@ -85,7 +86,7 @@ object ItemAddManager {
}

private fun Source.addItem(internalName: NEUInternalName, amount: Int) {
ItemAddEvent(internalName, amount, this).postAndCatch()
ItemAddEvent(internalName, amount, this).post()
}

private var lastDiceRoll = SimpleTimeMark.farPast()
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.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.events.DrawScreenAfterEvent
import at.hannibal2.skyhanni.events.GuiRenderItemEvent
import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent
Expand All @@ -14,13 +15,11 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object ItemTipHelper {

@SubscribeEvent
@HandleEvent
fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost) {
val stack = event.stack ?: return
if (!LorenzUtils.inSkyBlock || stack.stackSize != 1) return
Expand All @@ -39,7 +38,7 @@ object ItemTipHelper {
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
@HandleEvent(priority = HandleEvent.HIGHEST)
fun onRenderInventoryItemOverlayPost(event: DrawScreenAfterEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!SkyHanniDebugsAndTests.globalRender) return
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object MinecraftData {
}
InventoryUtils.itemInHandId = newItem
InventoryUtils.latestItemInHand = hand
ItemInHandChangeEvent(newItem, oldItem).postAndCatch()
ItemInHandChangeEvent(newItem, oldItem).post()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ object MiningAPI {

}

@SubscribeEvent
@HandleEvent
fun onPlayerDeath(event: PlayerDeathEvent) {
if (event.name == LorenzUtils.getPlayerName()) {
updateCold(0)
Expand Down Expand Up @@ -477,7 +477,7 @@ object MiningAPI {
// Hypixel sends cold data once in scoreboard even after resetting it
if (cold == 0 && lastColdUpdate.passedSince() < 1.seconds) return
lastColdUpdate = SimpleTimeMark.now()
ColdUpdateEvent(newCold).postAndCatch()
ColdUpdateEvent(newCold).post()
cold = newCold
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ object OwnInventoryData {

if (internalName.startsWith("MAP-")) return

ItemAddInInventoryEvent(internalName, add).postAndCatch()
ItemAddInInventoryEvent(internalName, add).post()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object PlayerDeathManager {
deathMessagePattern.matchMatcher(message) {
val name = group("name")
val reason = group("reason").removeColor()
PlayerDeathEvent(name, reason, event).postAndCatch()
PlayerDeathEvent(name, reason, event).post()
}
}
}
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.SackData
import at.hannibal2.skyhanni.config.storage.PlayerSpecificStorage
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage
Expand Down Expand Up @@ -125,7 +126,7 @@ object ProfileStorageData {
ConfigLoadEvent().postAndCatch()
}

@SubscribeEvent
@HandleEvent
fun onHypixelJoin(event: HypixelJoinEvent) {
val playerUuid = LorenzUtils.getRawPlayerUuid()
playerSpecific = SkyHanniMod.feature.storage.players.getOrPut(playerUuid) { PlayerSpecificStorage() }
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ object QuiverAPI {
}

private fun postUpdateEvent(arrowType: ArrowType? = currentArrow) {
QuiverUpdateEvent(arrowType, currentAmount).postAndCatch()
QuiverUpdateEvent(arrowType, currentAmount).post()
}

@SubscribeEvent
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ object SackAPI {
}
val sackEvent = SackChangeEvent(sackChanges, otherItemsAdded, otherItemsRemoved)
updateSacks(sackEvent)
sackEvent.postAndCatch()
sackEvent.post()
if (chatConfig.hideSacksChange) {
event.blockedReason = "sacks_change"
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/SkillExperience.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.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
Expand Down Expand Up @@ -31,7 +32,7 @@ object SkillExperience {
skillExp.clear()
}

@SubscribeEvent
@HandleEvent
fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!LorenzUtils.inSkyBlock) return

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object TrackerManager {
}

commandEditTrackerSuccess = false
ItemAddEvent(internalName, amount, ItemAddManager.Source.COMMAND).postAndCatch()
ItemAddEvent(internalName, amount, ItemAddManager.Source.COMMAND).post()
if (!commandEditTrackerSuccess) {
ChatUtils.userError("Could not edit the Item Tracker! Does this item belong to this tracker? Is the tracker active right now?")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ object MobDetection {
}
}

@SubscribeEvent
@HandleEvent
fun onEntityHealthUpdateEvent(event: EntityHealthUpdateEvent) {
when {
event.entity is EntityBat && event.health == 6 -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import net.minecraft.util.ChatComponentText
import net.minecraft.util.IChatComponent

class ActionBarUpdateEvent(var actionBar: String, var chatComponent: IChatComponent) : LorenzEvent() {
class ActionBarUpdateEvent(var actionBar: String, var chatComponent: IChatComponent) : SkyHanniEvent() {
fun changeActionBar(newText: String) {
chatComponent = ChatComponentText(newText)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.data.ActionBarStatsData

class ActionBarValueUpdateEvent(val updated: ActionBarStatsData) : LorenzEvent()
class ActionBarValueUpdateEvent(val updated: ActionBarStatsData) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.utils.NEUInternalName

class BazaarOpenedProductEvent(val openedProduct: NEUInternalName?, val inventoryOpenEvent: InventoryFullyOpenedEvent) :
LorenzEvent()
class BazaarOpenedProductEvent(val openedProduct: NEUInternalName?, val inventoryOpenEvent: InventoryFullyOpenedEvent) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.events

open class BitsUpdateEvent(val bits: Int, val bitsAvailable: Int, val difference: Int = 0) : LorenzEvent() {
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

open class BitsUpdateEvent(val bits: Int, val bitsAvailable: Int, val difference: Int = 0) : SkyHanniEvent() {
class BitsGain(bits: Int, bitsAvailable: Int, difference: Int) : BitsUpdateEvent(bits, bitsAvailable, difference)
class BitsSpent(bits: Int, bitsAvailable: Int) : BitsUpdateEvent(bits, bitsAvailable)
class BitsAvailableGained(bits: Int, bitsAvailable: Int) : BitsUpdateEvent(bits, bitsAvailable)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.features.combat.damageindicator.EntityData

class BossHealthChangeEvent(val entityData: EntityData, val lastHealth: Long, val health: Long, val maxHealth: Long) : LorenzEvent()
class BossHealthChangeEvent(val entityData: EntityData, val lastHealth: Long, val health: Long, val maxHealth: Long) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package at.hannibal2.skyhanni.events

class BossbarUpdateEvent(val bossbar: String) : LorenzEvent()
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

class BossbarUpdateEvent(val bossbar: String) : SkyHanniEvent()
Loading
Loading