From 88157110adcc0b626b6801c4451066eeba974ffc Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 16 May 2016 16:59:57 +1000 Subject: [PATCH] Implement TabCompleteEvent --- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 11 +++++++++-- .../craftbukkit/command/ConsoleCommandCompleter.java | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index acf14fd525..a7c7dca65f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -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 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 tabCompleteCommand(Player player, String message) { diff --git a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java b/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java index 7ef5772719..c576f4f78a 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java +++ b/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java @@ -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> waitable = new Waitable>() { @Override protected List evaluate() { - return server.getCommandMap().tabComplete(server.getConsoleSender(), buffer); + List 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);