From 5d89d56e1a480ae26f325c995a66a4b40a436638 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 30 May 2024 12:59:00 +0200 Subject: Fix: /viewrecipe (#1939) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/commands/ViewRecipeCommand.kt | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt index fbfb1a640..cbdc626ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/ViewRecipeCommand.kt @@ -2,23 +2,36 @@ package at.hannibal2.skyhanni.features.commands import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.MessageSendToServerEvent +import at.hannibal2.skyhanni.utils.ChatUtils.senderIsSkyhanni import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ViewRecipeCommand { private val config get() = SkyHanniMod.feature.misc.commands + /** + * REGEX-TEST: /viewrecipe aspect of the end + * REGEX-TEST: /viewrecipe aspect_of_the_end + * REGEX-TEST: /viewrecipe ASPECT_OF_THE_END + */ + private val pattern by RepoPattern.pattern( + "commands.viewrecipe", + "\\/viewrecipe (?.*)" + ) + @SubscribeEvent fun onMessageSendToServer(event: MessageSendToServerEvent) { if (!config.viewRecipeLowerCase) return - val message = event.message - if (!message.startsWith("/viewrecipe ", ignoreCase = true)) return + if (event.senderIsSkyhanni()) return + + val item = pattern.matchMatcher(event.message.lowercase()) { + group("item").uppercase().replace(" ", "_") + } ?: return - if (message == message.uppercase()) return - val item = message.uppercase().substringAfter("viewrecipe").trim() - if (item.isEmpty()) return event.isCanceled = true HypixelCommands.viewRecipe(item) } -- cgit