Skip to content

Commit

Permalink
Added autocompletion for /togglechat <team ...>.
Browse files Browse the repository at this point in the history
Related to #35.
  • Loading branch information
AmauryCarrade committed Aug 31, 2014
1 parent aca9944 commit a6dab63
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/main/java/me/azenet/UHPlugin/UHPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

public final class UHPlugin extends JavaPlugin {

private UHPluginCommand commandManager = null;
private UHTabCompleter tabCompleter = null;

private UHTeamManager teamManager = null;
private UHGameManager gameManager = null;
private UHPluginCommand commandManager = null;
private UHBorderManager borderManager = null;
private UHRecipeManager recipeManager = null;
private UHTeamChatManager teamChatManager = null;
Expand Down Expand Up @@ -81,13 +83,16 @@ public void onEnable() {
protocollibintegrationwrapper = new UHProtocolLibIntegrationWrapper(this);

commandManager = new UHPluginCommand(this);
getCommand("uh").setExecutor(commandManager);
getCommand("uh").setTabCompleter(new UHTabCompleter(this));
tabCompleter = new UHTabCompleter(this);

getCommand("uh").setExecutor(commandManager);
getCommand("t").setExecutor(commandManager);
getCommand("g").setExecutor(commandManager);
getCommand("togglechat").setExecutor(commandManager);

getCommand("uh").setTabCompleter(tabCompleter);
getCommand("togglechat").setTabCompleter(tabCompleter);

getServer().getPluginManager().registerEvents(new UHGameListener(this), this);
getServer().getPluginManager().registerEvents(new UHGameplayListener(this), this);
getServer().getPluginManager().registerEvents(new UHCraftingListener(this), this);
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/me/azenet/UHPlugin/UHTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

public class UHTabCompleter implements TabCompleter {

Expand Down Expand Up @@ -72,10 +73,26 @@ public UHTabCompleter(UHPlugin plugin) {

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!command.getName().equalsIgnoreCase("uh")) {
if (!command.getName().equalsIgnoreCase("uh") && !command.getName().equalsIgnoreCase("togglechat")) {
return null;
}

/** ** Autocompletion for the /togglechat command ** **/

if(command.getName().equalsIgnoreCase("togglechat")) {
if(sender instanceof Player && ((Player) sender).hasPermission("uh.teamchat.others")) {
ArrayList<String> teamNames = new ArrayList<String>();
for(UHTeam team : this.p.getTeamManager().getTeams()) {
teamNames.add(team.getName());
}
return getAutocompleteSuggestions(args[0], teamNames);
}
return null;
}


/** ** Autocompletion for the /uh command ** **/

/** Autocompletion for subcommands **/
if(args.length == 1) {
return getAutocompleteSuggestions(args[0], this.commands);
Expand Down

0 comments on commit a6dab63

Please sign in to comment.