@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(); }
@Test public void testEmptyChildrenWorks() throws CommandException { final AtomicBoolean parent = new AtomicBoolean(); final CommandSpec spec = CommandSpec.builder() .children(ImmutableMap.<List<String>, CommandSpec>of()) .executor((s, c) -> { parent.set(true); return CommandResult.success(); }) .build(); final SimpleDispatcher execute = new SimpleDispatcher(); execute.register(spec, "emptyparent"); execute.process(mock(CommandSource.class), "emptyparent"); assertTrue(parent.get()); }
@Test public void testEmptyChildrenWorksWithOptionalArgument() throws CommandException { final AtomicBoolean parent = new AtomicBoolean(); final CommandSpec spec = CommandSpec.builder() .arguments(GenericArguments.optional(GenericArguments.string(Text.of("b")))) .children(ImmutableMap.<List<String>, CommandSpec>builder() .put(Lists.newArrayList("aaa"), CommandSpec.builder().executor((s, c) -> CommandResult.empty()).build()).build()) .executor((s, c) -> { parent.set(true); return CommandResult.success(); }) .build(); final SimpleDispatcher execute = new SimpleDispatcher(); execute.register(spec, "emptyparentwithopt"); execute.process(mock(CommandSource.class), "emptyparentwithopt"); assertTrue(parent.get()); }
@Test public void testEmptyChildrenWorksWithArgument() throws CommandException { final AtomicBoolean parent = new AtomicBoolean(); final CommandSpec spec = CommandSpec.builder() .arguments(GenericArguments.optional(GenericArguments.string(Text.of("a")))) .children(ImmutableMap.<List<String>, CommandSpec>of()) .executor((s, c) -> { parent.set(true); return CommandResult.success(); }) .build(); final SimpleDispatcher execute = new SimpleDispatcher(); execute.register(spec, "emptyparentwith"); execute.process(mock(CommandSource.class), "emptyparentwith child"); assertTrue(parent.get()); }
@Test public void testSimpleChildCommandIsSuppressedOnError() throws CommandException { final AtomicBoolean parentExecuted = new AtomicBoolean(); final AtomicBoolean childExecuted = new AtomicBoolean(); final CommandSpec spec = CommandSpec.builder() .children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder() .arguments(GenericArguments.literal(Text.of("test"), "test")) .executor((src, args) -> { childExecuted.set(true); return CommandResult.builder().successCount(1).build(); }) .build())) .arguments(GenericArguments.literal(Text.of("t"), "child")) .executor((src, args) -> { parentExecuted.set(true); return CommandResult.success(); }) .build(); final SimpleDispatcher execute = new SimpleDispatcher(); execute.register(spec, "parent"); execute.process(mock(CommandSource.class), "parent child"); assertFalse(childExecuted.get()); assertTrue(parentExecuted.get()); }
@Test public void testSimpleChildCommandIsThrownOnErrorWhenSelected() throws CommandException { final AtomicBoolean parentExecuted = new AtomicBoolean(); final AtomicBoolean childExecuted = new AtomicBoolean(); final CommandSpec spec = CommandSpec.builder() .children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder() .arguments(GenericArguments.literal(Text.of("test"), "test")) .executor((src, args) -> { childExecuted.set(true); return CommandResult.builder().successCount(1).build(); }) .build())) .arguments(GenericArguments.literal(Text.of("t"), "child")) .executor((src, args) -> { parentExecuted.set(true); return CommandResult.success(); }) .childArgumentParseExceptionFallback(false) .build(); final SimpleDispatcher execute = new SimpleDispatcher(); execute.register(spec, "parent"); try { execute.process(mock(CommandSource.class), "parent child"); } catch (ArgumentParseException ex) { // ignored - we check this with the booleans } assertFalse(childExecuted.get()); assertFalse(parentExecuted.get()); }
@Test public void testErrorOnNonExistentChildWithNoOtherParameters() throws CommandException { final CommandSpec spec = CommandSpec.builder() .children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder() .executor((src, args) -> CommandResult.builder().successCount(1).build()) .build())) .childArgumentParseExceptionFallback(false) .executor((src, args) -> CommandResult.success()) .build(); final SimpleDispatcher execute = new SimpleDispatcher(); execute.register(spec, "parent"); try { execute.process(mock(CommandSource.class), "parent wrong"); } catch (ArgumentParseException ex) { assertEquals("Input command wrong was not a valid subcommand!\nwrong\n^", ex.getMessage()); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { src.sendMessage(docsText); return CommandResult.success(); } }
@Override public CommandResult executeCommand(CommandSource src, CommandContext args, Cause cause) throws Exception { return CommandResult.success(); } }
@Override public CommandResult process(CommandSource source, String arguments) throws CommandException { String[] args = arguments.length() > 0 ? arguments.split(" ") : new String[0]; onCommand(new SpongeCommandSender(source), args); return CommandResult.success(); }
@Override public CommandResult process(CommandSource commandSource, String arguments) throws CommandException { command.process(new SpongeCommander(plugin, commandSource), arguments); return CommandResult.success(); }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { User user = args.<User>getOne("user").get(); String password = args.<String>getOne("password").get(); uuidRegister(user.getUniqueId(), src, password); return CommandResult.success(); }
@Override public CommandResult execute(CommandSource src, CommandContext gargs) throws CommandException { Player player = (Player) gargs.getOne("sniper").get(); Sniper sniper = SniperManager.get().getSniperForPlayer(player); Optional<Integer> count = gargs.getOne("count"); if (count.isPresent()) { sniper.undo(count.get()); } else { sniper.undo(1); } return CommandResult.success(); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Map<String, Object> data = new LinkedHashMap<>(); data.put("source", WebAPI.getCacheService().asCachedObject(src)); for (WebHookParam param : cmdHook.getParams()) { data.put(param.getName(), param.getValue(args).orElse(null)); } WebAPI.getWebHookService().notifyHook(cmdHook, src.getIdentifier(), data); return CommandResult.success(); } }
@Override public CommandResult execute(CommandSource source, CommandContext args) { plugin.onReload(); source.sendMessage(settings.getText().getOnReload()); return CommandResult.success(); }
@Override public CommandResult execute(CommandSource src, CommandContext gargs) throws CommandException { Player player = (Player) gargs.getOne("sniper").get(); Player target = (Player) gargs.getOne("target").get(); SniperManager.get().getSniperForPlayer(target).undo(1); player.sendMessage(Text.of(TextColors.GREEN, "One action of player " + target.getName() + " has been undone")); return CommandResult.success(); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) { User user = args.<User>getOne("user").get(); String password = args.<String>getOne("password").get(); //check if the account is a valid player name Task.builder() //Async as it could run a SQL query .async() .execute(new UUIDResetPwTask(plugin, src, password, user.getUniqueId())) .submit(plugin); return CommandResult.success(); }
@Override public CommandResult execute(CommandSource src, CommandContext gargs) throws CommandException { Player player = (Player) gargs.getOne("sniper").get(); Sniper sniper = SniperManager.get().getSniperForPlayer(player); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); snipeData.setcCen((int) gargs.getOne("center").get()); snipeData.getVoxelMessage().center(); return CommandResult.success(); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { if (whitelist) { WebAPI.getSecurityService().toggleWhitelist(true); src.sendMessage(Text.of("Enabled whitelist")); } else { WebAPI.getSecurityService().toggleBlacklist(true); src.sendMessage(Text.of("Enabled blacklist")); } return CommandResult.success(); } }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { src.sendMessage(Text.of(TextColors.YELLOW, "About CraftBook")); src.sendMessage(Text.of("===============")); src.sendMessage(Text.of("Version: " + CraftBookPlugin.spongeInst().container.getVersion().orElse("UNKNOWN"))); src.sendMessage(Text.of("Build: " + CraftBookPlugin.BUILD_NUMBER)); src.sendMessage(Text.of("Commit: " + CraftBookPlugin.GIT_HASH)); return CommandResult.success(); } }