From e42bc6340771d87e2fb0263a4ad81528aeebec69 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Fri, 17 Jan 2025 00:14:55 +0100 Subject: feat: Pest Repellent Detection --- .../nea/ledger/modules/PestRepellentDetection.kt | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 mod/src/main/kotlin/moe/nea/ledger/modules/PestRepellentDetection.kt (limited to 'mod/src/main/kotlin/moe/nea/ledger/modules') diff --git a/mod/src/main/kotlin/moe/nea/ledger/modules/PestRepellentDetection.kt b/mod/src/main/kotlin/moe/nea/ledger/modules/PestRepellentDetection.kt new file mode 100644 index 0000000..f627393 --- /dev/null +++ b/mod/src/main/kotlin/moe/nea/ledger/modules/PestRepellentDetection.kt @@ -0,0 +1,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 (?[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), + ) + ) + ) + } + } + } +} \ No newline at end of file -- cgit