From fb9d2f2633c185faba162d85e4ae71c2a347fbb5 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 1 May 2022 12:08:25 +0200 Subject: improve non-oneconfig mod command finding --- .../polyfrost/oneconfig/gui/elements/ModCard.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java') diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java index 444094e..1587a93 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java @@ -11,6 +11,7 @@ import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; import io.polyfrost.oneconfig.utils.InputUtils; import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.I18n; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraftforge.client.ClientCommandHandler; @@ -19,6 +20,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.nanovg.NanoVG; +import java.util.ArrayList; + public class ModCard extends BasicElement { private final String iconPath; private final Mod modData; @@ -94,11 +97,21 @@ public class ModCard extends BasicElement { } for (ModMetadata mod : OneConfig.loadedOtherMods) { if (mod.name.equalsIgnoreCase(modData.name)) { - System.out.println("Attempting to run command for a mod that isn't OneConfig: " + mod.name); - for (String commands : ClientCommandHandler.instance.getCommands().keySet()) { - if (commands.equalsIgnoreCase(mod.name) || commands.equalsIgnoreCase(mod.modId)) { + ArrayList possibleCommands = new ArrayList<>(); + possibleCommands.add(mod.name.toLowerCase().replace(" ", "")); + possibleCommands.add(mod.modId.toLowerCase().replaceAll("[ -_]", "")); + if (mod.name.split(" ").length > 1) { + StringBuilder result = new StringBuilder(); + for (String word : mod.name.split(" ")) { + if (word.length() == 0) continue; + result.append(word.charAt(0)); + } + possibleCommands.add(result.toString().toLowerCase()); + } + for (String command : ClientCommandHandler.instance.getCommands().keySet()) { + if (possibleCommands.contains(command)) { try { - ClientCommandHandler.instance.getCommands().get(commands).processCommand(Minecraft.getMinecraft().thePlayer, new String[]{}); + ClientCommandHandler.instance.getCommands().get(command).processCommand(Minecraft.getMinecraft().thePlayer, new String[]{}); } catch (CommandException e) { throw new RuntimeException(e); } -- cgit