Tab list with subcommands
Now when using tab it should suggest subcommands (if any available) instead of players/senders. Conflicts: src/main/java/com/massivecraft/massivecore/cmd/MassiveCoreBukkitCommand.java
This commit is contained in:
parent
014815d227
commit
22cef1d9da
@ -39,6 +39,16 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
|
|||||||
this.massiveCommand = massiveCommand;
|
this.massiveCommand = massiveCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE: PLUGIN IDENTIFIABLE COMMAND
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return massiveCommand.getRegisteredPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE: EXECUTE
|
// OVERRIDE: EXECUTE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -78,14 +88,37 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
|
|||||||
@Override
|
@Override
|
||||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException
|
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
|
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
String tokenlc = args[args.length - 1].toLowerCase();
|
||||||
|
|
||||||
|
// First we need a command to find the subcommands in.
|
||||||
|
MassiveCommand cmd = this.getSubCommand(args, massiveCommand);
|
||||||
|
|
||||||
|
// So if we found a command, and it has subcommands
|
||||||
|
// we will suggest the aliases instead of senders.
|
||||||
|
if (cmd != null && cmd.getSubCommands().size() > 0)
|
||||||
|
{
|
||||||
|
// If we compiled in Java 8, I could have used streams :(
|
||||||
|
for (MassiveCommand sub : cmd.getSubCommands())
|
||||||
|
{
|
||||||
|
if ( ! sub.isVisibleTo(sender)) continue;
|
||||||
|
for (String subAlias : sub.getAliases())
|
||||||
|
{
|
||||||
|
if ( ! subAlias.toLowerCase().startsWith(tokenlc)) continue;
|
||||||
|
ret.add(subAlias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return, so senders is not suggested.
|
||||||
|
return new ArrayList<String>(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If subcommands didn't work, we will try with senders.
|
||||||
List<String> superRet = super.tabComplete(sender, alias, args);
|
List<String> superRet = super.tabComplete(sender, alias, args);
|
||||||
if (args.length == 0) return superRet;
|
if (args.length == 0) return superRet;
|
||||||
|
|
||||||
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
ret.addAll(superRet);
|
ret.addAll(superRet);
|
||||||
|
|
||||||
String tokenlc = args[args.length - 1].toLowerCase();
|
|
||||||
|
|
||||||
// Add names of all online senders that match and isn't added yet.
|
// Add names of all online senders that match and isn't added yet.
|
||||||
for (String senderName : IdUtil.getOnlineNames())
|
for (String senderName : IdUtil.getOnlineNames())
|
||||||
{
|
{
|
||||||
@ -98,13 +131,43 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE: PLUGIN IDENTIFIABLE COMMAND
|
// PRIVATE: TAB COMPLETE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
private MassiveCommand getSubCommand(String[] args, MassiveCommand cmd)
|
||||||
public Plugin getPlugin()
|
|
||||||
{
|
{
|
||||||
return massiveCommand.getRegisteredPlugin();
|
// First we look in the basecommand, then in its subcommands,
|
||||||
|
// and the next subcommand and so on.
|
||||||
|
// Until we run out of args or no subcommand is found.
|
||||||
|
for (int i = 0; i < args.length-1; i++)
|
||||||
|
{
|
||||||
|
String arg = args[i];
|
||||||
|
// If no subcommand is found we will not look further.
|
||||||
|
if (cmd == null) break;
|
||||||
|
|
||||||
|
// We have to loop through the subcommands to see if any match the arg.
|
||||||
|
// if none exists we will get null, thus we break in case of null.
|
||||||
|
cmd = this.getSubCommand(arg, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MassiveCommand getSubCommand(String arg, MassiveCommand cmd)
|
||||||
|
{
|
||||||
|
if (cmd == null || arg == null) return null;
|
||||||
|
|
||||||
|
// We will look in all its subcommands
|
||||||
|
for (MassiveCommand sub : cmd.getSubCommands())
|
||||||
|
{
|
||||||
|
// and in all those look for an alias that matches
|
||||||
|
for (String subAlias : sub.getAliases())
|
||||||
|
{
|
||||||
|
// If it matched we had success
|
||||||
|
if (subAlias.equalsIgnoreCase(arg)) return sub;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user