66import fr .zcraft .quartzlib .components .rawtext .RawText ;
77import fr .zcraft .quartzlib .components .rawtext .RawTextPart ;
88import fr .zcraft .quartzlib .tools .text .StringUtils ;
9+ import java .util .List ;
10+ import java .util .stream .Collectors ;
911import org .bukkit .ChatColor ;
1012import org .bukkit .command .CommandSender ;
1113import org .jetbrains .annotations .Nullable ;
@@ -33,10 +35,14 @@ public RawText display(CommandSender sender) {
3335
3436 if (nearest != null ) {
3537 text = text .then ("\n " + CHAT_PREFIX ).color (ChatColor .AQUA )
36- .then (" " + I .t ("Did you mean" ) + " : " ).color (ChatColor .GRAY )
38+ .then (" " + I .t ("Did you mean: " ) ).color (ChatColor .GRAY )
3739 .then ("/" ).color (ChatColor .WHITE )
38- .then (getParents () + " " ).color (ChatColor .AQUA )
39- .then (nearest ).color (ChatColor .DARK_AQUA );
40+ .then (getParents () + " " ).style (ChatColor .AQUA , ChatColor .UNDERLINE )
41+ .hover (I .t ("Click to insert this command" ))
42+ .suggest ("/" + getParents () + " " + nearest )
43+ .then (nearest ).style (ChatColor .DARK_AQUA , ChatColor .UNDERLINE )
44+ .hover (I .t ("Click to insert this command" ))
45+ .suggest ("/" + getParents () + " " + nearest );
4046 }
4147
4248 return text .build ();
@@ -46,20 +52,12 @@ public RawText display(CommandSender sender) {
4652
4753 @ Nullable
4854 private String getNearestCommand () {
49- String nearest = null ;
50- int nearestDistance = MAX_DISTANCE ;
55+ List <String > names = commandGroup .getSubCommands ()
56+ .stream ()
57+ .map (CommandNode ::getName )
58+ .collect (Collectors .toList ());
5159
52- for (CommandNode subCommand : commandGroup .getSubCommands ()) {
53- String name = subCommand .getName ();
54- int distance = StringUtils .levenshteinDistance (attemptedSubcommand , name );
55-
56- if (distance < nearestDistance ) {
57- nearest = name ;
58- nearestDistance = distance ;
59- }
60- }
61-
62- return nearest ;
60+ return StringUtils .levenshteinNearest (attemptedSubcommand , names , MAX_DISTANCE );
6361 }
6462
6563 private String getParents () {
0 commit comments