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