blob: 08486e325d303ddc5646bf173aa1159bf526bbaf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
}
}
|