Rework commands to be sub commands of /bloodmagic
This commit is contained in:
parent
fa78706fca
commit
731f92a7fd
7 changed files with 461 additions and 3 deletions
|
@ -0,0 +1,71 @@
|
|||
package WayofTime.alchemicalWizardry.common.commands;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.command.ISubCommand;
|
||||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandBind;
|
||||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandHelp;
|
||||
import WayofTime.alchemicalWizardry.common.commands.sub.SubCommandNetwork;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandBloodMagic extends CommandBase {
|
||||
|
||||
private final List aliases = new ArrayList();
|
||||
private final Map<String, ISubCommand> subCommands = new HashMap<String, ISubCommand>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CommandBloodMagic() {
|
||||
aliases.add("BloodMagic");
|
||||
aliases.add("bloodmagic");
|
||||
aliases.add("bloodMagic");
|
||||
aliases.add("bm");
|
||||
|
||||
subCommands.put("help", new SubCommandHelp(this));
|
||||
subCommands.put("network", new SubCommandNetwork(this));
|
||||
subCommands.put("bind", new SubCommandBind(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "/bloodmagic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender commandSender) {
|
||||
return getCommandName() + " help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getCommandAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender commandSender, String[] args) {
|
||||
if (args.length > 0 && subCommands.containsKey(args[0])) {
|
||||
|
||||
ISubCommand subCommand = subCommands.get(args[0]);
|
||||
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
if (subCommand.canSenderUseSubCommand(commandSender))
|
||||
subCommand.processSubCommand(commandSender, subArgs);
|
||||
else
|
||||
commandSender.addChatMessage(new ChatComponentText("You do not have permission to use this command.").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
} else {
|
||||
commandSender.addChatMessage(new ChatComponentText("Unknown command!").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, ISubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue