org.bukkit.craftbukkit.command.ConsoleCommandCompleter Maven / Gradle / Ivy
package org.bukkit.craftbukkit.command;
import jline.console.completer.Completer;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Waitable;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
public class ConsoleCommandCompleter implements Completer {
private final CraftServer server;
public ConsoleCommandCompleter(CraftServer server) {
this.server = server;
}
public int complete(final String buffer, final int cursor, final List candidates) {
Waitable> waitable = new Waitable>() {
@Override
protected List evaluate() {
return server.getCommandMap().tabComplete(server.getConsoleSender(), buffer);
}
};
this.server.getServer().processQueue.add(waitable);
try {
List offers = waitable.get();
if (offers == null) {
return cursor;
}
candidates.addAll(offers);
final int lastSpace = buffer.lastIndexOf(' ');
if (lastSpace == -1) {
return cursor - buffer.length();
} else {
return cursor - (buffer.length() - lastSpace - 1);
}
} catch (ExecutionException e) {
this.server.getLogger().log(Level.WARNING, "Unhandled exception when tab completing", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return cursor;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy