From f7507f384459b57460af899bf9ceae4f52f1ea21 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 6 Dec 2024 19:27:07 +0100 Subject: refactor: Add DI and packages --- src/main/kotlin/moe/nea/ledger/Ledger.kt | 45 ++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'src/main/kotlin/moe/nea/ledger/Ledger.kt') diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt index a11480f..521fd9d 100644 --- a/src/main/kotlin/moe/nea/ledger/Ledger.kt +++ b/src/main/kotlin/moe/nea/ledger/Ledger.kt @@ -4,6 +4,18 @@ import io.github.notenoughupdates.moulconfig.common.IMinecraft import io.github.notenoughupdates.moulconfig.managed.ManagedConfig import moe.nea.ledger.config.LedgerConfig import moe.nea.ledger.database.Database +import moe.nea.ledger.events.ChatReceived +import moe.nea.ledger.events.LateWorldLoadEvent +import moe.nea.ledger.modules.AuctionHouseDetection +import moe.nea.ledger.modules.BankDetection +import moe.nea.ledger.modules.BazaarDetection +import moe.nea.ledger.modules.BazaarOrderDetection +import moe.nea.ledger.modules.BitsDetection +import moe.nea.ledger.modules.BitsShopDetection +import moe.nea.ledger.modules.DungeonChestDetection +import moe.nea.ledger.modules.MinionDetection +import moe.nea.ledger.modules.NpcDetection +import moe.nea.ledger.utils.DI import net.minecraft.client.Minecraft import net.minecraft.command.CommandBase import net.minecraft.command.ICommandSender @@ -96,22 +108,23 @@ class Ledger { return listOf("moneyledger") } }) - val ledger = LedgerLogger() - val ids = ItemIdProvider() - listOf( - this, - ids, - ledger, - BankDetection(ledger), - BazaarDetection(ledger, ids), - DungeonChestDetection(ledger), - BazaarOrderDetection(ledger, ids), - AuctionHouseDetection(ledger, ids), - BitsDetection(ledger), - BitsShop(ledger), - MinionDetection(ledger), - NpcDetection(ledger, ids), - ).forEach(MinecraftForge.EVENT_BUS::register) + val di = DI() + di.registerSingleton(this) + di.registerInjectableClasses( + LedgerLogger::class.java, + ItemIdProvider::class.java, + BankDetection::class.java, + BazaarDetection::class.java, + DungeonChestDetection::class.java, + BazaarOrderDetection::class.java, + AuctionHouseDetection::class.java, + BitsDetection::class.java, + BitsShopDetection::class.java, + MinionDetection::class.java, + NpcDetection::class.java, + ) + di.instantiateAll() + di.getAllInstances().forEach(MinecraftForge.EVENT_BUS::register) } var lastJoin = -1L -- cgit