public boolean dispatchCommand(CommandSender sender, String commandLine) { return dispatchCommand( sender, commandLine, null ); }
@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { List<String> suggestions = new ArrayList<>(); proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, suggestions ); candidates.addAll( suggestions ); int lastSpace = buffer.lastIndexOf( ' ' ); return ( lastSpace == -1 ) ? cursor - buffer.length() : cursor - ( buffer.length() - lastSpace - 1 ); } }
while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null ) if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) )
@Override public void handle(Chat chat) throws Exception { int maxLength = ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_11 ) ? 256 : 100; Preconditions.checkArgument( chat.getMessage().length() <= maxLength, "Chat message too long" ); // Mojang limit, check on updates ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() ); if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) { chat.setMessage( chatEvent.getMessage() ); if ( !chatEvent.isCommand() || !bungee.getPluginManager().dispatchCommand( con, chat.getMessage().substring( 1 ) ) ) { con.getServer().unsafe().sendPacket( chat ); } } throw CancelSendSignal.INSTANCE; }
bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions );
public boolean dispatchCommand(CommandSender sender, String commandLine) { return dispatchCommand( sender, commandLine, null ); }
@Override public int complete( String buffer, int cursor, List<CharSequence> candidates ) { List<String> offers = new ArrayList<>(); if ( !proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, offers ) ) { return cursor; } Iterables.addAll( candidates, offers ); final int lastSpace = buffer.lastIndexOf( ' ' ); if ( lastSpace == -1 ) { return cursor - buffer.length(); } else { return cursor - ( buffer.length() - lastSpace - 1 ); } } }
@EventHandler public void onPubSubMessage(PubSubMessageEvent event) { if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + RedisBungee.getApi().getServerId())) { String message = event.getMessage(); if (message.startsWith("/")) message = message.substring(1); plugin.getLogger().info("Invoking command via PubSub: /" + message); plugin.getProxy().getPluginManager().dispatchCommand(RedisBungeeCommandSender.instance, message); } } }
@Override public void dispatchCommand(String command) { plugin.getProxy().getPluginManager().dispatchCommand(plugin.getProxy().getConsole(), command); }
@Override public void executeCommand(String cmd) { ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), cmd); }
while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null ) if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) )
@Override public void handle(Chat chat) throws Exception { Preconditions.checkArgument( chat.getMessage().length() <= 100, "Chat message too long" ); // Mojang limit, check on updates Preconditions.checkArgument(!StringUtil.isBlank(chat.getMessage()), "Chat message is empty"); ServerConnection server = con.getServer(); // if we're still connecting just ignore this packet if ( server == null ) { throw CancelSendSignal.INSTANCE; } ChatEvent chatEvent = new ChatEvent( con, server, chat.getMessage() ); if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) { chat.setMessage( chatEvent.getMessage() ); if ( !chatEvent.isCommand() || !bungee.getPluginManager().dispatchCommand( con, chat.getMessage().substring( 1 ) ) ) { server.unsafe().sendPacket( chat ); } } throw CancelSendSignal.INSTANCE; }
@Override public void handle(TabCompleteRequest tabComplete) throws Exception { if ( bungee.getConfig().getTabThrottle() > 0 ) { long now = System.currentTimeMillis(); if ( lastTabCompletion > 0 && (now - lastTabCompletion) <= bungee.getConfig().getTabThrottle() ) { throw CancelSendSignal.INSTANCE; } lastTabCompletion = now; } List<String> suggestions = new ArrayList<>(); if ( tabComplete.getCursor().startsWith( "/" ) ) { bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions ); } TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions ); bungee.getPluginManager().callEvent( tabCompleteEvent ); if ( tabCompleteEvent.isCancelled() ) { throw CancelSendSignal.INSTANCE; } List<String> results = tabCompleteEvent.getSuggestions(); if ( !results.isEmpty() ) { con.unsafe().sendPacket( new TabCompleteResponse( results ) ); throw CancelSendSignal.INSTANCE; } }
private void onCommandForward(CommandSender invoker, ByteArrayDataInput dataInput) { ForwardMessage message = new ForwardMessage(); message.readFrom(dataInput); if (message.isOP() && message.isSource()) { //bukkit op and it won't run as bungee console invoker.addGroups(plugin.getName() + "-OP"); } String line = message.getCommandName() + ' ' + message.getArgs(); if (message.isSource()) { //the player is the actual invoker other it's the console ProxyServer.getInstance().getPluginManager().dispatchCommand(invoker, line); } else { CommandSender console = ProxyServer.getInstance().getConsole(); ProxyServer.getInstance().getPluginManager().dispatchCommand(console, line); } } }
@EventHandler public void handleChannel(PluginMessageEvent pluginMessageEvent) { if (!(pluginMessageEvent.getReceiver() instanceof ProxiedPlayer)) return; if (pluginMessageEvent.getTag().equalsIgnoreCase("cloudnet:main")) { ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(pluginMessageEvent.getData()); switch (byteArrayDataInput.readUTF().toLowerCase()) { case "connect": List<String> servers = CloudProxy.getInstance().getServers(byteArrayDataInput.readUTF()); if (servers.size() == 0) return; ((ProxiedPlayer) pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance().getServerInfo(servers.get(NetworkUtils.RANDOM.nextInt(servers.size())))); break; case "fallback": ((ProxiedPlayer) pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance() .getServerInfo(CloudProxy.getInstance() .fallback(((ProxiedPlayer) pluginMessageEvent.getReceiver())))); break; case "command": ProxyServer.getInstance().getPluginManager().dispatchCommand(((ProxiedPlayer) pluginMessageEvent.getReceiver()), byteArrayDataInput.readUTF()); break; } } }
public static void main(String[] args) throws Exception { BungeeCord bungee = new BungeeCord(); ProxyServer.setInstance( bungee ); bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); bungee.start(); while ( bungee.isRunning ) { String line = bungee.getConsoleReader().readLine( ">" ); if ( line != null ) { if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) ) { bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); } } } } }
TimoCloudBungee.getInstance().getProxy().getPluginManager().dispatchCommand(TimoCloudBungee.getInstance().getProxy().getConsole(), (String) data); break; case "ADD_SERVER":