Skip to content

Commit

Permalink
Filter auto-complete arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Jul 22, 2023
1 parent 3a33b7b commit d935ae3
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SlashServerCommand extends BaseCommand {
Expand Down Expand Up @@ -60,6 +60,6 @@ public void execute(ICommandSender sender, String[] args) {

@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
return new ArrayList<>();
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class LeaveCommand extends BaseCommand {
Expand Down Expand Up @@ -105,11 +106,12 @@ private String getQueueList(List<QueueServer> servers) {

@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
if(args.length > 1) return Collections.emptyList();
List<QueuePlayer> servers = main.getQueueManager().findPlayerInQueues(main.getPlatformMethods().senderToPlayer(sender));
List<String> serverNames = new ArrayList<>();
for(QueuePlayer queuePlayer : servers) {
serverNames.add(queuePlayer.getQueueServer().getName());
}
return serverNames;
return filterCompletion(serverNames, args[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListCommand extends BaseCommand {
Expand Down Expand Up @@ -79,6 +79,6 @@ public void execute(ICommandSender sender, String[] args) {

@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
return new ArrayList<>();
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public void execute(ICommandSender sender, String[] args) {
@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
if(args.length == 1) {
return main.getPlatformMethods().getPlayerNames(false);
return filterCompletion(main.getPlatformMethods().getPlayerNames(false), args[0]);
}
if(args.length == 2) {
return main.getQueueManager().getServerNames();
return filterCompletion(main.getQueueManager().getServerNames(), args[1]);
}
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class KickAll extends SubCommand {
Expand Down Expand Up @@ -65,9 +66,9 @@ public void execute(ICommandSender sender, String[] args) {
@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
if(args.length == 1) {
return main.getQueueManager().getServerNames();
return filterCompletion(main.getQueueManager().getServerNames(), args[0]);
}
return new ArrayList<>();
return Collections.emptyList();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ public List<String> autoComplete(ICommandSender sender, String[] args) {
commands.add(subCommand.getName());
commands.addAll(subCommand.getAliases());
}
return commands;
return filterCompletion(commands, args[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public List<String> autoComplete(ICommandSender sender, String[] args) {
if(args.length == 1) {
List<String> servers = new ArrayList<>(main.getQueueManager().getServerNames());
servers.add("all");
return servers;
return filterCompletion(servers, args[0]);
}
if(args.length == 2) {
return Arrays.asList("on", "off", "true", "false");
return filterCompletion(Arrays.asList("on", "off", "true", "false"), args[1]);
}
return new ArrayList<>();
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -88,6 +88,6 @@ public void execute(ICommandSender sender, String[] args) {

@Override
public java.util.List<String> autoComplete(ICommandSender sender, String[] args) {
return new ArrayList<>();
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Reload extends SubCommand {
Expand Down Expand Up @@ -63,6 +63,6 @@ public void execute(ICommandSender sender, String[] args) {

@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
return new ArrayList<>();
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Send extends SubCommand {
Expand Down Expand Up @@ -93,12 +94,12 @@ public List<String> autoComplete(ICommandSender sender, String[] args) {
if(args.length == 1) {
List<String> options = new ArrayList<>(main.getPlatformMethods().getServerNames());
options.addAll(main.getPlatformMethods().getPlayerNames(false));
return options;
return filterCompletion(options, args[0]);
}
if(args.length == 2) {
return main.getQueueManager().getServerNames();
return filterCompletion(main.getQueueManager().getServerNames(), args[1]);
}
return new ArrayList<>();
return Collections.emptyList();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class QueueCommand extends BaseCommand {
Expand Down Expand Up @@ -92,7 +89,7 @@ public void execute(ICommandSender sender, String[] args) {
@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
if(!main.getConfig().getBoolean("tab-complete-queues")) {
return new ArrayList<>();
return Collections.emptyList();
}
if(args.length == 1) {
List<String> servers = filterCompletion(main.getQueueManager().getServerNames(), args[0]);
Expand All @@ -101,6 +98,6 @@ public List<String> autoComplete(ICommandSender sender, String[] args) {
}
return servers;
}
return new ArrayList<>();
return Collections.emptyList();
}
}

0 comments on commit d935ae3

Please sign in to comment.