mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 11:27:35 +01:00
Implement TabCompleteEvent
This commit is contained in:
parent
4e19de1295
commit
88157110ad
@ -126,6 +126,7 @@ import io.netty.buffer.ByteBufOutputStream;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.base64.Base64;
|
||||
import jline.console.ConsoleReader;
|
||||
import org.bukkit.event.server.TabCompleteEvent;
|
||||
|
||||
public final class CraftServer implements Server {
|
||||
private static final Player[] EMPTY_PLAYER_ARRAY = new Player[0];
|
||||
@ -1536,12 +1537,18 @@ public final class CraftServer implements Server {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
List<String> offers;
|
||||
Player player = ((EntityPlayer) sender).getBukkitEntity();
|
||||
if (message.startsWith("/")) {
|
||||
return tabCompleteCommand(player, message);
|
||||
offers = tabCompleteCommand(player, message);
|
||||
} else {
|
||||
return tabCompleteChat(player, message);
|
||||
offers = tabCompleteChat(player, message);
|
||||
}
|
||||
|
||||
TabCompleteEvent tabEvent = new TabCompleteEvent(player, message, offers);
|
||||
getPluginManager().callEvent(tabEvent);
|
||||
|
||||
return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
|
||||
}
|
||||
|
||||
public List<String> tabCompleteCommand(Player player, String message) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.bukkit.craftbukkit.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
@ -8,6 +9,7 @@ import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
|
||||
import jline.console.completer.Completer;
|
||||
import org.bukkit.event.server.TabCompleteEvent;
|
||||
|
||||
public class ConsoleCommandCompleter implements Completer {
|
||||
private final CraftServer server;
|
||||
@ -20,7 +22,12 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
||||
@Override
|
||||
protected List<String> evaluate() {
|
||||
return server.getCommandMap().tabComplete(server.getConsoleSender(), buffer);
|
||||
List<String> offers = server.getCommandMap().tabComplete(server.getConsoleSender(), buffer);
|
||||
|
||||
TabCompleteEvent tabEvent = new TabCompleteEvent(server.getConsoleSender(), buffer, offers);
|
||||
server.getPluginManager().callEvent(tabEvent);
|
||||
|
||||
return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
|
||||
}
|
||||
};
|
||||
this.server.getServer().processQueue.add(waitable);
|
||||
|
Loading…
Reference in New Issue
Block a user