Skip to content

Commit

Permalink
Backend: Migrate to skyhanni events #3 (hannibal002#3058)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored Dec 14, 2024
1 parent a39243d commit c9df512
Show file tree
Hide file tree
Showing 234 changed files with 458 additions and 379 deletions.
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 @@ -215,8 +215,8 @@ object SkillAPI {
}
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Skills")
val storage = storage
if (storage == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object SkyHanniEvents {
disabledHandlerInvokers = data.disabledInvokers
}

@SubscribeEvent
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Events")
event.addIrrelevant {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.hannibal2.skyhanni.config

import at.hannibal2.skyhanni.events.LorenzEvent
import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils.asIntOrNull
Expand Down Expand Up @@ -30,7 +30,7 @@ object ConfigUpdaterMigrator {
val oldVersion: Int,
var movesPerformed: Int,
val dynamicPrefix: Map<String, List<String>>,
) : LorenzEvent() {
) : SkyHanniEvent() {

init {
dynamicPrefix.entries
Expand Down Expand Up @@ -141,7 +141,7 @@ object ConfigUpdaterMigrator {
it.add("lastVersion", JsonPrimitive(i + 1))
},
i, 0, dynamicPrefix
).also { it.postAndCatch() }
).also { it.post() }
logger.log("Transformations scheduled: ${migration.new}")
val mergesPerformed = merge(migration.old, migration.new)
logger.log("Migration done with $mergesPerformed merges and ${migration.movesPerformed} moves performed")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ object BitsAPI {

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

@SubscribeEvent
@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(35, "#profile.bits.bitsToClaim", "#profile.bits.bitsAvailable")
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/data/ElectionAPI.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.ConfigManager
import at.hannibal2.skyhanni.data.ElectionCandidate.Companion.getMayorFromPerk
import at.hannibal2.skyhanni.data.ElectionCandidate.Companion.setAssumeMayorJson
Expand Down Expand Up @@ -242,8 +243,8 @@ object ElectionAPI {

private fun List<MayorCandidate>.bestCandidate() = maxBy { it.votes }

@SubscribeEvent
fun onConfigReload(event: ConfigLoadEvent) {
@HandleEvent
fun onConfigLoad(event: ConfigLoadEvent) {
val config = SkyHanniMod.feature.dev.debug.assumeMayor
config.onToggle {
val mayor = config.get()
Expand All @@ -257,8 +258,8 @@ object ElectionAPI {
}
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Mayor")
event.addIrrelevant {
add("Current Mayor: ${currentMayor?.name ?: "Unknown"}")
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor
import at.hannibal2.skyhanni.events.GuiPositionMovedEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.minecraft.KeyPressEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.utils.ChatUtils
Expand Down Expand Up @@ -38,8 +39,8 @@ object GuiEditManager {
private val currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
private var lastMovedGui: String? = null

@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
@HandleEvent
fun onKeyPress(event: KeyPressEvent) {
if (event.keyCode != SkyHanniMod.feature.gui.keyBindOpen) return
if (event.keyCode == Keyboard.KEY_RETURN) {
ChatUtils.chat("You can't use Enter as a keybind to open the gui editor!")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ enum class HotmData(
}
}

@SubscribeEvent
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("HotM")
event.addIrrelevant {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ object HypixelData {
)
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Server ID")
if (!LorenzUtils.inSkyBlock) {
event.addIrrelevant("not in sb")
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 @@ -436,8 +436,8 @@ object MiningAPI {
pickobulusWaitingForBlock = false
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Mining API")
if (!inCustomMiningIsland()) {
event.addIrrelevant("not in a mining island")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.minecraft.KeyPressEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.GuiRenderUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
Expand All @@ -28,8 +28,8 @@ object NotificationManager {

private const val CLOSE_TEXT = "§c[X] Close"

@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
@HandleEvent
fun onKeyPress(event: KeyPressEvent) {
currentNotification ?: return
if (lastNotificationClosed.passedSince() < 200.milliseconds) return
if (event.keyCode != Keyboard.KEY_X) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object ProfileStorageData {
}

loadProfileSpecific(playerSpecific, sackPlayers, profileName)
ConfigLoadEvent().postAndCatch()
ConfigLoadEvent.post()
}

private fun workaroundIn10SecondsProfileStorage(profileName: String) {
Expand All @@ -72,7 +72,7 @@ object ProfileStorageData {
ErrorManager.skyHanniError("sackPlayers is null in ProfileJoinEvent!")
}
loadProfileSpecific(playerSpecific, sackPlayers, profileName)
ConfigLoadEvent().postAndCatch()
ConfigLoadEvent.post()
}

@HandleEvent
Expand Down Expand Up @@ -122,15 +122,15 @@ object ProfileStorageData {
profileSpecific = playerSpecific.profiles.getOrPut(profileName) { ProfileSpecificStorage() }
sackProfiles = sackProfile.profiles.getOrPut(profileName) { SackData.ProfileSpecific() }
loaded = true
ConfigLoadEvent().postAndCatch()
ConfigLoadEvent.post()
}

@HandleEvent
fun onHypixelJoin(event: HypixelJoinEvent) {
val playerUuid = LorenzUtils.getRawPlayerUuid()
playerSpecific = SkyHanniMod.feature.storage.players.getOrPut(playerUuid) { PlayerSpecificStorage() }
sackPlayers = SkyHanniMod.sackData.players.getOrPut(playerUuid) { SackData.PlayerSpecific() }
ConfigLoadEvent().postAndCatch()
ConfigLoadEvent.post()
}

@SubscribeEvent
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/RenderData.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.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.chroma.ChromaConfig
import at.hannibal2.skyhanni.events.GuiRenderEvent
Expand Down Expand Up @@ -63,7 +64,7 @@ object RenderData {
}

// TODO find better spot for this
@SubscribeEvent
@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.transform(17, "chroma.chromaDirection") { element ->
ConfigUtils.migrateIntToEnum(element, ChromaConfig.Direction::class.java)
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.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.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
Expand Down Expand Up @@ -57,8 +58,8 @@ object SlayerAPI {
}
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Slayer")

if (!hasActiveSlayerQuest()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/TrackerManager.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.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.ItemAddEvent
Expand All @@ -19,7 +20,7 @@ object TrackerManager {
var dirty = false
var commandEditTrackerSuccess = false

@SubscribeEvent
@HandleEvent
fun onConfigLoad(event: ConfigLoadEvent) {
val config = SkyHanniMod.feature.misc.tracker.hideCheapItems
ConditionalUtils.onToggle(config.alwaysShowBest, config.minPrice, config.enabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data.bazaar

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
Expand Down Expand Up @@ -35,8 +36,8 @@ object HypixelBazaarFetcher {
private var failedAttempts = 0
private var nextFetchIsManual = false

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Bazaar Data Fetcher from API")

val data = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import net.minecraft.client.gui.FontRenderer
import net.minecraft.util.ChatComponentText
import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.IChatComponent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

/**
* Listening to the player chat events, and applying custom chat options to them.
Expand Down Expand Up @@ -280,7 +279,7 @@ object PlayerNameFormatter {

fun isEnabled() = LorenzUtils.inSkyBlock && config.enable

@SubscribeEvent
@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.transform(41, "chat.PlayerMessagesConfig.partsOrder") { element ->
val newList = JsonArray()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ object MobDetection {
shouldClear.set(true)
}

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Mob Detection")
if (forceReset) {
event.addData("Mob Detection is manually disabled!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ enum class SkyblockStat(
}
}

@SubscribeEvent
@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(69, "#profile.stats.TRUE_DEFENCE", "#profile.stats.TRUE_DEFENSE")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package at.hannibal2.skyhanni.events

class ConfigLoadEvent : LorenzEvent()
import at.hannibal2.skyhanni.api.event.SkyHanniEvent

object ConfigLoadEvent : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.utils.StringUtils.equalsIgnoreColor

class DebugDataCollectEvent(private val list: MutableList<String>, private val search: String) : LorenzEvent() {
class DebugDataCollectEvent(private val list: MutableList<String>, private val search: String) : SkyHanniEvent() {

var empty = true
private var currentTitle = ""
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package at.hannibal2.skyhanni.events.minecraft

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

class KeyPressEvent(val keyCode: Int) : SkyHanniEvent()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.features.bingo

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.storage.PlayerSpecificStorage.BingoSession
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoData
Expand Down Expand Up @@ -36,8 +37,8 @@ object BingoAPI {
" §.Ⓑ §.Bingo"
)

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
@HandleEvent
fun onDebug(event: DebugDataCollectEvent) {
event.title("Bingo Card")

if (!LorenzUtils.isBingoProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.bingo

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
Expand Down Expand Up @@ -276,7 +277,7 @@ object MinionCraftHelper {
}
}

@SubscribeEvent
@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.transform(26, "#player.bingoSessions") { element ->
for ((_, data) in element.asJsonObject.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ object BingoCardDisplay {
update()
}

@SubscribeEvent
@HandleEvent
fun onConfigLoad(event: ConfigLoadEvent) {
config.hideCommunityGoals.onToggle { update() }
config.nextTipDuration.onToggle { update() }
update()
}

@SubscribeEvent
@HandleEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "bingo", "event.bingo")
}
Expand Down
Loading

0 comments on commit c9df512

Please sign in to comment.