mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 21:27:44 +01:00
Removed useless constructor in CompositeCommand + updated unit tests
This commit is contained in:
parent
6ba27eef4e
commit
e4cedb58d0
@ -26,8 +26,8 @@ import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* BSB composite command
|
||||
* @author tastybento, poslovich
|
||||
*
|
||||
* @author tastybento
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public abstract class CompositeCommand extends Command implements PluginIdentifiableCommand, BSBCommand {
|
||||
|
||||
@ -66,23 +66,28 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
private String usage;
|
||||
|
||||
/**
|
||||
* Used only for testing....
|
||||
* This is the top-level command constructor for commands that have no parent.
|
||||
* @param label - string for this command
|
||||
* @param aliases - aliases for this command
|
||||
*/
|
||||
public CompositeCommand(BSkyBlock plugin, String label, String... string) {
|
||||
public CompositeCommand(String label, String... aliases) {
|
||||
super(label);
|
||||
setAliases(new ArrayList<>(Arrays.asList(string)));
|
||||
setAliases(new ArrayList<>(Arrays.asList(aliases)));
|
||||
parent = null;
|
||||
setUsage("");
|
||||
subCommandLevel = 0; // Top level
|
||||
subCommands = new LinkedHashMap<>();
|
||||
subCommandAliases = new LinkedHashMap<>();
|
||||
// Register command if it is not already registered
|
||||
if (getPlugin().getCommand(label) == null) {
|
||||
getPlugin().getCommandsManager().registerCommand(this);
|
||||
}
|
||||
setup();
|
||||
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||
new DefaultHelpCommand(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sub-command constructor
|
||||
* @param parent - the parent composite command
|
||||
@ -110,30 +115,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the top-level command constructor for commands that have no parent.
|
||||
* @param label - string for this command
|
||||
* @param aliases - aliases for this command
|
||||
*/
|
||||
public CompositeCommand(String label, String... aliases) {
|
||||
super(label);
|
||||
setAliases(new ArrayList<>(Arrays.asList(aliases)));
|
||||
parent = null;
|
||||
setUsage("");
|
||||
subCommandLevel = 0; // Top level
|
||||
subCommands = new LinkedHashMap<>();
|
||||
subCommandAliases = new LinkedHashMap<>();
|
||||
// Register command if it is not already registered
|
||||
if (getPlugin().getCommand(label) == null) {
|
||||
getPlugin().getCommandsManager().registerCommand(this);
|
||||
}
|
||||
setup();
|
||||
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
|
||||
new DefaultHelpCommand(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This method deals with the command execution. It traverses the tree of
|
||||
* subcommands until it finds the right object and then runs execute on it.
|
||||
@ -257,7 +238,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
return BSkyBlock.getInstance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Settings object
|
||||
*/
|
||||
@ -265,7 +245,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
return getPlugin().getSettings();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the CompositeCommand object referring to this command label
|
||||
* @param label - command label or alias
|
||||
|
@ -226,10 +226,10 @@ public class TestBSkyBlock {
|
||||
String[] args3 = {"sub2","subsub", ""};
|
||||
assertEquals(Arrays.asList("subsubsub", "help"), testCommand.tabComplete(player, "test", args3));
|
||||
// Test for overridden tabcomplete
|
||||
assertEquals(Arrays.asList(new String[] {"Florian", "Ben", "Bill", "Ted", "help"}),
|
||||
assertEquals(Arrays.asList("Florian", "Ben", "Bill", "Ted", "help"),
|
||||
testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", ""}));
|
||||
// Test for partial word
|
||||
assertEquals(Arrays.asList(new String[] {"Ben", "Bill"}),
|
||||
assertEquals(Arrays.asList("Ben", "Bill"),
|
||||
testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", "b"}));
|
||||
|
||||
// Test command arguments
|
||||
@ -253,7 +253,7 @@ public class TestBSkyBlock {
|
||||
private class TestCommand extends CompositeCommand {
|
||||
|
||||
public TestCommand() {
|
||||
super(plugin, "test", "t", "tt");
|
||||
super("test", "t", "tt");
|
||||
setParameters("test.params");
|
||||
}
|
||||
|
||||
@ -340,17 +340,15 @@ public class TestBSkyBlock {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
Bukkit.getLogger().info("args are " + args.toString());
|
||||
if (args.size() == 3) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
return args.size() == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(final User user, final String alias, final LinkedList<String> args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
String lastArg = (!args.isEmpty() ? args.getLast() : "");
|
||||
options.addAll(Arrays.asList(new String[] {"Florian", "Ben", "Bill", "Ted"}));
|
||||
options.addAll(Arrays.asList("Florian", "Ben", "Bill", "Ted"));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
||||
@ -358,7 +356,7 @@ public class TestBSkyBlock {
|
||||
private class Test3ArgsCommand extends CompositeCommand {
|
||||
|
||||
public Test3ArgsCommand() {
|
||||
super(plugin, "args", "");
|
||||
super("args", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -367,7 +365,7 @@ public class TestBSkyBlock {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
Bukkit.getLogger().info("args are " + args.toString());
|
||||
return args.size() == 3 ? true : false;
|
||||
return args.size() == 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user