From edce7f7c3d7093cb5c91c1ad7c3ff7c24cff41ca Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Sat, 1 Feb 2014 11:21:59 +0000 Subject: [PATCH] Add tab completion to /send (Fixes #853) --- .../bungee/module/cmd/send/CommandSend.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java index 8a108aa3..da45a450 100644 --- a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java +++ b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java @@ -1,13 +1,19 @@ package net.md_5.bungee.module.cmd.send; +import com.google.common.collect.ImmutableSet; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; +import net.md_5.bungee.api.plugin.TabExecutor; -public class CommandSend extends Command +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class CommandSend extends Command implements TabExecutor { public CommandSend() @@ -69,4 +75,39 @@ public class CommandSend extends Command player.sendMessage( ChatColor.GOLD + "Summoned to " + target.getName() + " by " + sender.getName() ); } } + + @Override + public Iterable onTabComplete(CommandSender sender, String[] args) + { + if ( args.length > 2 || args.length == 0 ) + { + return ImmutableSet.of(); + } + + Set matches = new HashSet<>(); + if ( args.length == 1 ) + { + String search = args[0].toLowerCase(); + for ( ProxiedPlayer player : ProxyServer.getInstance().getPlayers() ) + { + if ( player.getName().toLowerCase().startsWith( search ) ) + { + matches.add( player.getName() ); + } + } + if ( "all".startsWith( search ) ) matches.add( "all" ); + if ( "current".startsWith( search ) ) matches.add( "current" ); + } else + { + String search = args[1].toLowerCase(); + for ( String server : ProxyServer.getInstance().getServers().keySet() ) + { + if ( server.toLowerCase().startsWith( search ) ) + { + matches.add( server ); + } + } + } + return matches; + } }