Merge pull request #2228 from Minecrell/patch-2
Fix some issues with the console command completion
This commit is contained in:
commit
cef50616d8
2 changed files with 15 additions and 13 deletions
|
@ -2,6 +2,7 @@ package net.minecraftforge.server.console;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -28,14 +29,9 @@ public final class ConsoleCommandCompleter implements Completer
|
||||||
public int complete(String buffer, int cursor, List<CharSequence> candidates)
|
public int complete(String buffer, int cursor, List<CharSequence> candidates)
|
||||||
{
|
{
|
||||||
int len = buffer.length();
|
int len = buffer.length();
|
||||||
buffer = buffer.trim();
|
|
||||||
if (buffer.isEmpty())
|
|
||||||
{
|
|
||||||
return cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean prefix;
|
boolean prefix;
|
||||||
if (buffer.charAt(0) != '/')
|
if (buffer.isEmpty() || buffer.charAt(0) != '/')
|
||||||
{
|
{
|
||||||
buffer = '/' + buffer;
|
buffer = '/' + buffer;
|
||||||
prefix = false;
|
prefix = false;
|
||||||
|
@ -59,6 +55,7 @@ public final class ConsoleCommandCompleter implements Completer
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<String> completions = tabComplete.get();
|
List<String> completions = tabComplete.get();
|
||||||
|
Collections.sort(completions);
|
||||||
if (prefix)
|
if (prefix)
|
||||||
{
|
{
|
||||||
candidates.addAll(completions);
|
candidates.addAll(completions);
|
||||||
|
@ -76,6 +73,10 @@ public final class ConsoleCommandCompleter implements Completer
|
||||||
{
|
{
|
||||||
return cursor - len;
|
return cursor - len;
|
||||||
}
|
}
|
||||||
|
else if (prefix)
|
||||||
|
{
|
||||||
|
return cursor - len + pos + 1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return cursor - len + pos;
|
return cursor - len + pos;
|
||||||
|
|
|
@ -34,14 +34,15 @@ public final class TerminalHandler
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
line = reader.readLine("> ");
|
line = reader.readLine("> ");
|
||||||
|
if (line == null)
|
||||||
if (line != null)
|
|
||||||
{
|
{
|
||||||
line = line.trim();
|
break;
|
||||||
if (!line.isEmpty())
|
}
|
||||||
{
|
|
||||||
server.addPendingCommand(line, server);
|
line = line.trim();
|
||||||
}
|
if (!line.isEmpty())
|
||||||
|
{
|
||||||
|
server.addPendingCommand(line, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|
Loading…
Reference in a new issue