From 959c7fd76d3e862ad5d9bd181ce7658f849f4563 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 13 Jul 2024 17:29:56 +0200 Subject: [PATCH 01/12] meow --- .../config/features/chat/ChatConfig.java | 5 +++ .../skyhanni/features/chat/SoundResponse.kt | 33 +++++++++++++++++++ .../at/hannibal2/skyhanni/utils/SoundUtils.kt | 7 +++- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index f9e64f1e07d4..1e3b2dbad415 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -142,4 +142,9 @@ public String toString() { @ConfigEditorBoolean @FeatureToggle public boolean petRarityDropMessage = true; + + @Expose + @ConfigOption(name = "Meow", desc = "Play a meow any time a meow appears in chat.") + @ConfigEditorBoolean + public boolean meow = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt new file mode 100644 index 000000000000..f4ae8d710b7a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.features.chat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object SoundResponse { + + private val config get() = SkyHanniMod.feature.chat + + private val repoGroup = RepoPattern.group("chat.sound.response") + + /** REGEX-TEST: meow + REGEX-TEST: meow + REGEX-TEST: meow + REGEX-TEST: MEow + REGEX-TEST: §ameow + REGEX-TEST: hello §ameow + * */ + private val meow by repoGroup.pattern("meow", "(?:^|^.* )(?: |§.)*(?i)meow(?: |§.)*(?:\$| .*\$)") + + @SubscribeEvent + fun onLorenzChat(event: LorenzChatEvent) { + if (config.meow && meow.matches(event.message)) { + SoundUtils.playMeowSound() + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index 70e6242c621c..0de3f3d4e441 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -15,6 +15,7 @@ object SoundUtils { private val beepSound by lazy { createSound("random.orb", 1f) } private val clickSound by lazy { createSound("gui.button.press", 1f) } private val errorSound by lazy { createSound("mob.endermen.portal", 0f) } + private val meowSound by lazy { createSound("mob.cat.meow", 1f) } val plingSound by lazy { createSound("note.pling", 1f) } val centuryActiveTimerAlert by lazy { createSound("skyhanni:centurytimer.active", 1f) } @@ -38,7 +39,7 @@ object SoundUtils { } ErrorManager.logErrorWithData( e, "Failed to play a sound", - "soundLocation" to this.soundLocation + "soundLocation" to this.soundLocation, ) } finally { if (!SkyHanniMod.feature.misc.maintainGameVolume) { @@ -73,6 +74,10 @@ object SoundUtils { plingSound.playSound() } + fun playMeowSound() { + meowSound.playSound() + } + fun command(args: Array) { if (args.isEmpty()) { ChatUtils.userError("Specify a sound effect to test") From 59edd374dd97321698422853c06a5a535053bbe8 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 13 Jul 2024 22:55:50 +0200 Subject: [PATCH 02/12] added bark --- .../config/features/chat/ChatConfig.java | 7 ++++--- .../features/chat/SoundResponseConfig.java | 18 ++++++++++++++++++ .../skyhanni/features/chat/SoundResponse.kt | 8 +++++--- .../at/hannibal2/skyhanni/utils/SoundUtils.kt | 5 +++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 1e3b2dbad415..c8efeff22c15 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -143,8 +143,9 @@ public String toString() { @FeatureToggle public boolean petRarityDropMessage = true; + @Expose - @ConfigOption(name = "Meow", desc = "Play a meow any time a meow appears in chat.") - @ConfigEditorBoolean - public boolean meow = false; + @ConfigOption(name = "Sound Responses", desc = "") + @Accordion + public SoundResponseConfig soundResponse = new SoundResponseConfig(); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java new file mode 100644 index 000000000000..c129d65528de --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java @@ -0,0 +1,18 @@ +package at.hannibal2.skyhanni.config.features.chat; + +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class SoundResponseConfig { + + @Expose + @ConfigOption(name = "Meow", desc = "Play a meow any time a meow appears in chat.") + @ConfigEditorBoolean + public boolean meow = false; + + @Expose + @ConfigOption(name = "Bark", desc = "Play a bark any time a woof, arf or bark appears in chat.") + @ConfigEditorBoolean + public boolean bark = false; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt index f4ae8d710b7a..a010d732899b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt @@ -11,7 +11,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object SoundResponse { - private val config get() = SkyHanniMod.feature.chat + private val config get() = SkyHanniMod.feature.chat.soundResponse private val repoGroup = RepoPattern.group("chat.sound.response") @@ -23,11 +23,13 @@ object SoundResponse { REGEX-TEST: hello §ameow * */ private val meow by repoGroup.pattern("meow", "(?:^|^.* )(?: |§.)*(?i)meow(?: |§.)*(?:\$| .*\$)") + private val bark by repoGroup.pattern("bark", "(?:^|^.* )(?: |§.)*(?i)(?:bark|arf|woof)(?: |§.)*(?:\$| .*\$)") @SubscribeEvent fun onLorenzChat(event: LorenzChatEvent) { - if (config.meow && meow.matches(event.message)) { - SoundUtils.playMeowSound() + when { + config.meow && meow.matches(event.message) -> SoundUtils.playMeowSound() + config.bark && bark.matches(event.message) -> SoundUtils.playBarkSound() } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index 0de3f3d4e441..ef9f12ccf9b5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -16,6 +16,7 @@ object SoundUtils { private val clickSound by lazy { createSound("gui.button.press", 1f) } private val errorSound by lazy { createSound("mob.endermen.portal", 0f) } private val meowSound by lazy { createSound("mob.cat.meow", 1f) } + private val barkSound by lazy { createSound("mob.wolf.bark", 1f) } val plingSound by lazy { createSound("note.pling", 1f) } val centuryActiveTimerAlert by lazy { createSound("skyhanni:centurytimer.active", 1f) } @@ -78,6 +79,10 @@ object SoundUtils { meowSound.playSound() } + fun playBarkSound() { + barkSound.playSound() + } + fun command(args: Array) { if (args.isEmpty()) { ChatUtils.userError("Specify a sound effect to test") From 2ee34a5533602dd236996459d4e491e2243d23b5 Mon Sep 17 00:00:00 2001 From: Cal Date: Thu, 10 Oct 2024 19:25:35 +1100 Subject: [PATCH 03/12] formatting of regex test --- .../java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt index a010d732899b..cb855568a044 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt @@ -21,7 +21,7 @@ object SoundResponse { REGEX-TEST: MEow REGEX-TEST: §ameow REGEX-TEST: hello §ameow - * */ + */ private val meow by repoGroup.pattern("meow", "(?:^|^.* )(?: |§.)*(?i)meow(?: |§.)*(?:\$| .*\$)") private val bark by repoGroup.pattern("bark", "(?:^|^.* )(?: |§.)*(?i)(?:bark|arf|woof)(?: |§.)*(?:\$| .*\$)") From de3ec96f7efafcf88afe66001ea7d18cf23eda5c Mon Sep 17 00:00:00 2001 From: Cal Date: Fri, 11 Oct 2024 22:32:18 +1100 Subject: [PATCH 04/12] use enum instead --- .../config/features/chat/ChatConfig.java | 1 - .../features/chat/SoundResponseConfig.java | 17 ++++--- .../skyhanni/features/chat/SoundResponse.kt | 45 +++++++++++++------ .../at/hannibal2/skyhanni/utils/SoundUtils.kt | 10 ----- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 990dba0c675a..1449bcc4c5c8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -143,7 +143,6 @@ public String toString() { @FeatureToggle public boolean petRarityDropMessage = true; - @Expose @ConfigOption(name = "Sound Responses", desc = "") @Accordion diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java index c129d65528de..5bec262b7be9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java @@ -1,18 +1,25 @@ package at.hannibal2.skyhanni.config.features.chat; +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.features.chat.SoundResponseTypes; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import java.util.ArrayList; +import java.util.List; + public class SoundResponseConfig { @Expose - @ConfigOption(name = "Meow", desc = "Play a meow any time a meow appears in chat.") + @ConfigOption(name = "Enabled", desc = "Enable sound responses which play animal sounds when they are said in chat.") + @FeatureToggle @ConfigEditorBoolean - public boolean meow = false; + public boolean enabled = false; @Expose - @ConfigOption(name = "Bark", desc = "Play a bark any time a woof, arf or bark appears in chat.") - @ConfigEditorBoolean - public boolean bark = false; + @ConfigOption(name = "Sound Responses", desc = "Add animal sounds to play when certain words are said in chat.") + @ConfigEditorDraggableList + public List soundResponses = new ArrayList<>(SoundResponseTypes.getEntries()); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt index cb855568a044..1c6e999ee88b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.SoundUtils.playSound import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -13,23 +14,39 @@ object SoundResponse { private val config get() = SkyHanniMod.feature.chat.soundResponse - private val repoGroup = RepoPattern.group("chat.sound.response") - - /** REGEX-TEST: meow - REGEX-TEST: meow - REGEX-TEST: meow - REGEX-TEST: MEow - REGEX-TEST: §ameow - REGEX-TEST: hello §ameow - */ - private val meow by repoGroup.pattern("meow", "(?:^|^.* )(?: |§.)*(?i)meow(?: |§.)*(?:\$| .*\$)") - private val bark by repoGroup.pattern("bark", "(?:^|^.* )(?: |§.)*(?i)(?:bark|arf|woof)(?: |§.)*(?:\$| .*\$)") + init { + SoundResponseTypes.entries.forEach { it.pattern } + } @SubscribeEvent fun onLorenzChat(event: LorenzChatEvent) { - when { - config.meow && meow.matches(event.message) -> SoundUtils.playMeowSound() - config.bark && bark.matches(event.message) -> SoundUtils.playBarkSound() + for (soundType in SoundResponseTypes.entries) { + if (!config.soundResponses.contains(soundType)) continue + if (soundType.pattern.matches(event.message)) { + soundType.sound.playSound() + return + } } } } + +private const val START_PATTERN = "(?:^|^.* )(?: |§.)*(?i)" +private const val END_PATTERN = "(?: |§.|!|\\?|\\.)*(?:\$| .*\$)" + +enum class SoundResponseTypes(soundLocation: String, triggersOn: List) { + CAT("mob.cat.meow", listOf("meow")), + DOG("mob.wolf.bark", listOf("bark", "arf", "woof")), + SHEEP("mob.sheep.say", listOf("baa", "baah", "baaa", "baaaa", "baaaaa")), + COW("mob.cow.say", listOf("moo", "mooo", "moooo")), + PIG("mob.pig.say", listOf("oink")), + CHICKEN("mob.chicken.say", listOf("cluck")), + ; + + val sound by lazy { SoundUtils.createSound(soundLocation, 1f) } + + // creates a pattern that looks for if the message contains any of the triggerOn strings but as a full word + val pattern by RepoPattern.pattern( + "chat.sound.response" + name.lowercase(), + "$START_PATTERN(?:${triggersOn.joinToString("|")})$END_PATTERN", + ) +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index e9366f68cb17..2827ab41813a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -15,8 +15,6 @@ object SoundUtils { private val beepSound by lazy { createSound("random.orb", 1f) } private val clickSound by lazy { createSound("gui.button.press", 1f) } private val errorSound by lazy { createSound("mob.endermen.portal", 0f) } - private val meowSound by lazy { createSound("mob.cat.meow", 1f) } - private val barkSound by lazy { createSound("mob.wolf.bark", 1f) } val plingSound by lazy { createSound("note.pling", 1f) } val centuryActiveTimerAlert by lazy { createSound("skyhanni:centurytimer.active", 1f) } @@ -71,14 +69,6 @@ object SoundUtils { plingSound.playSound() } - fun playMeowSound() { - meowSound.playSound() - } - - fun playBarkSound() { - barkSound.playSound() - } - fun command(args: Array) { if (args.isEmpty()) { ChatUtils.userError("Specify a sound effect to test") From 58faf140c7dcebbceceb42208150992e358afb37 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:22:39 +0200 Subject: [PATCH 05/12] Better Patterns for moo and baah --- .../java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt index 1c6e999ee88b..61e6981b7227 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt @@ -36,8 +36,8 @@ private const val END_PATTERN = "(?: |§.|!|\\?|\\.)*(?:\$| .*\$)" enum class SoundResponseTypes(soundLocation: String, triggersOn: List) { CAT("mob.cat.meow", listOf("meow")), DOG("mob.wolf.bark", listOf("bark", "arf", "woof")), - SHEEP("mob.sheep.say", listOf("baa", "baah", "baaa", "baaaa", "baaaaa")), - COW("mob.cow.say", listOf("moo", "mooo", "moooo")), + SHEEP("mob.sheep.say", listOf("baa+h*")), + COW("mob.cow.say", listOf("moo+")), PIG("mob.pig.say", listOf("oink")), CHICKEN("mob.chicken.say", listOf("cluck")), ; From f6b9776727cffb105e3a91c6450d33b8f961e410 Mon Sep 17 00:00:00 2001 From: calwolfson Date: Thu, 9 Jan 2025 17:12:08 +0100 Subject: [PATCH 06/12] Rename .java to .kt --- .../chat/{SoundResponseConfig.java => SoundResponseConfig.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/java/at/hannibal2/skyhanni/config/features/chat/{SoundResponseConfig.java => SoundResponseConfig.kt} (100%) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt similarity index 100% rename from src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.java rename to src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt From e71e4caed804d160578d2affe5867e73a799db7c Mon Sep 17 00:00:00 2001 From: calwolfson Date: Thu, 9 Jan 2025 17:12:08 +0100 Subject: [PATCH 07/12] kotlin --- .../config/features/chat/ChatConfig.kt | 10 +++---- .../features/chat/SoundResponseConfig.kt | 29 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt index 1b3b6cd15e82..c409d0d05429 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt @@ -28,6 +28,11 @@ class ChatConfig { @Accordion var playerMessage: PlayerMessagesConfig = PlayerMessagesConfig() + @Expose + @ConfigOption(name = "Sound Responses", desc = "") + @Accordion + var soundResponse: SoundResponseConfig = SoundResponseConfig() + @Expose @ConfigOption(name = "Dungeon Filters", desc = "Hide specific message types in Dungeons.") @ConfigEditorDraggableList @@ -144,9 +149,4 @@ class ChatConfig { @ConfigEditorBoolean @FeatureToggle var petRarityDropMessage: Boolean = true - - @Expose - @ConfigOption(name = "Sound Responses", desc = "") - @Accordion - public SoundResponseConfig soundResponse = new SoundResponseConfig(); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt index 5bec262b7be9..6720dc220dc3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt @@ -1,25 +1,24 @@ -package at.hannibal2.skyhanni.config.features.chat; +package at.hannibal2.skyhanni.config.features.chat -import at.hannibal2.skyhanni.config.FeatureToggle; -import at.hannibal2.skyhanni.features.chat.SoundResponseTypes; -import com.google.gson.annotations.Expose; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; -import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; - -import java.util.ArrayList; -import java.util.List; - -public class SoundResponseConfig { +import at.hannibal2.skyhanni.config.FeatureToggle +import at.hannibal2.skyhanni.features.chat.SoundResponseTypes +import com.google.gson.annotations.Expose +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption +class SoundResponseConfig { @Expose - @ConfigOption(name = "Enabled", desc = "Enable sound responses which play animal sounds when they are said in chat.") + @ConfigOption( + name = "Enabled", + desc = "Enable sound responses which play animal sounds when they are said in chat.", + ) @FeatureToggle @ConfigEditorBoolean - public boolean enabled = false; + var enabled: Boolean = false @Expose @ConfigOption(name = "Sound Responses", desc = "Add animal sounds to play when certain words are said in chat.") @ConfigEditorDraggableList - public List soundResponses = new ArrayList<>(SoundResponseTypes.getEntries()); + var soundResponses: List = ArrayList(SoundResponseTypes.entries) } From 1cd1a9bef40d68bb43f4445e28ca322b7709fef1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 11 Jan 2025 00:45:20 +0100 Subject: [PATCH 08/12] added enabled check, renamed class --- .../hannibal2/skyhanni/config/features/chat/ChatConfig.kt | 2 +- .../{SoundResponseConfig.kt => ChatSoundResponseConfig.kt} | 2 +- .../chat/{SoundResponse.kt => ChatSoundResponse.kt} | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) rename src/main/java/at/hannibal2/skyhanni/config/features/chat/{SoundResponseConfig.kt => ChatSoundResponseConfig.kt} (96%) rename src/main/java/at/hannibal2/skyhanni/features/chat/{SoundResponse.kt => ChatSoundResponse.kt} (91%) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt index c409d0d05429..851288e80fba 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.kt @@ -31,7 +31,7 @@ class ChatConfig { @Expose @ConfigOption(name = "Sound Responses", desc = "") @Accordion - var soundResponse: SoundResponseConfig = SoundResponseConfig() + var soundResponse: ChatSoundResponseConfig = ChatSoundResponseConfig() @Expose @ConfigOption(name = "Dungeon Filters", desc = "Hide specific message types in Dungeons.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt similarity index 96% rename from src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt rename to src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt index 6720dc220dc3..4cc8dd0610d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/SoundResponseConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt @@ -7,7 +7,7 @@ import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList import io.github.notenoughupdates.moulconfig.annotations.ConfigOption -class SoundResponseConfig { +class ChatSoundResponseConfig { @Expose @ConfigOption( name = "Enabled", diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt similarity index 91% rename from src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt rename to src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt index 61e6981b7227..7d6db738bd79 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.SoundUtils.playSound @@ -10,7 +11,7 @@ import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule -object SoundResponse { +object ChatSoundResponse { private val config get() = SkyHanniMod.feature.chat.soundResponse @@ -20,6 +21,8 @@ object SoundResponse { @SubscribeEvent fun onLorenzChat(event: LorenzChatEvent) { + if (!isEnabled()) return + for (soundType in SoundResponseTypes.entries) { if (!config.soundResponses.contains(soundType)) continue if (soundType.pattern.matches(event.message)) { @@ -28,6 +31,8 @@ object SoundResponse { } } } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled } private const val START_PATTERN = "(?:^|^.* )(?: |§.)*(?i)" From c01a486c16db8cca7cb4220a1d635c215fa900a2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 11 Jan 2025 00:46:55 +0100 Subject: [PATCH 09/12] fixed upper case name in config --- .../at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt index 7d6db738bd79..94ad2f7d4353 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatSoundResponse.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.SoundUtils.playSound +import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -54,4 +55,6 @@ enum class SoundResponseTypes(soundLocation: String, triggersOn: List) { "chat.sound.response" + name.lowercase(), "$START_PATTERN(?:${triggersOn.joinToString("|")})$END_PATTERN", ) + + override fun toString(): String = name.firstLetterUppercase() } From 34d161db29a4c2cc6ea9c30efb4aca11d3b14584 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 11 Jan 2025 00:47:09 +0100 Subject: [PATCH 10/12] removed unnecessary boxing --- .../skyhanni/config/features/chat/ChatSoundResponseConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt index 4cc8dd0610d2..19dbdc082285 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt @@ -20,5 +20,5 @@ class ChatSoundResponseConfig { @Expose @ConfigOption(name = "Sound Responses", desc = "Add animal sounds to play when certain words are said in chat.") @ConfigEditorDraggableList - var soundResponses: List = ArrayList(SoundResponseTypes.entries) + var soundResponses: List = SoundResponseTypes.entries } From 2fc9050b9e8a74f8d01ff8e5a0c195f395f0b2bd Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 11 Jan 2025 04:30:05 +0100 Subject: [PATCH 11/12] Fix --- .../skyhanni/config/features/chat/ChatSoundResponseConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt index 19dbdc082285..8f03f4b794a0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt @@ -20,5 +20,5 @@ class ChatSoundResponseConfig { @Expose @ConfigOption(name = "Sound Responses", desc = "Add animal sounds to play when certain words are said in chat.") @ConfigEditorDraggableList - var soundResponses: List = SoundResponseTypes.entries + var soundResponses = mutableListOf(SoundResponseTypes.entries) } From bb14a6fbb73474115a86f66110e1720935c5bada Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sat, 11 Jan 2025 04:37:12 +0100 Subject: [PATCH 12/12] correct fix --- .../skyhanni/config/features/chat/ChatSoundResponseConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt index 8f03f4b794a0..1396818d5656 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSoundResponseConfig.kt @@ -20,5 +20,5 @@ class ChatSoundResponseConfig { @Expose @ConfigOption(name = "Sound Responses", desc = "Add animal sounds to play when certain words are said in chat.") @ConfigEditorDraggableList - var soundResponses = mutableListOf(SoundResponseTypes.entries) + var soundResponses = SoundResponseTypes.entries.toMutableList() }