Suggestions for unknown command response (#5165)

This commit is contained in:
Skat
2021-04-29 13:11:51 -04:00
committed by GitHub
parent 73f0593acf
commit 0e1c4ccd6d
+17 -2
View File
@@ -236,7 +236,22 @@ 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
text = "[scarlet]Unknown command. Check [lightgray]/help[scarlet]."; 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].";
}
} }
player.sendMessage(text); player.sendMessage(text);
@@ -279,7 +294,7 @@ public class NetClient implements ApplicationListener{
public static void kick(KickReason reason){ public static void kick(KickReason reason){
netClient.disconnectQuietly(); netClient.disconnectQuietly();
logic.reset(); logic.reset();
if(reason == KickReason.serverRestarting){ if(reason == KickReason.serverRestarting){
ui.join.reconnect(); ui.join.reconnect();
return; return;