Add TabCompleteEvent
This commit is contained in:
parent
9cd7c1ac03
commit
92ebce2ec6
@ -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<String> suggestions;
|
||||||
|
|
||||||
|
public TabCompleteEvent(Connection sender, Connection receiver, String cursor, List<String> suggestions)
|
||||||
|
{
|
||||||
|
super( sender, receiver );
|
||||||
|
this.cursor = cursor;
|
||||||
|
this.suggestions = suggestions;
|
||||||
|
}
|
||||||
|
}
|
@ -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.ChatEvent;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
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.ChannelWrapper;
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
import net.md_5.bungee.netty.PacketHandler;
|
||||||
import net.md_5.bungee.protocol.PacketWrapper;
|
import net.md_5.bungee.protocol.PacketWrapper;
|
||||||
@ -99,16 +100,26 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
@Override
|
@Override
|
||||||
public void handle(TabCompleteRequest tabComplete) throws Exception
|
public void handle(TabCompleteRequest tabComplete) throws Exception
|
||||||
{
|
{
|
||||||
|
List<String> suggestions = new ArrayList<>();
|
||||||
|
|
||||||
if ( tabComplete.getCursor().startsWith( "/" ) )
|
if ( tabComplete.getCursor().startsWith( "/" ) )
|
||||||
{
|
{
|
||||||
List<String> results = new ArrayList<>();
|
bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions );
|
||||||
bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), results );
|
}
|
||||||
|
|
||||||
|
TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions );
|
||||||
|
bungee.getPluginManager().callEvent( tabCompleteEvent );
|
||||||
|
|
||||||
|
List<String> results = tabCompleteEvent.getSuggestions();
|
||||||
if ( !results.isEmpty() )
|
if ( !results.isEmpty() )
|
||||||
{
|
{
|
||||||
con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) );
|
con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) );
|
||||||
throw CancelSendSignal.INSTANCE;
|
throw CancelSendSignal.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( tabCompleteEvent.isCancelled() )
|
||||||
|
{
|
||||||
|
throw CancelSendSignal.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user