Server command completion

This commit is contained in:
md_5 2013-09-15 07:43:50 +10:00
parent e998faeec1
commit c108e4e1ce

View File

@ -1,16 +1,23 @@
package net.md_5.bungee.command; package net.md_5.bungee.command;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
/** /**
* Command to list and switch a player between available servers. * Command to list and switch a player between available servers.
*/ */
public class CommandServer extends Command public class CommandServer extends Command implements TabExecutor
{ {
public CommandServer() public CommandServer()
@ -60,4 +67,24 @@ public class CommandServer extends Command
} }
} }
} }
@Override
public Iterable<String> onTabComplete(final CommandSender sender, String[] args)
{
return Iterables.transform( Iterables.filter( ProxyServer.getInstance().getServers().values(), new Predicate<ServerInfo>()
{
@Override
public boolean apply(ServerInfo input)
{
return input.canAccess( sender );
}
} ), new Function<ServerInfo, String>()
{
@Override
public String apply(ServerInfo input)
{
return input.getName();
}
} );
}
} }