From ec24fdbd476000274ce26395dfe435857da0fcf9 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sat, 6 Jul 2024 15:53:07 +0200 Subject: [PATCH] fix Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../farming/garden/CropMilestoneWebhook.kt | 17 ++++---- .../gui/hud/rngdropbanner/DropWebhook.kt | 42 ++++++++----------- .../skills/BestiaryMilestoneWebhook.kt | 15 +++---- .../features/skills/PetLevelUpWebhook.kt | 20 ++++----- .../features/skills/SkillUpgradeWebhook.kt | 18 ++++---- 5 files changed, 53 insertions(+), 59 deletions(-) diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt index 74521fae..d7fada98 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt @@ -16,7 +16,6 @@ import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField import me.partlysanestudios.partlysaneskies.features.discord.webhooks.Webhook import me.partlysanestudios.partlysaneskies.features.discord.webhooks.WebhookData import me.partlysanestudios.partlysaneskies.render.gui.components.PSSItemRender -import me.partlysanestudios.partlysaneskies.utils.ChatUtils.trueUnformattedMessage import me.partlysanestudios.partlysaneskies.utils.ImageUtils.asHex import me.partlysanestudios.partlysaneskies.utils.StringUtils.romanNumeralToInt import me.partlysanestudios.partlysaneskies.utils.StringUtils.toRoman @@ -26,7 +25,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color -object CropMilestoneWebhook: Webhook() { +object CropMilestoneWebhook : Webhook() { override val icon = PSSItemRender(ItemStack(Items.reeds), true) .setX(CenterConstraint()) .setY(CenterConstraint()) @@ -46,8 +45,10 @@ object CropMilestoneWebhook: Webhook() { @SubscribeEvent fun onChatMessage(event: ClientChatReceivedEvent) { + if (!enabled) return + val message = event.message.formattedText - + val (crop, oldLevel, newLevel) = regex.find(message)?.destructured ?: return val oldLevelInt = if ("\\d+".toRegex().containsMatchIn(oldLevel)) { oldLevel.toIntOrNull() ?: 0 @@ -95,10 +96,10 @@ object CropMilestoneWebhook: Webhook() { EmbedField( name = crop, value = ":tada: $oldLevelString ➜ $newLevelString :tada:", - ) - ) - ) - ) + ), + ), + ), + ), ).send() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/rngdropbanner/DropWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/rngdropbanner/DropWebhook.kt index bac1f929..0caed4d0 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/rngdropbanner/DropWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/rngdropbanner/DropWebhook.kt @@ -6,19 +6,13 @@ package me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner -import gg.essential.elementa.UIComponent -import gg.essential.elementa.components.UIBlock import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.dsl.constrain import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean -import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asToggle import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity -import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode -import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager -import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockItem import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField import me.partlysanestudios.partlysaneskies.features.discord.webhooks.Webhook @@ -26,20 +20,19 @@ import me.partlysanestudios.partlysaneskies.features.discord.webhooks.WebhookDat import me.partlysanestudios.partlysaneskies.render.gui.components.PSSItemRender import me.partlysanestudios.partlysaneskies.utils.ImageUtils.asHex import me.partlysanestudios.partlysaneskies.utils.StringUtils.colorCodeToColor -import net.minecraft.block.material.Material import net.minecraft.init.Items import net.minecraft.item.ItemStack import java.awt.Color -import java.util.* -object DropWebhook: Webhook() { - override val icon get() = PSSItemRender(ItemStack(Items.gold_ingot), true).constrain { - width = 80.percent - height = 80.percent - x = CenterConstraint() - y = CenterConstraint() - } - +object DropWebhook : Webhook() { + override val icon + get() = PSSItemRender(ItemStack(Items.gold_ingot), true).constrain { + width = 80.percent + height = 80.percent + x = CenterConstraint() + y = CenterConstraint() + } + override val id: String = "rngdrop" override val name: String = "RNG Drop" override val description: String = "Automatically send a Discord message\nwhenever a rare item has dropped" @@ -51,10 +44,9 @@ object DropWebhook: Webhook() { config.registerOption("send$displayName", Toggle("Send $displayName Drops", "Allow the webhook to send drops of ${displayName.lowercase()} rarity.", true)) } } + fun trigger(drop: Drop) { - if (config.find("enabled")?.asBoolean != true) { - return - } + if (!enabled) return if (shouldBlockDrop(drop.dropRarity)) { return @@ -81,13 +73,13 @@ object DropWebhook: Webhook() { EmbedField( name = name, value = description, - inline = true - ) - ) - ) - ) + inline = true, + ), + ), + ), + ), ).send() } private fun shouldBlockDrop(rarity: Rarity) = config.find("send${rarity.displayName}")?.asBoolean != true -} \ No newline at end of file +} diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt index 342f03e1..3faf963c 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt @@ -16,7 +16,6 @@ import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField import me.partlysanestudios.partlysaneskies.features.discord.webhooks.Webhook import me.partlysanestudios.partlysaneskies.features.discord.webhooks.WebhookData import me.partlysanestudios.partlysaneskies.render.gui.components.PSSItemRender -import me.partlysanestudios.partlysaneskies.utils.ChatUtils.trueUnformattedMessage import me.partlysanestudios.partlysaneskies.utils.ImageUtils.asHex import me.partlysanestudios.partlysaneskies.utils.StringUtils.romanNumeralToInt import me.partlysanestudios.partlysaneskies.utils.StringUtils.toRoman @@ -26,7 +25,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color -object BestiaryMilestoneWebhook: Webhook() { +object BestiaryMilestoneWebhook : Webhook() { override val icon = PSSItemRender(ItemStack(Items.golden_sword), true) .setX(CenterConstraint()) .setY(CenterConstraint()) @@ -49,6 +48,8 @@ object BestiaryMilestoneWebhook: Webhook() { @SubscribeEvent fun onChatMessage(event: ClientChatReceivedEvent) { + if (!enabled) return + val message = event.message.formattedText if (message.contains("§lBESTIARY MILESTONE")) { headingMessageSent = true @@ -104,10 +105,10 @@ object BestiaryMilestoneWebhook: Webhook() { EmbedField( name = "Milestone", value = ":tada: $oldLevelString ➜ $newLevelString :tada:", - ) - ) - ) - ) + ), + ), + ), + ), ).send() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt index 537747b7..6392cbbc 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt @@ -11,7 +11,6 @@ import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean -import me.partlysanestudios.partlysaneskies.data.cache.PetData import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData @@ -19,18 +18,15 @@ import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField import me.partlysanestudios.partlysaneskies.features.discord.webhooks.Webhook import me.partlysanestudios.partlysaneskies.features.discord.webhooks.WebhookData import me.partlysanestudios.partlysaneskies.render.gui.components.PSSItemRender -import me.partlysanestudios.partlysaneskies.utils.ChatUtils.trueUnformattedMessage import me.partlysanestudios.partlysaneskies.utils.ImageUtils.asHex import me.partlysanestudios.partlysaneskies.utils.StringUtils.colorCodeToColor -import me.partlysanestudios.partlysaneskies.utils.StringUtils.romanNumeralToInt import me.partlysanestudios.partlysaneskies.utils.StringUtils.toRoman import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.awt.Color -object PetLevelUpWebhook: Webhook() { +object PetLevelUpWebhook : Webhook() { override val icon = PSSItemRender(ItemStack(Items.bone), true) .setX(CenterConstraint()) .setY(CenterConstraint()) @@ -56,6 +52,8 @@ object PetLevelUpWebhook: Webhook() { @SubscribeEvent fun onChatMessage(event: ClientChatReceivedEvent) { + if (!enabled) return + val message = event.message.formattedText regex.find(message)?.let { @@ -96,11 +94,11 @@ object PetLevelUpWebhook: Webhook() { fields = listOf( EmbedField( name = "${rarity.displayName} $name", - value = ":tada: $levelString :tada:" - ) - ) - ) - ) + value = ":tada: $levelString :tada:", + ), + ), + ), + ), ).send() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt index 6c7f6cbb..53c83ae0 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt @@ -26,7 +26,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color -object SkillUpgradeWebhook: Webhook() { +object SkillUpgradeWebhook : Webhook() { override val icon = PSSItemRender(ItemStack(Items.diamond_pickaxe), true) .setX(CenterConstraint()) .setY(CenterConstraint()) @@ -43,9 +43,11 @@ object SkillUpgradeWebhook: Webhook() { } val regex = "SKILL LEVEL UP (\\w+) (\\w+)➜(\\w+)".toRegex() - + @SubscribeEvent fun onChatMessage(event: ClientChatReceivedEvent) { + if (!enabled) return + val message = event.trueUnformattedMessage val (skill, oldLevel, newLevel) = regex.find(message)?.destructured ?: return @@ -96,11 +98,11 @@ object SkillUpgradeWebhook: Webhook() { EmbedField( name = skill, value = ":tada: $oldLevelString ➜ $newLevelString :tada:", - inline = true - ) - ) - ) - ) + inline = true, + ), + ), + ), + ), ).send() } -} \ No newline at end of file +}