aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-09-21 11:18:41 +0200
committerGitHub <noreply@github.com>2024-09-21 11:18:41 +0200
commit208fc04e7db767abda24fdbae141d60898371d61 (patch)
tree1f40e682a3dec8d6ee673672ca9a0ba493e183a5
parentf298d65f6b3029474f6695ccf3cb6ac5f0400e42 (diff)
downloadskyhanni-208fc04e7db767abda24fdbae141d60898371d61.tar.gz
skyhanni-208fc04e7db767abda24fdbae141d60898371d61.tar.bz2
skyhanni-208fc04e7db767abda24fdbae141d60898371d61.zip
Backend: AreaChangeEvent and Islands in HandleEvent (#2535)
Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/event/HandleEvent.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/skyblock/AreaChangeEvents.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt4
14 files changed, 66 insertions, 30 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt b/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt
index 78769060a..4b4c00852 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt
@@ -130,6 +130,13 @@ class EventHandler<T : SkyHanniEvent> private constructor(val name: String, priv
val invoker: Consumer<Any>,
val options: HandleEvent,
val generic: Class<*>?,
- val onlyOnIslandTypes: Set<IslandType> = options.onlyOnIslands.toSet(),
- )
+ ) {
+ val onlyOnIslandTypes: Set<IslandType> = getIslands(options)
+
+ companion object {
+ private fun getIslands(options: HandleEvent): Set<IslandType> =
+ if (options.onlyOnIslands.isEmpty()) setOf(options.onlyOnIsland)
+ else options.onlyOnIslands.toSet()
+ }
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/api/event/HandleEvent.kt b/src/main/java/at/hannibal2/skyhanni/api/event/HandleEvent.kt
index c07239dc2..a88f7f337 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/event/HandleEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/event/HandleEvent.kt
@@ -12,8 +12,15 @@ annotation class HandleEvent(
/**
* If the event should only be received while on a specific skyblock island.
+ * To specify multiple islands, use [onlyOnIslands] instead.
*/
- vararg val onlyOnIslands: IslandType = [IslandType.ANY],
+ val onlyOnIsland: IslandType = IslandType.ANY,
+
+ /**
+ * If the event should only be received while being on specific skyblock islands.
+ * To specify only one island, use [onlyOnIsland] instead.
+ */
+ vararg val onlyOnIslands: IslandType = [],
/**
* The priority of when the event will be called, lower priority will be called first, see the companion object.
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index 0cd806f57..b48805ef5 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.WidgetUpdateEvent
import at.hannibal2.skyhanni.events.minecraft.ClientDisconnectEvent
+import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent
import at.hannibal2.skyhanni.features.bingo.BingoAPI
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.rift.RiftAPI
@@ -319,8 +320,13 @@ object HypixelData {
loop@ for (line in ScoreboardData.sidebarLinesFormatted) {
skyblockAreaPattern.matchMatcher(line) {
val originalLocation = group("area").removeColor()
- skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation
+ val area = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation
skyBlockAreaWithSymbol = line.trim()
+ if (area != skyBlockArea) {
+ val previousArea = skyBlockArea
+ skyBlockArea = area
+ ScoreboardAreaChangeEvent(area, previousArea).post()
+ }
break@loop
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt b/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt
index 129e1cd95..20dfbb615 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt
@@ -11,9 +11,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object LocationFixData {
- private var locationFixes = mutableListOf<LocationFix>()
+ private var locationFixes = mutableMapOf<IslandType, List<LocationFix>>()
- class LocationFix(val island: IslandType, val area: AxisAlignedBB, val realLocation: String)
+ 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)
@@ -26,11 +26,18 @@ object LocationFixData {
val area = fix.a.axisAlignedTo(fix.b)
val realLocation = fix.realLocation
- locationFixes.add(LocationFix(island, area, realLocation))
+ val list = locationFixes[island]
+
+ val locationFix = LocationFix(area, realLocation)
+
+ if (list == null) locationFixes[island] = listOf(locationFix)
+ else locationFixes[island] = list + locationFix
}
}
- fun fixLocation(skyBlockIsland: IslandType) = locationFixes
- .firstOrNull { skyBlockIsland == it.island && it.area.isPlayerInside() }
- ?.realLocation
+ fun fixLocation(skyBlockIsland: IslandType): String? =
+ locationFixes[skyBlockIsland]
+ ?.find { it.area.isPlayerInside() }
+ ?.realLocation
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
index 758294ffc..35855fc61 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
@@ -1,8 +1,10 @@
package at.hannibal2.skyhanni.data
+import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.BlockClickEvent
import at.hannibal2.skyhanni.events.ColdUpdateEvent
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
+import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
@@ -11,6 +13,7 @@ import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
import at.hannibal2.skyhanni.events.mining.OreMinedEvent
import at.hannibal2.skyhanni.events.player.PlayerDeathEvent
+import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern
import at.hannibal2.skyhanni.features.mining.OreBlock
import at.hannibal2.skyhanni.features.mining.isTitanium
@@ -69,8 +72,6 @@ object MiningAPI {
var currentAreaOreBlocks = setOf<OreBlock>()
private set
- private var lastSkyblockArea: String? = null
-
private val recentClickedBlocks = ConcurrentSet<Pair<LorenzVec, SimpleTimeMark>>()
private val surroundingMinedBlocks = ConcurrentLinkedQueue<Pair<MinedBlock, LorenzVec>>()
private val allowedSoundNames = setOf("dig.glass", "dig.stone", "dig.gravel", "dig.cloth", "random.orb")
@@ -203,10 +204,6 @@ object MiningAPI {
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!inCustomMiningIsland()) return
-
- if (LorenzUtils.lastWorldSwitch.passedSince() < 4.seconds) return
- updateLocation()
-
if (currentAreaOreBlocks.isEmpty()) return
// if somehow you take more than 20 seconds to mine a single block, congrats
@@ -219,6 +216,17 @@ object MiningAPI {
resetOreEvent()
}
+ @HandleEvent
+ fun onAreaChange(event: ScoreboardAreaChangeEvent) {
+ if (!inCustomMiningIsland()) return
+ updateLocation()
+ }
+
+ @SubscribeEvent
+ fun onIslandChange(event: IslandChangeEvent) {
+ updateLocation()
+ }
+
private fun runEvent() {
resetOreEvent()
@@ -287,11 +295,6 @@ object MiningAPI {
}
private fun updateLocation() {
- val currentArea = LorenzUtils.skyBlockArea
- // TODO add area change event with HypixelData.skyBlockArea instead
- if (currentArea == lastSkyblockArea) return
- lastSkyblockArea = currentArea
-
inGlacite = inGlaciteArea()
inTunnels = inGlacialTunnels()
inMineshaft = inMineshaft()
diff --git a/src/main/java/at/hannibal2/skyhanni/events/skyblock/AreaChangeEvents.kt b/src/main/java/at/hannibal2/skyhanni/events/skyblock/AreaChangeEvents.kt
new file mode 100644
index 000000000..b262ea9fb
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/skyblock/AreaChangeEvents.kt
@@ -0,0 +1,6 @@
+package at.hannibal2.skyhanni.events.skyblock
+
+import at.hannibal2.skyhanni.api.event.SkyHanniEvent
+
+// Detect area changes by looking at the scoreboard.
+class ScoreboardAreaChangeEvent(val area: String, val previousArea: String?) : SkyHanniEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt
index b3c9be188..2fee0577e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt
@@ -80,7 +80,7 @@ object ArachneSpawnTimer {
}
}
- @HandleEvent(onlyOnIslands = [IslandType.SPIDER_DEN], priority = HandleEvent.LOW, receiveCancelled = true)
+ @HandleEvent(onlyOnIsland = IslandType.SPIDER_DEN, priority = HandleEvent.LOW, receiveCancelled = true)
fun onPacketReceive(event: PacketReceivedEvent) {
if (!saveNextTickParticles) return
if (searchTime.passedSince() < 3.seconds) return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt
index abe83df8c..ca888392f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt
@@ -16,7 +16,7 @@ object DungeonShadowAssassinNotification {
private val config get() = SkyHanniMod.feature.dungeon
- @HandleEvent(onlyOnIslands = [IslandType.CATACOMBS])
+ @HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onWorldBorderChange(event: PacketReceivedEvent) {
if (!isEnabled()) return
if (DungeonAPI.dungeonFloor?.contains("3") == true && DungeonAPI.inBossRoom) return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt
index 0f0220a76..80d6ea0e0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt
@@ -58,7 +58,7 @@ object GriffinBurrowParticleFinder {
}
}
- @HandleEvent(onlyOnIslands = [IslandType.HUB], priority = HandleEvent.LOW, receiveCancelled = true)
+ @HandleEvent(onlyOnIsland = IslandType.HUB, priority = HandleEvent.LOW, receiveCancelled = true)
fun onPacketReceive(event: PacketReceivedEvent) {
if (!isEnabled()) return
if (!config.burrowsSoopyGuess) return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt
index fbb599d68..2d0e2a809 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt
@@ -222,7 +222,7 @@ object InquisitorWaypointShare {
HypixelCommands.partyChat("x: $x, y: $y, z: $z ")
}
- @HandleEvent(onlyOnIslands = [IslandType.HUB], priority = HandleEvent.LOW, receiveCancelled = true)
+ @HandleEvent(onlyOnIsland = IslandType.HUB, priority = HandleEvent.LOW, receiveCancelled = true)
fun onFirstChatEvent(event: PacketReceivedEvent) {
if (!isEnabled()) return
val packet = event.packet
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
index e188dcfd0..4e80bdbea 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -90,7 +90,7 @@ object GardenAPI {
"BINGHOE",
)
- @HandleEvent(onlyOnIslands = [IslandType.GARDEN])
+ @HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onSendPacket(event: PacketSentEvent) {
if (event.packet !is C09PacketHeldItemChange) return
checkItemInHand()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt
index 7aefb74cd..d49de324c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt
@@ -158,7 +158,7 @@ object PestAPI {
PestUpdateEvent().post()
}
- @HandleEvent(onlyOnIslands = [IslandType.GARDEN])
+ @HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onPestSpawn(event: PestSpawnEvent) {
PestSpawnTimer.lastSpawnTime = SimpleTimeMark.now()
val plotNames = event.plotNames
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt
index d3dd8a27b..23ead6f91 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt
@@ -121,7 +121,7 @@ object PestParticleWaypoint {
++particles
}
- @HandleEvent(onlyOnIslands = [IslandType.GARDEN])
+ @HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onFireWorkSpawn(event: PacketReceivedEvent) {
if (event.packet !is S0EPacketSpawnObject) return
if (!config.hideParticles) return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt
index e709fcda7..66d03745f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt
@@ -56,7 +56,7 @@ object VisitorListener {
}
// TODO make event
- @HandleEvent(onlyOnIslands = [IslandType.GARDEN])
+ @HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onSendEvent(event: PacketSentEvent) {
val packet = event.packet
if (packet !is C02PacketUseEntity) return
@@ -136,7 +136,7 @@ object VisitorListener {
inventory.handleMouseClick_skyhanni(slot, slot.slotIndex, 0, 0)
}
- @HandleEvent(onlyOnIslands = [IslandType.GARDEN])
+ @HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onTooltip(event: ItemHoverEvent) {
if (!GardenAPI.onBarnPlot) return
if (!VisitorAPI.inInventory) return