if ( !command.hasPermission( sender ) ) } ); command.execute( sender, args ); } else if ( commandLine.contains( " " ) && command instanceof TabExecutor )
/** * Register a command so that it may be executed. * * @param plugin the plugin owning this command * @param command the command to register */ public void registerCommand(Plugin plugin, Command command) { commandMap.put( command.getName().toLowerCase( Locale.ROOT ), command ); for ( String alias : command.getAliases() ) { commandMap.put( alias.toLowerCase( Locale.ROOT ), command ); } commandsByPlugin.put( plugin, command ); }
@Override public void execute(CommandSender sender, String[] args) { if (args.length > 0 && subCommands.containsKey(args[0])) { Command command = subCommands.get(args[0]); if (command.getPermission() == null || checkPermission(sender, command)) { command.execute(sender, Arrays.copyOfRange(args, 1, args.length)); } else { sender.sendMessage(TextComponent.fromLegacyText(ProxyServer.getInstance().getTranslation("no_permission"))); } } else if (defaultAction != null) { defaultAction.accept(sender); } else { sender.sendMessage(ChatUtil.parseBBCode("&cWrong usage!")); } }
@Override public Iterable<String> onTabComplete(CommandSender sender, String[] args) { if (args.length == 1) { return subCommands.keySet().stream() .filter(cmd -> cmd.startsWith(args[0])) .collect(Collectors.toList()); } else if (args.length > 1) { Command command = subCommands.get(args[0]); if (command != null && command instanceof TabExecutor) { if (command.getPermission() == null || checkPermission(sender, command)) { ((TabExecutor) command).onTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); } } } return Collections.emptyList(); }
@Override public void handle(Commands commands) throws Exception { boolean modified = false; if ( BungeeCord.getInstance().config.isInjectCommands() ) { for ( Map.Entry<String, Command> command : bungee.getPluginManager().getCommands() ) { if ( !bungee.getDisabledCommands().contains( command.getKey() ) && commands.getRoot().getChild( command.getKey() ) == null && command.getValue().hasPermission( con ) ) { LiteralCommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() ) .then( RequiredArgumentBuilder.argument( "args", StringArgumentType.greedyString() ) .suggests( Commands.SuggestionRegistry.ASK_SERVER ) ) .build(); commands.getRoot().addChild( dummy ); modified = true; } } } if ( modified ) { con.unsafe().sendPacket( commands ); throw CancelSendSignal.INSTANCE; } }
String permission = command.getPermission(); if ( permission != null && !permission.isEmpty() && !sender.hasPermission( permission ) ) } ); command.execute( sender, args ); } else if ( commandLine.contains( " " ) && command instanceof TabExecutor )
private static boolean checkPermission(CommandSender sender, Command command) { return BungeeTabListPlus.getInstance().getPermissionManager().hasPermission(sender, command.getPermission()); } }
public void addSubCommand(Command command) { subCommands.put(command.getName(), command); for (String alias : command.getAliases()) { subCommands.put(alias, command); } }
/** * Register a command so that it may be executed. * * @param plugin the plugin owning this command * @param command the command to register */ public void registerCommand(Plugin plugin, Command command) { commandMap.put( command.getName().toLowerCase(), command ); for ( String alias : command.getAliases() ) { commandMap.put( alias.toLowerCase(), command ); } commandsByPlugin.put( plugin, command ); }