diff --git a/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java b/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java new file mode 100644 index 00000000..2fcd8616 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/event/TabCompleteEvent.java @@ -0,0 +1,39 @@ +package net.md_5.bungee.api.event; + +import java.util.List; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import net.md_5.bungee.api.connection.Connection; +import net.md_5.bungee.api.plugin.Cancellable; + +/** + * Event called when a player uses tab completion. + */ +@Data +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class TabCompleteEvent extends TargetedEvent implements Cancellable +{ + + /** + * Cancelled state. + */ + private boolean cancelled; + /** + * The message the player has already entered. + */ + private final String cursor; + /** + * The suggestions that will be sent to the client. This list is mutable. If + * this list is empty, the request will be forwarded to the server. + */ + private final List suggestions; + + public TabCompleteEvent(Connection sender, Connection receiver, String cursor, List suggestions) + { + super( sender, receiver ); + this.cursor = cursor; + this.suggestions = suggestions; + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index c29cbd07..bec51bda 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -9,6 +9,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.TabCompleteEvent; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.PacketWrapper; @@ -99,16 +100,26 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(TabCompleteRequest tabComplete) throws Exception { + List suggestions = new ArrayList<>(); + if ( tabComplete.getCursor().startsWith( "/" ) ) { - List results = new ArrayList<>(); - bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), results ); + bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions ); + } - if ( !results.isEmpty() ) - { - con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) ); - throw CancelSendSignal.INSTANCE; - } + TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions ); + bungee.getPluginManager().callEvent( tabCompleteEvent ); + + List results = tabCompleteEvent.getSuggestions(); + if ( !results.isEmpty() ) + { + con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) ); + throw CancelSendSignal.INSTANCE; + } + + if ( tabCompleteEvent.isCancelled() ) + { + throw CancelSendSignal.INSTANCE; } }