Skip to content
Permalink
Browse files

Improve player target suggestions prioritization

  • Loading branch information
DarkArc committed Jan 5, 2020
1 parent e8db3cc commit 4b5af179a0df05b5b5d08121a56fd08add1f5bda
@@ -49,14 +49,14 @@ public Component describeAcceptableArguments() {
public List<String> getSuggestions(String input) {
List<String> suggestions = new ArrayList<>();

SuggestionHelper.addPlayerNameSuggestions(suggestions, input);

SuggestionHelper.trialAddPlayerSuggestion(suggestions, "*");
SuggestionHelper.trialAddPlayerSuggestion(suggestions, "#world");
SuggestionHelper.trialAddPlayerSuggestion(suggestions, "#near");
SuggestionHelper.trialAddPlayerSuggestion(suggestions, input + "*");
SuggestionHelper.trialAddPlayerSuggestion(suggestions, "*" + input);

SuggestionHelper.addPlayerNameSuggestions(suggestions);

return suggestions;
}
}
@@ -49,7 +49,7 @@ public Component describeAcceptableArguments() {
public List<String> getSuggestions(String input) {
List<String> suggestions = new ArrayList<>();

SuggestionHelper.addPlayerNameSuggestions(suggestions);
SuggestionHelper.addPlayerNameSuggestions(suggestions, input);

return suggestions;
}
@@ -109,7 +109,7 @@ public Component describeAcceptableArguments() {
List<String> suggestions = new ArrayList<>();

if (normalizedSplit(input).length == 1) {
SuggestionHelper.addPlayerNameSuggestions(suggestions);
SuggestionHelper.addPlayerNameSuggestions(suggestions, input);
}

return suggestions;
@@ -6,6 +6,7 @@
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@@ -19,18 +20,31 @@ public static void trialAddPlayerSuggestion(List<String> suggestions, String tra
} catch (CommandException ignored) { }
}

public static void addPlayerNameSuggestions(List<String> suggestions) {
public static void addPlayerNameSuggestions(List<String> suggestions, String input) {
Collection<? extends Player> players = CommandBook.server().getOnlinePlayers();
boolean useDisplayNames = CommandBook.inst().lookupWithDisplayNames;

List<String> secondarySuggestions = new ArrayList<>();

for (Player player : players) {
String playerName = player.getName();
String displayName = ChatColor.stripColor(player.getDisplayName());

suggestions.add(playerName);
if (playerName.startsWith(input)) {
suggestions.add(playerName);
} else {
secondarySuggestions.add(playerName);
}

String displayName = ChatColor.stripColor(player.getDisplayName());
if (useDisplayNames && !playerName.equals(displayName)) {
suggestions.add(displayName);
if (displayName.startsWith(input)) {
suggestions.add(displayName);
} else {
secondarySuggestions.add(displayName);
}
}
}

suggestions.addAll(secondarySuggestions);
}
}

0 comments on commit 4b5af17

Please sign in to comment.
You can’t perform that action at this time.