aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/moe/nea/firmament/events/subscription/Subscription.kt18
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt18
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt49
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt47
5 files changed, 92 insertions, 44 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/events/subscription/Subscription.kt b/src/main/kotlin/moe/nea/firmament/events/subscription/Subscription.kt
new file mode 100644
index 0000000..1e7a6a8
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/events/subscription/Subscription.kt
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.events.subscription
+
+import moe.nea.firmament.events.FirmamentEvent
+import moe.nea.firmament.events.FirmamentEventBus
+
+interface SubscriptionOwner
+
+data class Subscription<T : FirmamentEvent>(
+ val owner: SubscriptionOwner,
+ val invoke: (T) -> Unit,
+ val eventBus: FirmamentEventBus<T>,
+)
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
index a8daf63..669b3c9 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
@@ -10,7 +10,10 @@ package moe.nea.firmament.features
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import moe.nea.firmament.Firmament
+import moe.nea.firmament.annotations.generated.AllSubscriptions
import moe.nea.firmament.events.FeaturesInitializedEvent
+import moe.nea.firmament.events.FirmamentEvent
+import moe.nea.firmament.events.subscription.Subscription
import moe.nea.firmament.features.chat.AutoCompletions
import moe.nea.firmament.features.chat.ChatLinks
import moe.nea.firmament.features.chat.QuickCommands
@@ -80,11 +83,26 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
loadFeature(DebugView)
}
allFeatures.forEach { it.config }
+ subscribeEvents()
FeaturesInitializedEvent.publish(FeaturesInitializedEvent(allFeatures.toList()))
hasAutoloaded = true
}
}
+ private fun subscribeEvents() {
+ AllSubscriptions.provideSubscriptions {
+ subscribeSingleEvent(it)
+ }
+ }
+
+ private fun <T : FirmamentEvent> subscribeSingleEvent(it: Subscription<T>) {
+ if (it.owner in features.values) { // TODO: better check here, somehow. probably implement some interface method
+ it.eventBus.subscribe(false, it.invoke) // TODO: pass through receivesCancelled from the annotation
+ } else {
+ Firmament.logger.error("Ignoring event listener for ${it.eventBus} in ${it.owner}")
+ }
+ }
+
fun loadFeature(feature: FirmamentFeature) {
synchronized(features) {
if (feature.identifier in features) {
diff --git a/src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt b/src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt
index afd36a5..2416fec 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt
@@ -1,14 +1,16 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.features
+import moe.nea.firmament.events.subscription.SubscriptionOwner
import moe.nea.firmament.gui.config.ManagedConfig
-interface FirmamentFeature {
+interface FirmamentFeature : SubscriptionOwner {
val identifier: String
val defaultEnabled: Boolean
get() = true
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt
index aa8982d..b511611 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -7,6 +8,7 @@
package moe.nea.firmament.features.inventory
import net.minecraft.text.Text
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ItemTooltipEvent
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
@@ -26,27 +28,32 @@ object PriceData : FirmamentFeature {
override val config get() = TConfig
override fun onLoad() {
- ItemTooltipEvent.subscribe {
- if (!TConfig.tooltipEnabled && !TConfig.enableKeybinding.isPressed()) {
- return@subscribe
- }
- val sbId = it.stack.skyBlockId
- val bazaarData = HypixelStaticData.bazaarData[sbId]
- val lowestBin = HypixelStaticData.lowestBin[sbId]
- if (bazaarData != null) {
- it.lines.add(Text.literal(""))
- it.lines.add(
- Text.stringifiedTranslatable("firmament.tooltip.bazaar.sell-order", FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1))
- )
- it.lines.add(
- Text.stringifiedTranslatable("firmament.tooltip.bazaar.buy-order", FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1))
- )
- } else if (lowestBin != null) {
- it.lines.add(Text.literal(""))
- it.lines.add(
- Text.stringifiedTranslatable("firmament.tooltip.ah.lowestbin", FirmFormatters.formatCurrency(lowestBin, 1))
- )
- }
+ }
+
+ @Subscribe
+ fun function(it: ItemTooltipEvent) {
+ if (!TConfig.tooltipEnabled && !TConfig.enableKeybinding.isPressed()) {
+ return
+ }
+ val sbId = it.stack.skyBlockId
+ val bazaarData = HypixelStaticData.bazaarData[sbId]
+ val lowestBin = HypixelStaticData.lowestBin[sbId]
+ if (bazaarData != null) {
+ it.lines.add(Text.literal(""))
+ it.lines.add(
+ Text.stringifiedTranslatable("firmament.tooltip.bazaar.sell-order",
+ FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1))
+ )
+ it.lines.add(
+ Text.stringifiedTranslatable("firmament.tooltip.bazaar.buy-order",
+ FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1))
+ )
+ } else if (lowestBin != null) {
+ it.lines.add(Text.literal(""))
+ it.lines.add(
+ Text.stringifiedTranslatable("firmament.tooltip.ah.lowestbin",
+ FirmFormatters.formatCurrency(lowestBin, 1))
+ )
}
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
index 9bf2182..aee985c 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
@@ -20,6 +20,7 @@ import net.minecraft.entity.player.PlayerInventory
import net.minecraft.screen.GenericContainerScreenHandler
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.util.Identifier
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.events.IsSlotProtectedEvent
import moe.nea.firmament.events.SlotRenderEvents
@@ -166,29 +167,31 @@ object SlotLocking : FirmamentFeature {
event.protectSilent()
}
}
- SlotRenderEvents.After.subscribe {
- val isSlotLocked = it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())
- val isUUIDLocked = (it.slot.stack?.skyblockUUID) in (lockedUUIDs ?: setOf())
- if (isSlotLocked || isUUIDLocked) {
- RenderSystem.disableDepthTest()
- it.context.drawSprite(
- it.slot.x, it.slot.y, 0,
- 16, 16,
- MC.guiAtlasManager.getSprite(
- when {
- isSlotLocked ->
- (Identifier("firmament:slot_locked"))
-
- isUUIDLocked ->
- (Identifier("firmament:uuid_locked"))
-
- else ->
- error("unreachable")
- }
- )
+ }
+
+ @Subscribe
+ fun function(it: SlotRenderEvents.After) {
+ val isSlotLocked = it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())
+ val isUUIDLocked = (it.slot.stack?.skyblockUUID) in (lockedUUIDs ?: setOf())
+ if (isSlotLocked || isUUIDLocked) {
+ RenderSystem.disableDepthTest()
+ it.context.drawSprite(
+ it.slot.x, it.slot.y, 0,
+ 16, 16,
+ MC.guiAtlasManager.getSprite(
+ when {
+ isSlotLocked ->
+ (Identifier("firmament:slot_locked"))
+
+ isUUIDLocked ->
+ (Identifier("firmament:uuid_locked"))
+
+ else ->
+ error("unreachable")
+ }
)
- RenderSystem.enableDepthTest()
- }
+ )
+ RenderSystem.enableDepthTest()
}
}
}