/** * This should be called whenever the command gets registered. * It sets all required fields correctly and injects dependencies. * * @param manager * The manager to register as this command's owner and handler. */ void onRegister(CommandManager manager) { onRegister(manager, this.commandName); }
@Override public boolean hasPermission(CommandIssuer sender) { return command.hasPermission(sender); }
default List<String> getTabCompletions(CommandIssuer sender, String alias, String[] args, boolean commandsOnly) { Set<String> completions = new HashSet<>(); getChildren().forEach(child -> { if (!commandsOnly) { completions.addAll(child.tabComplete(sender, alias, args)); } completions.addAll(child.getCommandsForCompletion(sender, args)); }); return new ArrayList<>(completions); }
public void registerCommand(BaseCommand command, boolean force) { final String plugin = this.plugin.getName().toLowerCase(); command.onRegister(this); for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { String commandName = entry.getKey().toLowerCase(); if (split.length > 1) { oldCommand.unregister(commandMap); oldCommand.setLabel(split[0] + ":" + command.getName()); oldCommand.register(commandMap);
/** * Gets tab completed data from the given command from the user. * * @param issuer * The user who executed the tabcomplete. * @param commandLabel * The label which is being used by the user. * @param args * The arguments the user has typed so far. * * @return All possibilities in the tab complete. */ public List<String> tabComplete(CommandIssuer issuer, String commandLabel, String[] args) { return tabComplete(issuer, commandLabel, args, false); }
default void addChildShared(List<BaseCommand> children, SetMultimap<String, RegisteredCommand> subCommands, BaseCommand command) { command.subCommands.entries().forEach(e -> { String key = e.getKey(); RegisteredCommand registeredCommand = e.getValue(); if (key.equals(BaseCommand.DEFAULT) || key.equals(BaseCommand.CATCHUNKNOWN)) { return; } Set<RegisteredCommand> registered = subCommands.get(key); if (!registered.isEmpty()) { BaseCommand prevBase = registered.iterator().next().scope; if (prevBase != registeredCommand.scope) { this.getManager().log(LogLevel.ERROR, "ACF Error: " + command.getName() + " registered subcommand " + key + " for root command " + getCommandName() + " - but it is already defined in " + prevBase.getName()); this.getManager().log(LogLevel.ERROR, "2 subcommands of the same prefix may not be spread over 2 different classes. Ignoring this."); return; } } subCommands.put(key, registeredCommand); }); children.add(command); }
private void executeCommand(CommandOperationContext commandOperationContext, CommandIssuer issuer, String[] args, RegisteredCommand cmd) { if (cmd.hasPermission(issuer)) { commandOperationContext.setRegisteredCommand(cmd); if (checkPrecommand(commandOperationContext, cmd, issuer, args)) { return; } List<String> sargs = Arrays.asList(args); cmd.invoke(issuer, sargs, commandOperationContext); } else { issuer.sendMessage(MessageType.ERROR, MessageKeys.PERMISSION_DENIED); } }
void invoke(CommandIssuer sender, List<String> args, CommandOperationContext context) { if (!scope.canExecute(sender, this)) { return; } preCommand(); try { this.manager.conditions.validateConditions(context); Map<String, Object> passedArgs = resolveContexts(sender, args); if (passedArgs == null) return; method.invoke(scope, passedArgs.values().toArray()); } catch (Exception e) { handleException(sender, args, e); } postCommand(); } public void preCommand() {}
@Override public List<String> tabComplete(CommandIssuer issuer, String alias, String[] args) throws IllegalArgumentException { return command.tabComplete(issuer, alias, ApacheCommonsLangUtil.addAll(baseArgs, args)); }
@Override public void registerCommand(BaseCommand command) { command.onRegister(this); for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { String commandName = entry.getKey().toLowerCase(); JDARootCommand cmd = (JDARootCommand) entry.getValue(); if (!cmd.isRegistered) { cmd.isRegistered = true; commands.put(commandName, cmd); } } }
@Override public boolean testPermission(@NotNull CommandSource source) { return this.defCommand.hasPermission(source); }
@EventHandler(ignoreCancelled = true) public void onAsyncTabComplete(AsyncTabCompleteEvent event) { String buffer = event.getBuffer(); if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) { return; } try { //noinspection ConstantConditions,ConstantIfStatement if (false) throw new CommandCompletions.SyncCompletionRequired(); // fake compiler due to SneakyThrows String[] args = ACFPatterns.SPACE.split(buffer, -1); String commandLabel = args[0]; if (commandLabel.startsWith("/")) { commandLabel = commandLabel.substring(1); } args = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[]{""}; BaseCommand cmd = this.manager.getBaseCommand(commandLabel, args); if (cmd == null) { return; } BukkitCommandIssuer issuer = this.manager.getCommandIssuer(event.getSender()); List<String> results = cmd.tabComplete(issuer, commandLabel, args, true); event.setCompletions(ACFUtil.preformOnImmutable( event.getCompletions(), (list) -> list.addAll(results))); event.setHandled(true); } catch (Exception ignored) {} }
@Override public void registerCommand(BaseCommand command) { command.onRegister(this); for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { String commandName = entry.getKey().toLowerCase(); SpongeRootCommand spongeCommand = (SpongeRootCommand) entry.getValue(); if (!spongeCommand.isRegistered) { Sponge.getCommandManager().register(this.plugin, spongeCommand, commandName); } spongeCommand.isRegistered = true; registeredCommands.put(commandName, spongeCommand); } }
public boolean hasPermission(Object issuer) { return hasPermission(manager.getCommandIssuer(issuer)); }
@Override public void registerCommand(BaseCommand command) { command.onRegister(this); for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) { String commandName = entry.getKey().toLowerCase(); BungeeRootCommand bungeeCommand = (BungeeRootCommand) entry.getValue(); if (!bungeeCommand.isRegistered) { this.plugin.getProxy().getPluginManager().registerCommand(this.plugin, bungeeCommand); } bungeeCommand.isRegistered = true; registeredCommands.put(commandName, bungeeCommand); } }
public boolean hasPermission(CommandIssuer issuer) { return permission == null || permission.isEmpty() || (manager.hasPermission(issuer, permission) && (parentCommand == null || parentCommand.hasPermission(issuer))); }
subCommand.onRegister(manager, cmd); this.subCommands.putAll(subCommand.subCommands); this.registeredCommands.putAll(subCommand.registeredCommands);
boolean hasPermission(CommandIssuer issuer) { return (permission == null || permission.isEmpty() || scope.manager.hasPermission(issuer, permission)) && scope.hasPermission(issuer); }