Big Break: Change the Command Completion Handler signature to match Context

For consistency, make Completion Handlers be implemented the same way Context Handlers are.

Previously when we added the Context parameter, we left the original signature in place and simply tacked , c on the end.

This made migration easier than changing all completion handlers bodies.

But since 0.5.0 is a big migration already, let's just get it over with.

See changes to Bukkit default completions and the example plugin for migration example.
This commit is contained in:
Aikar
2017-06-14 22:17:33 -04:00
parent 14a1c33926
commit 15b149d55c
10 changed files with 27 additions and 26 deletions
@@ -35,11 +35,11 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class BungeeCommandCompletions extends CommandCompletions<CommandSender, BungeeCommandCompletionContext> {
public class BungeeCommandCompletions extends CommandCompletions<BungeeCommandCompletionContext> {
public BungeeCommandCompletions(CommandManager manager) {
super(manager);
registerCompletion("chatcolors", (sender, config, input, c) -> {
registerCompletion("chatcolors", c -> {
Stream<ChatColor> colors = Stream.of(ChatColor.values());
if (c.hasConfig("colorsonly")) {
colors = colors.filter(color -> color.ordinal() <= 0xF);
@@ -54,8 +54,10 @@ public class BungeeCommandCompletions extends CommandCompletions<CommandSender,
return colors.map(color -> ACFUtil.simplifyString(color.name())).collect(Collectors.toList());
});
registerCompletion("players", (sender, config, input, c) -> {
registerCompletion("players", c -> {
CommandSender sender = c.getSender();
ACFBungeeUtil.validate(sender, "Sender cannot be null");
String input = c.getInput();
ArrayList<String> matchedPlayers = new ArrayList<>();
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
@@ -60,7 +60,7 @@ public class BungeeCommandManager extends CommandManager {
}
@Override
public synchronized CommandCompletions<CommandSender, BungeeCommandCompletionContext> getCommandCompletions() {
public synchronized CommandCompletions<BungeeCommandCompletionContext> getCommandCompletions() {
if (this.completions == null) {
this.completions = new BungeeCommandCompletions(this);
}
@@ -69,7 +69,6 @@ public class BungeeCommandManager extends CommandManager {
@Override
public void registerCommand(BaseCommand command) {
final String plugin = this.plugin.getDescription().getName().toLowerCase();
command.onRegister(this);
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
String key = entry.getKey().toLowerCase();