aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/kotlin/moe/nea/ledger/modules/PestRepellentDetection.kt
blob: f627393bd9d1ad5de45b5a678114bea8b029ce28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package moe.nea.ledger.modules

import moe.nea.ledger.ItemChange
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.TransactionType
import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.gen.ItemIds
import moe.nea.ledger.useMatcher
import moe.nea.ledger.utils.di.Inject
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class PestRepellentDetection {

    val pestRepellent = "YUM! Pests will now spawn (?<reduction>[2-4])x less while you break crops for the next 60m!".toPattern()

    @Inject
    lateinit var logger: LedgerLogger

    @SubscribeEvent
    fun onChat(event: ChatReceived) {
        pestRepellent.useMatcher(event.message) {
            val reductionAmount = group("reduction")
            if (reductionAmount == "2") {
                logger.logEntry(
                    LedgerEntry(
                        TransactionType.PEST_REPELLENT_USED,
                        event.timestamp,
                        listOf(
                            ItemChange.lose(ItemIds.PEST_REPELLENT, 1),
                        )
                    )
                )
            } else if (reductionAmount == "4"){
                logger.logEntry(
                    LedgerEntry(
                        TransactionType.PEST_REPELLENT_USED,
                        event.timestamp,
                        listOf(
                            ItemChange.lose(ItemIds.PEST_REPELLENT_MAX, 1),
                        )
                    )
                )
            }
        }
    }
}