/** * Return the arguments that were consumed between this point and that marked point. * * <p>The marked position initially starts at 0.</p> * * @return the consumed arguments */ public String getConsumed() { return context.getString(markedIndex, index); }
/** * Reset to the previously {@link #mark()}ed position of the stack, and return * the arguments that were consumed between this point and that previous point. * * <p>The marked position initially starts at 0.</p> * * @return the consumed arguments */ public String reset() { String value = context.getString(markedIndex, index); index = markedIndex; return value; }
public String getRemainingString(int start) { return getString(start, parsedArgs.size() - 1); }
@Override public String next() throws ParameterException { try { return context.getString(index++); } catch (IndexOutOfBoundsException e) { throw new MissingParameterException(); } }
@Override public Integer nextInt() throws ParameterException { try { return Integer.parseInt(next()); } catch (NumberFormatException e) { throw new ParameterException( "Expected a number, got '" + context.getString(index - 1) + "'"); } }
@Override public Integer nextInt() throws ParameterException { try { return Integer.parseInt(next()); } catch (NumberFormatException e) { throw new ParameterException( "Expected a number, got '" + context.getString(index - 1) + "'"); } }
@Override public Double nextDouble() throws ParameterException { try { return Double.parseDouble(next()); } catch (NumberFormatException e) { throw new ParameterException( "Expected a number, got '" + context.getString(index - 1) + "'"); } }
@Override public Double nextDouble() throws ParameterException { try { return Double.parseDouble(next()); } catch (NumberFormatException e) { throw new ParameterException( "Expected a number, got '" + context.getString(index - 1) + "'"); } }
@Command( aliases = { "tz" }, usage = "[timezone]", desc = "Set your timezone for snapshots", min = 1, max = 1 ) public void tz(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { TimeZone tz = TimeZone.getTimeZone(args.getString(0)); session.setTimezone(tz); player.print("Timezone set for this session to: " + tz.getDisplayName()); player.print("The current time in that timezone is: " + dateFormat.format(Calendar.getInstance(tz).getTime())); }
public CommandArgs parse(String arguments) throws CommandException { CommandContext context = new CommandContext(CommandContext.split("_ " + arguments), Collections.<Character>emptySet(), false, null, false); List<String> args = Lists.newArrayList(); for (int i = 0; i < context.argsLength(); i++) { args.add(context.getString(i)); } if (isUsingHangingArguments()) { if (arguments.isEmpty() || arguments.endsWith(" ")) { args.add(""); } } return new CommandArgs(args); } }
@Command( aliases = { "delete", "d" }, usage = "<filename>", desc = "Delete a saved schematic", help = "Delete a schematic from the schematic list", min = 1, max = 1 ) @CommandPermissions("worldedit.schematic.delete") public void delete(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { LocalConfiguration config = worldEdit.getConfiguration(); String filename = args.getString(0); File dir = worldEdit.getWorkingDirectoryFile(config.saveDir); File f = worldEdit.getSafeSaveFile(player, dir, filename, "schematic", "schematic"); if (!f.exists()) { player.printError("Schematic " + filename + " does not exist!"); return; } if (!f.delete()) { player.printError("Deletion of " + filename + " failed! Maybe it is read-only."); return; } player.print(filename + " has been deleted."); }
@Command( aliases = { "/", "," }, usage = "[on|off]", desc = "Toggle the super pickaxe function", min = 0, max = 1 ) @CommandPermissions("worldedit.superpickaxe") public void togglePickaxe(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { String newState = args.getString(0, null); if (session.hasSuperPickAxe()) { if ("on".equals(newState)) { player.printError("Super pick axe already enabled."); return; } session.disableSuperPickAxe(); player.print("Super pick axe disabled."); } else { if ("off".equals(newState)) { player.printError("Super pick axe already disabled."); return; } session.enableSuperPickAxe(); player.print("Super pick axe enabled."); } }
@Command( aliases = { "/fast" }, usage = "[on|off]", desc = "Toggle fast mode", min = 0, max = 1 ) @CommandPermissions("worldedit.fast") public void fast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { String newState = args.getString(0, null); if (session.hasFastMode()) { if ("on".equals(newState)) { player.printError("Fast mode already enabled."); return; } session.setFastMode(false); player.print("Fast mode disabled."); } else { if ("off".equals(newState)) { player.printError("Fast mode already disabled."); return; } session.setFastMode(true); player.print("Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes."); } }
@Command( aliases = { "tree" }, usage = "[type]", desc = "Tree generator tool", min = 0, max = 1 ) @CommandPermissions("worldedit.tool.tree") public void tree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { TreeGenerator.TreeType type = args.argsLength() > 0 ? TreeGenerator.lookup(args.getString(0)) : TreeGenerator.TreeType.TREE; if (type == null) { player.printError("Tree type '" + args.getString(0) + "' is unknown."); return; } BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new TreePlanter(type)); player.print("Tree tool bound to " + itemStack.getType().getName() + "."); }
@Command( aliases = { "/reorder" }, usage = "[multi|fast|none]", desc = "Sets the reorder mode of WorldEdit", min = 0, max = 1 ) @CommandPermissions("worldedit.reorder") public void reorderMode(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { String newState = args.getString(0, null); if (newState == null) { player.print("The reorder mode is " + session.getReorderMode().getDisplayName()); } else { java.util.Optional<EditSession.ReorderMode> reorderModeOptional = EditSession.ReorderMode.getFromDisplayName(newState); if (!reorderModeOptional.isPresent()) { player.printError("Unknown reorder mode!"); return; } EditSession.ReorderMode reorderMode = reorderModeOptional.get(); session.setReorderMode(reorderMode); player.print("The reorder mode is now " + session.getReorderMode().getDisplayName()); } }
@Command( aliases = { "/fill" }, usage = "<block> <radius> [depth]", desc = "Fill a hole", min = 2, max = 3 ) @CommandPermissions("worldedit.fill") @Logging(PLACEMENT) public void fill(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { ParserContext context = new ParserContext(); context.setActor(player); context.setWorld(player.getWorld()); context.setSession(session); Pattern pattern = we.getPatternFactory().parseFromInput(args.getString(0), context); double radius = Math.max(1, args.getDouble(1)); we.checkMaxRadius(radius); int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1; BlockVector3 pos = session.getPlacementPosition(player); int affected = editSession.fillXZ(pos, pattern, radius, depth, false); player.print(affected + " block(s) have been created."); }
@Test public void testBasicArgs() { String command = firstCommand.getCommand(); String argOne = firstCommand.getString(0); String joinedArg = firstCommand.getJoinedStrings(0); assertEquals("herpderp", command); assertEquals("another thing", argOne); assertEquals("'another thing' because something", joinedArg); }
@Command( aliases = { "cs" }, usage = "<filename> [args...]", desc = "Execute a CraftScript", min = 1, max = -1 ) @CommandPermissions("worldedit.scripting.execute") @Logging(ALL) public void execute(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { String[] scriptArgs = args.getSlice(1); String name = args.getString(0); if (!player.hasPermission("worldedit.scripting.execute." + name)) { player.printError("You don't have permission to use that script."); return; } session.setLastScript(name); File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir); File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js"); worldEdit.runScript(player, f, scriptArgs); }
@Command( aliases = { "/removenear", "removenear" }, usage = "<block> [size]", desc = "Remove blocks near you.", min = 1, max = 2 ) @CommandPermissions("worldedit.removenear") @Logging(PLACEMENT) public void removeNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { ParserContext context = new ParserContext(); context.setActor(player); context.setWorld(player.getWorld()); context.setSession(session); context.setRestricted(false); context.setPreferringWildcard(false); BaseBlock block = we.getBlockFactory().parseFromInput(args.getString(0), context); int size = Math.max(1, args.getInteger(1, 50)); we.checkMaxRadius(size); int affected = editSession.removeNear(session.getPlacementPosition(player), block.getBlockType(), size); player.print(affected + " block(s) have been removed."); }
@Command( aliases = { "/count" }, usage = "<block>", desc = "Counts the number of a certain type of block", min = 1, max = 1 ) @CommandPermissions("worldedit.analysis.count") public void count(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { ParserContext context = new ParserContext(); context.setActor(player); context.setExtent(player.getExtent()); context.setWorld(player.getWorld()); context.setSession(session); context.setRestricted(false); Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(args.getString(0), context); int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks); player.print("Counted: " + count); }