diff options
author | Cow <cow@volloeko.de> | 2021-07-08 11:56:52 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2021-07-08 11:56:52 +0200 |
commit | 060839b4960cf95d428d9ecbc69e455c913d720d (patch) | |
tree | 99e8a969ee8aaa6aaf16069c78ad43051b18c585 /src/main/java/de/cowtipper/cowlection/command/NumerousCommandsCommand.java | |
parent | 09e28b36a3159e35710b06e82a60c6814716f230 (diff) | |
download | Cowlection-060839b4960cf95d428d9ecbc69e455c913d720d.tar.gz Cowlection-060839b4960cf95d428d9ecbc69e455c913d720d.tar.bz2 Cowlection-060839b4960cf95d428d9ecbc69e455c913d720d.zip |
Added new command /commandslist
- list all client-side commands added by all installed mods
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/command/NumerousCommandsCommand.java')
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/command/NumerousCommandsCommand.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/command/NumerousCommandsCommand.java b/src/main/java/de/cowtipper/cowlection/command/NumerousCommandsCommand.java new file mode 100644 index 0000000..08486e3 --- /dev/null +++ b/src/main/java/de/cowtipper/cowlection/command/NumerousCommandsCommand.java @@ -0,0 +1,79 @@ +package de.cowtipper.cowlection.command; + +import de.cowtipper.cowlection.numerouscommands.ModInfo; +import de.cowtipper.cowlection.numerouscommands.NumerousCommandsGui; +import de.cowtipper.cowlection.util.TickDelay; +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; + +import java.util.*; + +public class NumerousCommandsCommand extends CommandBase { + @Override + public String getCommandName() { + return "commandslist"; + } + + @Override + public List<String> getCommandAliases() { + return Arrays.asList("clientcommands", "listcommands"); + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getCommandName(); + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + HashSet<String> ignoredMods = new HashSet<>(Arrays.asList("Minecraft Coder Pack", "Forge Mod Loader", "Minecraft Forge")); + + Map<String, ModInfo> modsInfo = new TreeMap<>(); + + for (ModContainer mod : Loader.instance().getActiveModList()) { + String modName = mod.getName(); + if (ignoredMods.contains(modName)) { + // ignored mod + continue; + } + modsInfo.put(modName, new ModInfo(mod)); + } + + ModInfo unknownMod = new ModInfo(); + for (Map.Entry<String, ICommand> cmdEntry : ClientCommandHandler.instance.getCommands().entrySet()) { + String cmdName = cmdEntry.getKey(); + ICommand cmd = cmdEntry.getValue(); + if (!cmdName.equalsIgnoreCase(cmd.getCommandName())) { + // skip command alias + continue; + } + String cmdPackageName = cmd.getClass().getPackage().getName(); + boolean foundOwningMod = false; + for (ModInfo modInfo : modsInfo.values()) { + if (modInfo.isOwnedPackage(cmdPackageName)) { + modInfo.addCommand(cmd, sender); + foundOwningMod = true; + break; + } + } + if (!foundOwningMod) { + unknownMod.addCommand(cmd, sender); + } + } + if (unknownMod.getCommandsCount() > 0) { + modsInfo.put("zzzzzzzz_unknown", unknownMod); + } + new TickDelay(() -> Minecraft.getMinecraft().displayGuiScreen(new NumerousCommandsGui(modsInfo.values())), 1); + } + + @Override + public int getRequiredPermissionLevel() { + return 0; + } +} |