Integrating CommandEE piece of #881

This commit is contained in:
Pahimar 2016-05-28 09:12:27 -04:00
parent 9e7f1cc910
commit 30ec9ab327
1 changed files with 29 additions and 28 deletions

View File

@ -1,58 +1,60 @@
package com.pahimar.ee3.command;
import com.google.common.base.Joiner;
import com.pahimar.ee3.reference.Messages;
import com.pahimar.ee3.reference.Names;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import java.util.ArrayList;
import java.util.List;
public class CommandEE extends CommandBase
{
private static List<CommandBase> modCommands = new ArrayList<CommandBase>();
private static List<String> commands = new ArrayList<String>();
public class CommandEE extends CommandBase {
private static List<CommandBase> modCommands = new ArrayList<>();
private static List<String> commands = new ArrayList<>();
@Override
public String getCommandName()
{
public String getCommandName() {
return Names.Commands.BASE_COMMAND;
}
@Override
public String getCommandUsage(ICommandSender commandSender)
{
public String getCommandUsage(ICommandSender commandSender) {
return Messages.Commands.BASE_COMMAND_USAGE;
}
@Override
public void processCommand(ICommandSender commandSender, String[] args)
{
if (args.length >= 1)
{
for (CommandBase command : modCommands)
{
if (command.getCommandName().equalsIgnoreCase(args[0]) && command.canCommandSenderUseCommand(commandSender))
{
public void processCommand(ICommandSender commandSender, String[] args) {
boolean found = false;
if (args.length >= 1) {
for (CommandBase command : modCommands) {
if (command.getCommandName().equalsIgnoreCase(args[0]) && command.canCommandSenderUseCommand(commandSender)) {
found = true;
command.processCommand(commandSender, args);
}
}
}
if (!found) {
throw new WrongUsageException("Invalid command. Usage: /ee3 " + Joiner.on(" ").join(commands));
}
}
@Override
public List addTabCompletionOptions(ICommandSender commandSender, String[] args)
{
if (args.length == 1)
{
public List addTabCompletionOptions(ICommandSender commandSender, String[] args) {
if (args.length == 1) {
return getListOfStringsFromIterableMatchingLastWord(args, commands);
}
else if (args.length >= 2)
{
for (CommandBase command : modCommands)
{
if (command.getCommandName().equalsIgnoreCase(args[0]))
{
else if (args.length >= 2) {
for (CommandBase command : modCommands) {
if (command.getCommandName().equalsIgnoreCase(args[0])) {
return command.addTabCompletionOptions(commandSender, args);
}
}
@ -81,8 +83,7 @@ public class CommandEE extends CommandBase
modCommands.add(new CommandRegenEnergyValues());
modCommands.add(new CommandRunTest());
for (CommandBase commandBase : modCommands)
{
for (CommandBase commandBase : modCommands) {
commands.add(commandBase.getCommandName());
}
}