Suggestions for unknown command response (#5165)

This commit is contained in:
Skat
2021-04-29 21:11:51 +04:00
committed by GitHub
parent 73f0593acf
commit 0e1c4ccd6d

View File

@@ -236,8 +236,23 @@ public class NetClient implements ApplicationListener{
}else if(response.type == ResponseType.fewArguments){ }else if(response.type == ResponseType.fewArguments){
text = "[scarlet]Too few arguments. Usage:[lightgray] " + response.command.text + "[gray] " + response.command.paramText; text = "[scarlet]Too few arguments. Usage:[lightgray] " + response.command.text + "[gray] " + response.command.paramText;
}else{ //unknown command }else{ //unknown command
int minDst = 0;
Command closest = null;
for(Command command : netServer.clientCommands.getCommandList()){
int dst = Strings.levenshtein(command.text, response.runCommand);
if(dst < 3 && (closest == null || dst < minDst)){
minDst = dst;
closest = command;
}
}
if(closest != null){
text = "[scarlet]Unknown command. Did you mean \"[lightgray]" + closest.text + "[]\"?";
}else{
text = "[scarlet]Unknown command. Check [lightgray]/help[scarlet]."; text = "[scarlet]Unknown command. Check [lightgray]/help[scarlet].";
} }
}
player.sendMessage(text); player.sendMessage(text);
} }