Skip to content

Commit

Permalink
Backend: Migrate to skyhanni events #2 (#3039)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored Dec 10, 2024
1 parent b218dbd commit 87b7fe5
Show file tree
Hide file tree
Showing 212 changed files with 438 additions and 380 deletions.
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object CollectionAPI {
"Mushroom" to "RED_MUSHROOM".toInternalName(),
)

@SubscribeEvent
@HandleEvent
fun onProfileJoin(event: ProfileJoinEvent) {
collectionValue.clear()
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.api

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.SackAPI
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
Expand Down Expand Up @@ -124,15 +125,15 @@ object GetFromSackAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onMessageToServer(event: MessageSendToServerEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.queuedGFS && !config.bazaarGFS) return
if (!event.isCommand(commandsWithSlash)) return
val replacedEvent = GetFromSacksTabComplete.handleUnderlineReplace(event)
queuedHandler(replacedEvent)
bazaarHandler(replacedEvent)
if (replacedEvent.isCanceled) {
if (replacedEvent.isCancelled) {
event.cancel()
return
}
Expand All @@ -159,7 +160,7 @@ object GetFromSackAPI {
}

private fun bazaarHandler(event: MessageSendToServerEvent) {
if (event.isCanceled) return
if (event.isCancelled) return
if (!config.bazaarGFS || LorenzUtils.noTradeMode) return
lastItemStack = commandValidator(event.splitMessage.drop(1)).second
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/api/ReforgeAPI.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.jsonobjects.repo.neu.NeuReforgeJson
import at.hannibal2.skyhanni.data.model.SkyblockStat
import at.hannibal2.skyhanni.data.model.SkyblockStatList
Expand All @@ -20,7 +21,6 @@ import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object ReforgeAPI {
Expand Down Expand Up @@ -151,7 +151,7 @@ object ReforgeAPI {
override fun toString(): String = "Reforge $name"
}

@SubscribeEvent
@HandleEvent
fun onNeuRepoReload(event: NeuRepositoryReloadEvent) {
val reforgeStoneData = event.readConstant<Map<String, NeuReforgeJson>>("reforgestones", reforgeGson).values
val reforgeData = event.readConstant<Map<String, NeuReforgeJson>>("reforges", reforgeGson).values
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ object SkillAPI {
skillMultiplierPattern -> handleSkillPatternMultiplier(matcher, skillType, skillInfo)
}

SkillExpGainEvent(skillType, matcher.group("gained").formatDouble()).postAndCatch()
SkillExpGainEvent(skillType, matcher.group("gained").formatDouble()).post()

showDisplay = true
lastUpdate = SimpleTimeMark.now()
Expand All @@ -139,7 +139,7 @@ object SkillAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onNEURepoReload(event: NeuRepositoryReloadEvent) {
val data = event.readConstant<NeuSkillLevelJson>("leveling")

Expand Down Expand Up @@ -274,7 +274,7 @@ object SkillAPI {
calculateSkillLevel(totalXp, cap)

if (skillInfo.overflowLevel > 60 && levelOverflow == skillInfo.overflowLevel + 1)
SkillOverflowLevelUpEvent(skillType, skillInfo.overflowLevel, levelOverflow).postAndCatch()
SkillOverflowLevelUpEvent(skillType, skillInfo.overflowLevel, levelOverflow).post()

skillInfo.apply {
this.level = level
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package at.hannibal2.skyhanni.events
package at.hannibal2.skyhanni.api.enoughupdates

import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish
import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelPlayerApiJson
import at.hannibal2.skyhanni.events.NeuProfileDataLoadedEvent
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.NumberUtil.isInt
Expand Down Expand Up @@ -71,6 +73,6 @@ object NeuEventWrappers {

@SubscribeEvent
fun onNeuRepoReload(event: RepositoryReloadEvent) {
NeuRepositoryReloadEvent().postAndCatch()
NeuRepositoryReloadEvent.post()
}
}
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/BitsAPI.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.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.FameRanks.getFameRankByNameOrNull
import at.hannibal2.skyhanni.events.BitsUpdateEvent
Expand Down Expand Up @@ -187,7 +188,7 @@ object BitsAPI {
"^§aCommunity Shop|§eFame Rank$",
)

@SubscribeEvent
@HandleEvent
fun onScoreboardChange(event: ScoreboardUpdateEvent) {
if (!isEnabled()) return
for (line in event.added) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/BlockData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ object BlockData {
if (event.packet is S23PacketBlockChange) {
val blockPos = event.packet.blockPosition ?: return
val blockState = event.packet.blockState ?: return
ServerBlockChangeEvent(blockPos, blockState).postAndCatch()
ServerBlockChangeEvent(blockPos, blockState).post()
} else if (event.packet is S22PacketMultiBlockChange) {
for (block in event.packet.changedBlocks) {
ServerBlockChangeEvent(block.pos, block.blockState).postAndCatch()
ServerBlockChangeEvent(block.pos, block.blockState).post()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object ChatManager {
trimmedMessage,
trimmedMessage.split(" "),
originatingModContainer
).postAndCatch()
).post()
) {
event.cancel()
messageHistory[IdentityCharacteristics(component)] = result.copy(actionKind = ActionKind.OUTGOING_BLOCKED)
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.InventoryUpdatedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
Expand Down Expand Up @@ -28,7 +29,7 @@ object CropAccessoryData {
private var accessoryInBag = CropAccessory.NONE
private var accessoryInInventory = CropAccessory.NONE

@SubscribeEvent
@HandleEvent
fun onProfileJoin(event: ProfileJoinEvent) {
accessoryInBag = CropAccessory.NONE
accessoryInInventory = CropAccessory.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object EntityMovementData {
}
}

@SubscribeEvent
@HandleEvent
fun onIslandChange(event: IslandChangeEvent) {
val nextData = nextTeleport ?: return
if (nextData.island != event.newIsland) 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
@@ -1,10 +1,10 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.enoughupdates.NEURenderEvent
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.NEURenderEvent
import at.hannibal2.skyhanni.events.minecraft.ClientDisconnectEvent
import at.hannibal2.skyhanni.features.inventory.wardrobe.CustomWardrobeKeybinds
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.api.HotmAPI
import at.hannibal2.skyhanni.api.HotmAPI.MayhemPerk
import at.hannibal2.skyhanni.api.HotmAPI.SkymallPerk
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage
import at.hannibal2.skyhanni.data.jsonobjects.local.HotmTree
import at.hannibal2.skyhanni.data.model.TabWidget
Expand Down Expand Up @@ -690,7 +691,7 @@ enum class HotmData(
}
}

@SubscribeEvent
@HandleEvent
fun onScoreboardUpdate(event: ScoreboardUpdateEvent) {
if (!LorenzUtils.inSkyBlock) return

Expand Down Expand Up @@ -726,7 +727,7 @@ enum class HotmData(
}
}

@SubscribeEvent
@HandleEvent
fun onWidgetUpdate(event: WidgetUpdateEvent) {
if (!event.isWidget(TabWidget.POWDER)) return
event.lines.forEach {
Expand Down Expand Up @@ -780,14 +781,14 @@ enum class HotmData(
}
}

@SubscribeEvent
fun onWorldSwitch(event: IslandChangeEvent) {
@HandleEvent
fun onIslandChange(event: IslandChangeEvent) {
if (HotmAPI.mineshaftMayhem == null) return
HotmAPI.mineshaftMayhem = null
ChatUtils.debug("resetting mineshaftMayhem")
}

@SubscribeEvent
@HandleEvent
fun onProfileSwitch(event: ProfileJoinEvent) {
HotmAPI.PowderType.entries.forEach {
if (it.getStorage() == null) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ object HypixelData {
hasScoreboardUpdated = false
}

@SubscribeEvent
@HandleEvent
fun onScoreboardUpdate(event: ScoreboardUpdateEvent) {
hasScoreboardUpdated = true
}
Expand All @@ -369,14 +369,14 @@ object HypixelData {
val newProfile = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim()
if (profileName == newProfile) return
profileName = newProfile
ProfileJoinEvent(newProfile).postAndCatch()
ProfileJoinEvent(newProfile).post()
}
if (message.startsWith("you are playing on profile:")) {
val newProfile = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim()
ProfileStorageData.profileJoinMessage()
if (profileName == newProfile) return
profileName = newProfile
ProfileJoinEvent(newProfile).postAndCatch()
ProfileJoinEvent(newProfile).post()
}
}

Expand All @@ -387,7 +387,7 @@ object HypixelData {
if (RiftAPI.inRift()) newProfile = newProfile.reversed()
if (profileName == newProfile) return
profileName = newProfile
ProfileJoinEvent(newProfile).postAndCatch()
ProfileJoinEvent(newProfile).post()
}
}

Expand Down Expand Up @@ -444,7 +444,7 @@ object HypixelData {
}
}

@SubscribeEvent
@HandleEvent
fun onTabListUpdate(event: WidgetUpdateEvent) {
when (event.widget) {
TabWidget.AREA -> checkIsland(event)
Expand All @@ -458,7 +458,7 @@ object HypixelData {

UtilsPatterns.tabListProfilePattern.firstMatcher(TabListData.getTabList()) {
profileName = group("profile").lowercase()
ProfileJoinEvent(profileName).postAndCatch()
ProfileJoinEvent(profileName).post()
}
}

Expand Down Expand Up @@ -538,7 +538,7 @@ object HypixelData {
if (skyBlockIsland != newIsland) {
val oldIsland = skyBlockIsland
skyBlockIsland = newIsland
IslandChangeEvent(newIsland, oldIsland).postAndCatch()
IslandChangeEvent(newIsland, oldIsland).post()

if (newIsland == IslandType.UNKNOWN) {
ChatUtils.debug("Unknown island detected: '$foundIsland'")
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 @@ -143,7 +143,7 @@ object IslandGraphs {
loadIsland(LorenzUtils.skyBlockIsland)
}

@SubscribeEvent
@HandleEvent
fun onIslandChange(event: IslandChangeEvent) {
if (currentIslandGraph != null) return
if (event.newIsland == IslandType.NONE) 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
Expand Up @@ -25,7 +25,7 @@ object ItemTipHelper {
if (!LorenzUtils.inSkyBlock || stack.stackSize != 1) return

val itemTipEvent = RenderItemTipEvent(stack, mutableListOf())
itemTipEvent.postAndCatch()
itemTipEvent.post()

if (itemTipEvent.renderObjects.isEmpty()) return

Expand Down Expand Up @@ -59,7 +59,7 @@ object ItemTipHelper {
val stack = slot.stack ?: continue

val itemTipEvent = RenderInventoryItemTipEvent(inventoryName, slot, stack)
itemTipEvent.postAndCatch()
itemTipEvent.post()
val stackTip = itemTipEvent.stackTip
if (stackTip.isEmpty()) continue

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ object MinecraftData {

@HandleEvent(receiveCancelled = true)
fun onPacket(event: PacketReceivedEvent) {
val packet = event.packet
when (packet) {
when (val packet = event.packet) {
is S29PacketSoundEffect -> {
if (PlaySoundEvent(
packet.soundName,
LorenzVec(packet.x, packet.y, packet.z),
packet.pitch,
packet.volume
).postAndCatch()
packet.volume,
).post()
) {
event.cancel()
}
}

is S2APacketParticles -> {
if (ReceiveParticleEvent(
packet.particleType!!,
Expand All @@ -55,6 +55,7 @@ object MinecraftData {
event.cancel()
}
}

is S32PacketConfirmTransaction -> {
totalServerTicks++
ServerTickEvent.post()
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ object MiningAPI {

fun inColdIsland() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT)

@SubscribeEvent
@HandleEvent
fun onScoreboardChange(event: ScoreboardUpdateEvent) {
if (!inCustomMiningIsland()) return

Expand Down Expand Up @@ -256,7 +256,7 @@ object MiningAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onPlaySound(event: PlaySoundEvent) {
if (!inCustomMiningIsland()) return
if (event.soundName == "random.explode" && lastPickobulusUse.passedSince() < 5.seconds) {
Expand Down Expand Up @@ -300,7 +300,7 @@ object MiningAPI {
}
}

@SubscribeEvent
@HandleEvent
fun onBlockChange(event: ServerBlockChangeEvent) {
if (!inCustomMiningIsland()) return
val oldState = event.oldState
Expand Down Expand Up @@ -369,7 +369,7 @@ object MiningAPI {
updateLocation()
}

@SubscribeEvent
@HandleEvent
fun onIslandChange(event: IslandChangeEvent) {
updateLocation()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object OwnInventoryData {
val slot = packet.func_149173_d()
val item = packet.func_149174_e() ?: return
DelayedRun.runNextTick {
OwnInventoryItemUpdateEvent(item, slot).postAndCatch()
OwnInventoryItemUpdateEvent(item, slot).post()
}
}
}
Expand Down
Loading

0 comments on commit 87b7fe5

Please sign in to comment.