@Override public void registerCommands(Dispatcher dispatcher) { for (CommandMapping command : dispatcher.getCommands()) { CommandAdapter adapter = new CommandAdapter(command) { @Override public CommandResult process(CommandSource source, String arguments) throws org.spongepowered.api.command.CommandException { CommandEvent weEvent = new CommandEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getPrimaryAlias() + " " + arguments); WorldEdit.getInstance().getEventBus().post(weEvent); return weEvent.isCancelled() ? CommandResult.success() : CommandResult.empty(); } @Override public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException { CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getPrimaryAlias() + " " + arguments); WorldEdit.getInstance().getEventBus().post(weEvent); return weEvent.getSuggestions(); } }; Sponge.getCommandManager().register(SpongeWorldEdit.inst(), adapter, command.getAllAliases()); } }
@Override public CommandResult process(CommandSource source, String commandLine) throws CommandException { final String[] argSplit = commandLine.split(" ", 2); Optional<CommandMapping> cmdOptional = get(argSplit[0], source); if (!cmdOptional.isPresent()) { throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]); // TODO: Fix properly to use a SpongeTranslation?? } final String arguments = argSplit.length > 1 ? argSplit[1] : ""; CommandMapping mapping = cmdOptional.get(); Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping); pluginOwner.ifPresent(pluginContainer -> Sponge.getCauseStackManager().pushCause(pluginContainer)); final CommandCallable spec = mapping.getCallable(); Sponge.getCauseStackManager().pushCause(spec); try { return spec.process(source, arguments); } catch (CommandNotFoundException e) { throw new CommandException(t("No such child command: %s", e.getCommand())); } finally { if (pluginOwner.isPresent()) { Sponge.getCauseStackManager().popCause(); } Sponge.getCauseStackManager().popCause(); } }
manager.removeMapping(mapping); .child(specUsers, "users", "user") .build(); manager.register(WebAPI.getInstance(), spec, "webapi").map(m -> mappings.add(m)); manager.register(WebAPI.getInstance(), entry.getValue(), entry.getKey()).map(m -> mappings.add(m));
commandManager.getOwnedBy(this).stream() .filter(mapping -> "register".equalsIgnoreCase(mapping.getPrimaryAlias())) .forEach(commandManager::removeMapping); commandManager.register(this, injector.getInstance(TwoFactorRegisterCommand.class).buildSpec(config), "register", "reg"); } else if (config.getGeneral().getHashAlgo() == HashingAlgorithm.BCrypt) { commandManager.register(this, injector.getInstance(PasswordRegisterCommand.class).buildSpec(config), "register", "reg");
public static CommandResult executeCommand(String command, CommandSource source) { CommandManager cmdManager = Sponge.getGame().getCommandManager(); return cmdManager.process(source, command); }
@Listener public void onCommand(SendCommandEvent commandEvent) { String command = commandEvent.getCommand(); Optional<? extends CommandMapping> commandOpt = commandManager.get(command); if (isOurCommand(command)) { //fake the cancelled event commandEvent.setCancelled(true); } }
@Override public void onDisable() { super.onDisable(); signs.clear(); if (signCommandManager != null) { Sponge.getCommandManager().removeMapping(signCommandManager); } }
private void triggerMechanic(Location<World> location, @Nullable Player player) { if (player != null && !usePermission.hasPermission(player)) { player.sendMessage(USE_PERMISSIONS); return; } Sign sign = location.getTileEntity().map(tile -> (Sign) tile).get(); if (SignUtil.getTextRaw(sign, 0).equalsIgnoreCase("EXPANSION")) { return; } StringBuilder command = new StringBuilder(); do { if(command.length() > 0 && !SignUtil.getTextRaw(sign, 0).equals("EXPANSION")) break; sign = location.getTileEntity().map(tile -> (Sign) tile).get(); command.append(SignUtil.getTextRaw(sign, 2)).append(SignUtil.getTextRaw(sign, 3)); location = location.getRelative(Direction.DOWN); } while(isValid(location)); String commandString = command.toString(); if (player == null) { if (commandString.contains("@p")) { return; } } else { commandString = commandString.replace("@p", player.getName()); } if (commandString.startsWith("/")) { commandString = commandString.substring(1); } Sponge.getCommandManager().process(Sponge.getServer().getConsole(), commandString); }
@Listener(order = Order.FIRST, beforeModifications = true) public void onCommand(SendCommandEvent commandEvent, @First Player player) { String command = commandEvent.getCommand(); Optional<? extends CommandMapping> commandOpt = commandManager.get(command); if (commandOpt.isPresent()) { CommandMapping mapping = commandOpt.get(); command = mapping.getPrimaryAlias(); //do not blacklist our own commands if (commandManager.getOwner(mapping) .map(pc -> pc.getId().equals(PomData.ARTIFACT_ID)) .orElse(false)) { return; } } commandEvent.setResult(CommandResult.empty()); if (settings.getGeneral().isCommandOnlyProtection()) { List<String> protectedCommands = settings.getGeneral().getProtectedCommands(); if (protectedCommands.contains(command) && !plugin.getDatabase().isLoggedIn(player)) { player.sendMessage(settings.getText().getProtectedCommand()); commandEvent.setCancelled(true); } } else { checkLoginStatus(commandEvent, player); } }
private void actOnCommandEvent(SendCommandEvent event) { String commandName = event.getCommand(); boolean logUnknownCommands = config.isTrue(DataGatheringSettings.LOG_UNKNOWN_COMMANDS); boolean combineCommandAliases = config.isTrue(DataGatheringSettings.COMBINE_COMMAND_ALIASES); if (!logUnknownCommands || combineCommandAliases) { Optional<? extends CommandMapping> existingCommand = Sponge.getCommandManager().get(commandName); if (!existingCommand.isPresent()) { if (!logUnknownCommands) { return; } } else if (combineCommandAliases) { commandName = existingCommand.get().getPrimaryAlias(); } } processing.submit(processors.commandProcessor(commandName)); }
@Override public void onDisable() { super.onDisable(); if (areaCommandMapping != null) { Sponge.getCommandManager().removeMapping(areaCommandMapping); } }
@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); } }
@Override public void dispatchCommand(String command) { Sponge.getGame().getCommandManager().process(Sponge.getServer().getConsole().getCommandSource().get(), command); }
private ExecuteCommandResponse runCommand(SecurityContext context, ExecuteCommandRequest req) { String cmd = req.getCommand().split(" ")[0]; Optional<? extends CommandMapping> map = Sponge.getCommandManager().get(cmd); if (!map.isPresent()) { return new ExecuteCommandResponse(req.command, "Unknown command: " + cmd); } String name = map.get().getPrimaryAlias(); if (!context.hasPerms(name)) { return new ExecuteCommandResponse(req.getCommand(), "You are not allowed to execute '" + cmd + "'"); } final CommandSource src = new CommandSource(req.getName(), req.getWaitLines(), req.isHiddenInConsole()); try { WebAPI.runOnMain(() -> WebAPI.executeCommand(req.getCommand(), src)); if (req.getWaitLines() > 0 || req.getWaitTime() > 0) { synchronized (src) { src.wait(req.getWaitTime() > 0 ? req.getWaitTime() : CMD_WAIT_TIME); } } return new ExecuteCommandResponse(req.command, src.getLines()); } catch (InterruptedException e) { e.printStackTrace(); WebAPI.sentryCapture(e); return new ExecuteCommandResponse(req.command, e.getMessage()); } }
@Override public void onDisable() { super.onDisable(); disabledPlayers.save(config); if (treelopperCommandMapping != null) { Sponge.getCommandManager().removeMapping(treelopperCommandMapping); } }
@Listener public void onServerStart(GameStartedServerEvent event) { this.game.getCommandManager().register(this, this, "spark"); }
public static void dispatchCommand(MessageReceivedEvent e) { String args[] = e.getMessage().getContentDisplay().replace(MagiBridge.getConfig().CHANNELS.CONSOLE_COMMAND + " ", "").split(" "); if (!canUseCommand(e.getMember(), args[0])) { DiscordHandler.sendMessageToChannel(e.getChannel().getId(), MagiBridge.getConfig().MESSAGES.CONSOLE_NO_PERMISSION); return; } String cmd = e.getMessage().getContentDisplay().replace(MagiBridge.getConfig().CHANNELS.CONSOLE_COMMAND + " ", ""); Sponge.getCommandManager().process(new BridgeCommandSource(e.getChannel().getId(), Sponge.getServer().getConsole()), cmd); }
@Override public void onDisable() { super.onDisable(); try { config.getNode("variables").setValue(new TypeToken<Map<String, Map<String, String>>>() {}, variableStore); } catch (ObjectMappingException e) { e.printStackTrace(); } if (variableCommandMapping != null) { Sponge.getCommandManager().removeMapping(variableCommandMapping); } }
@Override public void registerCommand(CommandSpec command) { game.getCommandManager().register(this, new PEXSpongeCommand(command, this), command.getAliases()); }