Skip to content

Commit

Permalink
Backend: Migrate to skyhanni events #1
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Dec 6, 2024
1 parent 0da7414 commit c9fe28e
Show file tree
Hide file tree
Showing 126 changed files with 256 additions and 180 deletions.
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/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 @@ -70,7 +71,7 @@ object ItemAddManager {
superCraftedItems.clear()
}

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

Expand Down
4 changes: 2 additions & 2 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,7 +15,6 @@ 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
Expand All @@ -39,7 +39,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
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()
}
}
}
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
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()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.features.event.diana.BurrowType
import at.hannibal2.skyhanni.utils.LorenzVec

class BurrowDetectEvent(val burrowLocation: LorenzVec, val type: BurrowType) : LorenzEvent()
class BurrowDetectEvent(val burrowLocation: LorenzVec, val type: BurrowType) : SkyHanniEvent()
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/events/BurrowDugEvent.kt
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.utils.LorenzVec

class BurrowDugEvent(val burrowLocation: LorenzVec) : LorenzEvent()
class BurrowDugEvent(val burrowLocation: LorenzVec) : SkyHanniEvent()
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.utils.LorenzVec

class BurrowGuessEvent(val guessLocation: LorenzVec) : LorenzEvent()
class BurrowGuessEvent(val guessLocation: LorenzVec) : SkyHanniEvent()
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/events/ChatHoverEvent.kt
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 net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText

Expand All @@ -12,6 +13,6 @@ import net.minecraft.util.ChatComponentText
* The edited chat component in [GuiChatHook][at.hannibal2.skyhanni.mixins.hooks.GuiChatHook] does not change the actual
* chat component, but rather makes a new one just before rendering.
*/
class ChatHoverEvent(val component: ChatComponentText) : LorenzEvent() {
class ChatHoverEvent(val component: ChatComponentText) : SkyHanniEvent() {
fun getHoverEvent(): HoverEvent = component.chatStyle.chatHoverEvent!!
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package at.hannibal2.skyhanni.events

class ColdUpdateEvent(val cold: Int) : LorenzEvent()
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

class ColdUpdateEvent(val cold: Int) : SkyHanniEvent()
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/events/CropClickEvent.kt
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.ClickType
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.utils.LorenzVec
Expand All @@ -12,4 +13,4 @@ class CropClickEvent(
val blockState: IBlockState,
val clickType: ClickType,
val itemInHand: ItemStack?,
) : LorenzEvent()
) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.features.combat.damageindicator.EntityData
import net.minecraft.entity.EntityLivingBase

class DamageIndicatorDeathEvent(val entity: EntityLivingBase, val data: EntityData) : LorenzEvent()
class DamageIndicatorDeathEvent(val entity: EntityLivingBase, val data: EntityData) : SkyHanniEvent()

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 DamageIndicatorDetectedEvent(val entityData: EntityData) : LorenzEvent()
class DamageIndicatorDetectedEvent(val entityData: EntityData) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package at.hannibal2.skyhanni.events

class DamageIndicatorFinalBossEvent(val id: Int) : LorenzEvent()
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

class DamageIndicatorFinalBossEvent(val id: Int) : SkyHanniEvent()
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfo

class DrawScreenAfterEvent(val mouseX: Int, val mouseY: Int, val ci: CallbackInfo) : LorenzEvent()
class DrawScreenAfterEvent(val mouseX: Int, val mouseY: Int, val ci: CallbackInfo) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package at.hannibal2.skyhanni.events

class DungeonCompleteEvent(val floor: String) : LorenzEvent()
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

class DungeonCompleteEvent(val floor: String) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package at.hannibal2.skyhanni.events

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

@Suppress("UnusedPrivateProperty")
class DungeonEnterEvent(dungeonFloor: String) : LorenzEvent()
class DungeonEnterEvent(dungeonFloor: String) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package at.hannibal2.skyhanni.events

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

@Suppress("UnusedPrivateProperty")
class DungeonStartEvent(dungeonFloor: String) : LorenzEvent()
class DungeonStartEvent(dungeonFloor: String) : SkyHanniEvent()
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 net.minecraft.entity.EntityLivingBase

class EntityHealthUpdateEvent(val entity: EntityLivingBase, val health: Int) : LorenzEvent()
class EntityHealthUpdateEvent(val entity: EntityLivingBase, val health: Int) : SkyHanniEvent()
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 net.minecraft.entity.EntityLivingBase

class EntityMaxHealthUpdateEvent(val entity: EntityLivingBase, val maxHealth: Int) : LorenzEvent()
class EntityMaxHealthUpdateEvent(val entity: EntityLivingBase, val maxHealth: Int) : SkyHanniEvent()
Loading

0 comments on commit c9fe28e

Please sign in to comment.