/** * Helper function for /up and /ceil. * * @param args The {@link CommandContext} to extract the flags from. * @return true, if glass should always be put under the player */ private boolean getAlwaysGlass(CommandContext args) { final LocalConfiguration config = worldEdit.getConfiguration(); final boolean forceFlight = args.hasFlag('f'); final boolean forceGlass = args.hasFlag('g'); return forceGlass || (config.navigationUseGlass && !forceFlight); } }
public void fromCommand(CommandContext args) { or(Flags.FRIENDLY , args.hasFlag('f')); // No permission check here. Flags will instead be filtered by the subsequent calls. or(Flags.PETS , args.hasFlag('p'), "worldedit.butcher.pets"); or(Flags.NPCS , args.hasFlag('n'), "worldedit.butcher.npcs"); or(Flags.GOLEMS , args.hasFlag('g'), "worldedit.butcher.golems"); or(Flags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals"); or(Flags.AMBIENT , args.hasFlag('b'), "worldedit.butcher.ambient"); or(Flags.TAGGED , args.hasFlag('t'), "worldedit.butcher.tagged"); or(Flags.ARMOR_STAND , args.hasFlag('r'), "worldedit.butcher.armorstands"); or(Flags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); }
private BlockVector3[] getChangesForEachDir(CommandContext args) { List<BlockVector3> changes = new ArrayList<>(6); int change = args.getInteger(0); if (!args.hasFlag('h')) { changes.add((BlockVector3.at(0, 1, 0)).multiply(change)); changes.add((BlockVector3.at(0, -1, 0)).multiply(change)); } if (!args.hasFlag('v')) { changes.add((BlockVector3.at(1, 0, 0)).multiply(change)); changes.add((BlockVector3.at(-1, 0, 0)).multiply(change)); changes.add((BlockVector3.at(0, 0, 1)).multiply(change)); changes.add((BlockVector3.at(0, 0, -1)).multiply(change)); } return changes.toArray(new BlockVector3[0]); }
@Test public void testFlagsAnywhere() { try { CommandContext context = new CommandContext("r hello -f"); assertTrue(context.hasFlag('f')); CommandContext context2 = new CommandContext("r hello -f world"); assertTrue(context2.hasFlag('f')); } catch (CommandException e) { log.log(Level.WARNING, "Error", e); fail("Error creating CommandContext"); } }
@Command( aliases = { "/green", "green" }, usage = "[radius]", desc = "Greens the area", flags = "f", min = 0, max = 1 ) @CommandPermissions("worldedit.green") @Logging(PLACEMENT) public void green(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { final double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10; final boolean onlyNormalDirt = !args.hasFlag('f'); final int affected = editSession.green(session.getPlacementPosition(player), size, onlyNormalDirt); player.print(affected + " surfaces greened."); }
@Command(aliases = {"report"}, desc = "Writes a report on WorldEdit", flags = "p", max = 0) @CommandPermissions({"worldedit.report"}) public void report(Actor actor, CommandContext args) throws WorldEditException { ReportList report = new ReportList("Report"); report.add(new SystemInfoReport()); report.add(new ConfigReport()); String result = report.toString(); try { File dest = new File(we.getWorkingDirectoryFile(we.getConfiguration().saveDir), "report.txt"); Files.write(result, dest, Charset.forName("UTF-8")); actor.print("WorldEdit report written to " + dest.getAbsolutePath()); } catch (IOException e) { actor.printError("Failed to write report: " + e.getMessage()); } if (args.hasFlag('p')) { actor.checkPermission("worldedit.report.pastebin"); ActorCallbackPaste.pastebin( we.getSupervisor(), actor, result, "WorldEdit report: %s.report", WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter() ); } }
/** * Get the right {@link ArgumentStack}. * * @param parameter the parameter * @param existing the existing scoped context * @return the context to use */ private static ArgumentStack getScopedContext(Parameter parameter, ArgumentStack existing) { if (parameter.getFlag() != null) { CommandContext context = existing.getContext(); if (parameter.isValueFlag()) { return new StringArgumentStack(context, context.getFlag(parameter.getFlag()), false); } else { String v = context.hasFlag(parameter.getFlag()) ? "true" : "false"; return new StringArgumentStack(context, v, true); } } return existing; }
if (args.hasFlag('d')) { RegionSelectorType found = null; for (RegionSelectorType type : RegionSelectorType.values()) {
return !parameter.isValueFlag() || context.hasFlag(parameter.getFlag()); } else { int numberFree = context.argsLength() - scoped.position();
if (context.hasFlag('?')) { throw new InvalidUsageException(null, this, true);
@Test public void testExactJoinedStrings() { try { CommandContext context = new CommandContext("r -f \"hello world\" foo bar"); assertTrue(context.hasFlag('f')); assertEquals("\"hello world\" foo bar", context.getJoinedStrings(0)); assertEquals("foo bar", context.getJoinedStrings(1)); CommandContext context2 = new CommandContext("pm name \"hello world\" foo bar"); assertEquals("\"hello world\" foo bar", context2.getJoinedStrings(1)); } catch (CommandException e) { log.log(Level.WARNING, "Error", e); fail("Error creating CommandContext"); } }
context.setSession(session); context.setRestricted(false); context.setPreferringWildcard(!args.hasFlag('f'));
if (args.hasFlag('c')) { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard();
@Command(aliases = {"testplace"}, usage = "[player]", desc = "Simulate a block place", min = 1, max = 1, flags = "ts") @CommandPermissions("worldguard.debug.event") public void firePlaceEvent(CommandContext args, final Actor sender) throws CommandException { LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0)); worldGuard.getPlatform().getDebugHandler().testPlace(sender, target, args.hasFlag('t'), args.hasFlag('s')); }