Java Code Examples for com.sk89q.minecraft.util.commands.CommandContext#argsLength()
The following examples show how to use
com.sk89q.minecraft.util.commands.CommandContext#argsLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavigationCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Command( aliases = {"ceil"}, usage = "[clearance]", desc = "Go to the celing", flags = "fg", min = 0, max = 1 ) @CommandPermissions("worldedit.navigation.ceiling") @Logging(POSITION) public void ceiling(Player player, LocalSession session, CommandContext args) throws WorldEditException { final int clearance = args.argsLength() > 0 ? Math.max(0, args.getInteger(0)) : 0; final boolean alwaysGlass = getAlwaysGlass(args); if (player.ascendToCeiling(clearance, alwaysGlass)) { BBC.WHOOSH.send(player); } else { BBC.ASCEND_FAIL.send(player); } }
Example 2
Source File: SettingCommands.java From CardinalPGM with MIT License | 6 votes |
@Command(aliases = {"settings"}, desc = "List all settings.", usage = "[page]") public static void settings(final CommandContext cmd, CommandSender sender) throws CommandException { if (cmd.argsLength() == 0) { Bukkit.dispatchCommand(sender, "settings 1"); } else { int page = cmd.getInteger(0); if (page > (Settings.getSettings().size() + 7) / 8) { throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_INVALID_PAGE_NUMBER, "" + (Settings.getSettings().size() + 7) / 8).getMessage(ChatUtil.getLocale(sender))); } sender.sendMessage(ChatColor.RED + "" + ChatColor.STRIKETHROUGH + "--------------" + ChatColor.YELLOW + " Settings (Page " + page + " of " + ((Settings.getSettings().size() + 7) / 8) + ") " + ChatColor.RED + "" + ChatColor.STRIKETHROUGH + "--------------"); for (int i = (page - 1) * 8; i < page * 8; i++) { if (i < Settings.getSettings().size()) { sender.sendMessage(ChatColor.YELLOW + Settings.getSettings().get(i).getNames().get(0) + ": " + ChatColor.WHITE + Settings.getSettings().get(i).getDescription()); } } } }
Example 3
Source File: TeamCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@Command( aliases = {"force"}, desc = "Force a player onto a team", usage = "<player> [team]", min = 1, max = 2 ) @CommandPermissions("pgm.team.force") public void force(CommandContext args, CommandSender sender) throws CommandException, SuggestException { MatchPlayer player = CommandUtils.findSingleMatchPlayer(args, sender, 0); if(args.argsLength() >= 2) { String name = args.getString(1); if(name.trim().toLowerCase().startsWith("obs")) { player.getMatch().setPlayerParty(player, player.getMatch().getDefaultParty()); } else { Team team = utils.teamArgument(args, 1); utils.module().forceJoin(player, team); } } else { utils.module().forceJoin(player, null); } }
Example 4
Source File: TraceCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@Command( aliases = {"off", "stop"}, desc = "Stop logging packets", min = 0, max = 1 ) public void stop(CommandContext args, CommandSender sender) throws CommandException { if(sender instanceof Player || args.argsLength() >= 1) { final Player player = (Player) getCommandSenderOrSelf(args, sender, 0); if(PacketTracer.stop(player)) { sender.sendMessage("Stopped packet trace for " + player.getName(sender)); } } else { traceAll.set(false); if(onlinePlayers.all().stream().anyMatch(PacketTracer::stop)) { sender.sendMessage("Stopped all packet tracing"); } } }
Example 5
Source File: PunishmentCommands.java From CardinalPGM with MIT License | 6 votes |
@Command(aliases = {"warn", "w"}, usage = "<player> [reason]", desc = "Warn a player.", min = 1) @CommandPermissions("cardinal.punish.warn") public static void warn(CommandContext cmd, CommandSender sender) throws CommandException { Player warned = Bukkit.getPlayer(cmd.getString(0)); if (warned == null) { throw new CommandException(ChatConstant.ERROR_NO_PLAYER_MATCH.getMessage(ChatUtil.getLocale(sender))); } String reason = cmd.argsLength() > 1 ? cmd.getJoinedStrings(1) : "You have been warned!"; ChatChannel channel = GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class); channel.sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + ((sender instanceof Player) ? Teams.getTeamColorByPlayer((Player) sender) + ((Player) sender).getDisplayName() : ChatColor.YELLOW + "*Console") + ChatColor.GOLD + " warned " + Teams.getTeamColorByPlayer(warned) + warned.getDisplayName() + ChatColor.GOLD + " for " + reason); warned.sendMessage(ChatColor.RED + "" + ChatColor.MAGIC + "-------" + ChatColor.YELLOW + "WARNING" + ChatColor.RED + ChatColor.MAGIC + "-------"); warned.sendMessage(ChatColor.GREEN + reason); warned.sendMessage(ChatColor.YELLOW + reason); warned.sendMessage(ChatColor.RED + reason); warned.sendMessage(ChatColor.RED + "" + ChatColor.MAGIC + "-------" + ChatColor.YELLOW + "WARNING" + ChatColor.RED + ChatColor.MAGIC + "-------"); }
Example 6
Source File: OptionsCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Command( aliases = {"/gtransform", "gtransform"}, usage = "[transform]", desc = "Set the global transform", min = 0, max = -1 ) @CommandPermissions({"worldedit.global-transform", "worldedit.transform.global"}) public void gtransform(Player player, EditSession editSession, LocalSession session, @Optional CommandContext context) throws WorldEditException { if (context == null || context.argsLength() == 0) { session.setTransform(null); BBC.TRANSFORM_DISABLED.send(player); } else { ParserContext parserContext = new ParserContext(); parserContext.setActor(player); parserContext.setWorld(player.getWorld()); parserContext.setSession(session); parserContext.setExtent(editSession); ResettableExtent transform = Fawe.get().getTransformParser().parseFromInput(context.getJoinedStrings(0), parserContext); session.setTransform(transform); BBC.TRANSFORM.send(player); } }
Example 7
Source File: SelectionCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Command( aliases = {"/shift"}, usage = "<amount> [direction]", desc = "Shift the selection area", min = 1, max = 2 ) @Logging(REGION) @CommandPermissions("worldedit.selection.shift") public void shift(Player player, LocalSession session, CommandContext args) throws WorldEditException { List<Vector> dirs = new ArrayList<Vector>(); int change = args.getInteger(0); if (args.argsLength() == 2) { if (args.getString(1).contains(",")) { for (String s : args.getString(1).split(",")) { dirs.add(we.getDirection(player, s.toLowerCase())); } } else { dirs.add(we.getDirection(player, args.getString(1).toLowerCase())); } } else { dirs.add(we.getDirection(player, "me")); } try { Region region = session.getSelection(player.getWorld()); for (Vector dir : dirs) { region.shift(dir.multiply(change)); } session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); BBC.SELECTION_SHIFT.send(player); } catch (RegionOperationException e) { player.printError(e.getMessage()); } }
Example 8
Source File: CommandUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Get an online {@link CommandSender} by exact name, defaulting to sender */ public static CommandSender getCommandSenderOrSelf(CommandContext args, CommandSender sender, int index) throws CommandException { if(args.argsLength() > index) { Player player = sender.getServer().getPlayerExact(args.getString(index), sender); if(player == null) throw new CommandException(ComponentRenderers.toLegacyText(new TranslatableComponent("command.playerNotFound"), sender)); return player; } else { return sender; } }
Example 9
Source File: CommandUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Get an online {@link Player} by exact name */ public static Player getPlayer(CommandContext args, CommandSender sender, int index) throws CommandException { if(args.argsLength() > index) { Player player = sender.getServer().getPlayerExact(args.getString(index), sender); if(player == null) throw new CommandException(ComponentRenderers.toLegacyText(new TranslatableComponent("command.playerNotFound"), sender)); return player; } else { throw new CommandException(ComponentRenderers.toLegacyText(new TranslatableComponent("command.specifyPlayer"), sender)); } }
Example 10
Source File: MapCommands.java From CardinalPGM with MIT License | 5 votes |
@Command(aliases = {"map", "mapinfo"}, flags = "lm:", desc = "Shows information about the currently playing map.") public static void map(final CommandContext args, CommandSender sender) throws CommandException { LoadedMap mapInfo = args.hasFlag('m') ? RepositoryManager.get().getMap(args.getFlagInteger('m')) : args.argsLength() == 0 ? GameHandler.getGameHandler().getMatch().getLoadedMap() : CycleCommand.getMap(sender, args.getJoinedStrings(0)); if (mapInfo == null) throw new CommandException(ChatConstant.ERROR_NO_MAP_MATCH.getMessage(ChatUtil.getLocale(sender))); sender.sendMessage(Align.padMessage(mapInfo.toShortMessage(ChatColor.DARK_AQUA, args.hasFlag('l'), true), ChatColor.RED)); sender.sendMessage(TITLE_FORM + ChatConstant.UI_MAP_OBJECTIVE.getMessage(ChatUtil.getLocale(sender)) + ": " + CONT_FORM + mapInfo.getObjective()); sendContributors(sender, ChatConstant.UI_MAP_AUTHOR, ChatConstant.UI_MAP_AUTHORS, mapInfo.getAuthors()); sendContributors(sender, ChatConstant.UI_MAP_CONTRIBUTORS, ChatConstant.UI_MAP_CONTRIBUTORS, mapInfo.getContributors()); if (mapInfo.getRules().size() > 0) { sender.sendMessage(TITLE_FORM + ChatConstant.UI_MAP_RULES.getMessage(ChatUtil.getLocale(sender)) + ":"); for (int i = 1; i <= mapInfo.getRules().size(); i++) sender.sendMessage(ChatColor.WHITE + "" + i + ") " + CONT_FORM + mapInfo.getRules().get(i - 1)); } sender.sendMessage(TITLE_FORM + ChatConstant.UI_MAP_MAX.getMessage(ChatUtil.getLocale(sender)) + ": " + CONT_FORM + mapInfo.getMaxPlayers()); if (args.hasFlag('l')) { Repository repo = GameHandler.getGameHandler().getRepositoryManager().getRepo(mapInfo); if (repo != null) { sender.sendMessage(TITLE_FORM + "Source: " + repo.toChatMessage(sender.isOp())); sender.sendMessage(TITLE_FORM + "Folder: " + CONT_FORM + repo.getRoot().toURI().relativize(mapInfo.getFolder().toURI()).getPath()); } else { sender.sendMessage(TITLE_FORM + "Source: " + CONT_FORM + "Unknown"); } } }
Example 11
Source File: TeamCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Command( aliases = {"roster", "players"}, usage = "[team]", desc = "Lists the players on a specified team.", flags = "p:", min = 0, max = -1 ) @Console @CommandPermissions("tourney.roster") public void roster(final CommandContext args, final CommandSender sender) throws CommandException, SuggestException { final int page = args.getFlagInteger('p', 1); final ListenableFuture<Entrant> futureEntrant; if(args.argsLength() > 0) { futureEntrant = tournamentService.entrant(tournament, teamArgument(args, 0)); } else if(sender instanceof Player) { futureEntrant = tournamentService.entrantByMember(tournament, userStore.playerId((Player) sender)); } else { throw new TranslatableCommandException("tourney.team.notSpecified"); } final Audience audience = audiences.get(sender); mainThread.callback( futureEntrant, CommandFutureCallback.<Entrant>onSuccess(sender, args, entrant -> { new Paginator<PlayerId>() .title(new TranslatableComponent("tourney.team.roster.title", tournamentName, teamName(entrant))) .entries((playerId, index) -> new Component(new PlayerComponent(identityProvider.createIdentity(playerId))) .bold(index == 0)) // Team leader is always first .display(audience, entrant.members(), page); }).onFailure(NotFound.class, notFound -> { audience.sendMessage(new WarningComponent("tourney.team.notOnAnyTeam")); }) ); }
Example 12
Source File: ProximityCommand.java From CardinalPGM with MIT License | 5 votes |
@Command(aliases = {"proximity"}, desc = "Shows the proximity of the objectives in the match.", usage = "[team]") public static void proximity(final CommandContext cmd, CommandSender sender) throws CommandException { Optional<TeamModule> team = Optional.absent(); if (cmd.argsLength() > 0) { team = Teams.getTeamByName(cmd.getJoinedStrings(0)); if (!team.isPresent()) throw new CommandException(ChatConstant.ERROR_NO_TEAM_MATCH.getMessage(ChatUtil.getLocale(sender))); } if (!(sender instanceof Player) || ObserverModule.testObserver((Player) sender) || (sender.hasPermission("cardinal.proximity") || (team.isPresent() && team.get().contains(sender)))) { boolean objectives = false; if (team.isPresent() && hasObjectives(team.get())) { sendTeamInfo(team.get(), sender); objectives = true; } else if (!team.isPresent()) { for (TeamModule teams : Teams.getTeams()) { if (!teams.isObserver() && hasObjectives(teams)) { sendTeamInfo(teams, sender); objectives = true; } } } if (!objectives) sender.sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.ERROR_PROXIMITY_NO_SCORING).getMessage(sender instanceof Player ? ((Player) sender).getLocale() : Locale.getDefault().toString())); } else { sender.sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.ERROR_PROXIMITY_OBS_ONLY).getMessage(((Player) sender).getLocale())); } }
Example 13
Source File: TeleportCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Command( aliases = { "remoteteleport", "rtp", "goto" }, desc = "Teleport to a player anywhere on the network", usage = "[traveler] <destination>", min = 1, max = 2 ) public void remoteTeleport(final CommandContext args, final CommandSender sender) throws CommandException { final Player traveler; final ListenableFuture<UserSearchResponse> future; if(args.argsLength() >= 2) { CommandUtils.assertPermission(sender, Teleporter.PERMISSION_OTHERS); traveler = CommandUtils.findOnlinePlayer(args, sender, 0); future = userFinder.findUser(sender, args, 1); } else { CommandUtils.assertPermission(sender, Teleporter.PERMISSION); traveler = CommandUtils.senderToPlayer(sender); future = userFinder.findUser(sender, args, 0); } syncExecutor.callback( future, CommandFutureCallback.onSuccess(sender, args, result -> { final PlayerComponent playerComponent = new PlayerComponent(identityProvider.createIdentity(result), NameStyle.FANCY); if(!result.online) { throw new TranslatableCommandException("command.playerNotOnline", playerComponent); } else if(result.last_server == null) { // Probably because player has disabled "show current server" throw new TranslatableCommandException("command.playerLocationUnavailable", playerComponent); } else { teleporter.remoteTeleport(traveler, result.last_server, result.user.uuid()); } }) ); }
Example 14
Source File: ClassCommands.java From CardinalPGM with MIT License | 5 votes |
@Command(aliases = {"class", "cl"}, desc = "Allows you to change your class.") public static void classCommand(final CommandContext cmd, CommandSender sender) throws CommandException { if (!(sender instanceof Player)) { throw new CommandException(ChatConstant.ERROR_CONSOLE_NO_USE.getMessage(ChatUtil.getLocale(sender))); } if (GameHandler.getGameHandler().getMatch().getModules().getModule(ClassModule.class) == null) { throw new CommandException(ChatConstant.ERROR_CLASSES_DISABLED.getMessage(ChatUtil.getLocale(sender))); } if (cmd.argsLength() == 0) { if (ClassModule.getClassByPlayer((Player) sender) != null) { sender.sendMessage(ChatColor.GREEN + new LocalizedChatMessage(ChatConstant.GENERIC_CLASS_CURRENT).getMessage(ChatUtil.getLocale(sender)) + " " + ChatColor.GOLD + "" + ChatColor.UNDERLINE + ClassModule.getClassByPlayer((Player) sender).getName()); String classMessage = new LocalizedChatMessage(ChatConstant.GENERIC_CLASS_LIST).getMessage(((Player) sender).getLocale()); String newClassMessage = ""; for (int i = 0; i < classMessage.split("'").length; i++) { newClassMessage += (i == 1 ? ChatColor.GOLD : ChatColor.DARK_PURPLE) + (i > 0 ? "'" : "") + classMessage.split("'")[i]; } sender.sendMessage(newClassMessage); } } else { String input = cmd.getJoinedStrings(0); if (ClassModule.getClassByName(input) == null) { throw new CommandException(ChatConstant.ERROR_NO_CLASS.getMessage(ChatUtil.getLocale(sender))); } ClassModule.playerClass.put(((Player) sender).getUniqueId(), ClassModule.getClassByName(input)); ClassChangeEvent changeEvent = new ClassChangeEvent((Player) sender, ClassModule.getClassByName(input)); Bukkit.getServer().getPluginManager().callEvent(changeEvent); } }
Example 15
Source File: MapRatingsCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Command( aliases = { "rate", "ratemap" }, desc = "Rate the current map", usage = "[rating]", min = 0, max = 1 ) @CommandPermissions(MapRatingsMatchModule.RATE_PERM_NAME) public static void rate(CommandContext args, final CommandSender sender) throws CommandException { Integer score = null; if(args.argsLength() > 0) { score = args.getInteger(0); } final Player player = tc.oc.commons.bukkit.commands.CommandUtils.senderToPlayer(sender); final Match match = PGM.getMatchManager().getCurrentMatch(sender); if (match == null) { throw new CommandException(PGMTranslations.get().t("match.invalid", sender)); } final MapRatingsMatchModule mrmm = match.getMatchModule(MapRatingsMatchModule.class); if(mrmm == null) { throw new CommandException(PGMTranslations.get().t("command.ratingsDisabled", sender)); } if(score == null) { mrmm.showDialog(match.getPlayer(player)); } else if(!mrmm.isScoreValid(score)) { throw new CommandException(PGMTranslations.get().t("command.rate.invalidRating", sender, mrmm.getMinimumScore(), mrmm.getMaximumScore())); } else { final Integer finalScore = score; mrmm.loadPlayerRating(match.getPlayer(player), new Runnable() { @Override public void run() { mrmm.rate(match.getPlayer(player), finalScore); } }); } }
Example 16
Source File: CycleCommand.java From CardinalPGM with MIT License | 5 votes |
@Command(aliases = {"cycle"}, desc = "Cycles the world and loads a new world.", usage = "[time] [map]", flags = "fnm:") @CommandPermissions("cardinal.match.cycle") public static void cycle(final CommandContext cmd, CommandSender sender) throws CommandException { processCycle(cmd, sender); LoadedMap map = cmd.hasFlag('m') ? RepositoryManager.get().getMap(cmd.getFlagInteger('m')) : cmd.argsLength() > 1 ? getMap(sender, cmd.getJoinedStrings(1).replace(" -f", "").replace("-f ", "")) : GameHandler.getGameHandler().getCycle().getMap(); if (map == null) throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_MAP_MATCH).getMessage(ChatUtil.getLocale(sender))); else setCycleMap(map); GameHandler.getGameHandler().getMatch().getModules().getModule(CycleTimer.class).startCountdown(cmd.getInteger(0, Config.cycleDefault)); }
Example 17
Source File: AdminCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Command( aliases = {"end", "finish"}, desc = "Ends the current running match, optionally with a winner", usage = "[competitor]", min = 0, max = -1 ) @CommandPermissions("pgm.end") public void end(CommandContext args, CommandSender sender) throws CommandException { Match match = PGM.getMatchManager().getCurrentMatch(sender); Competitor winner = null; if(args.argsLength() > 0) { winner = CommandUtils.getCompetitor(args.getJoinedStrings(0), sender); } if(match.isFinished()) { throw new TranslatableCommandException("command.admin.start.matchFinished"); } else if(!match.canTransitionTo(MatchState.Finished)) { throw new TranslatableCommandException("command.admin.end.unknownError"); } if(winner != null) { match.needMatchModule(VictoryMatchModule.class).setImmediateWinner(winner); } match.end(); }
Example 18
Source File: NicknameCommands.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@Command(aliases = {"nick" }, usage = "list | show [player] | set <nickname> [player] | clear [player] | <nickname> [player]", desc = "Show, set, or clear a nickname for yourself or another player. " + "Changes will take effect the next time the player " + "connects to the server. The -i option makes the change " + "visible immediately.", flags = "i", min = 0, max = 3) @CommandPermissions(PERMISSION) public void nick(final CommandContext args, final CommandSender sender) throws CommandException { if(!config.enabled()) { throw new CommandException(Translations.get().t("command.nick.notEnabled", sender)); } final boolean immediate = args.hasFlag('i'); if(args.argsLength() == 0) { show(sender, null); } else { final String arg = args.getString(0); switch(arg) { case "list": list(sender); break; case "show": show(sender, args.getString(1, null)); break; case "set": if(args.argsLength() < 2) CommandUtils.notEnoughArguments(sender); set(sender, args.getString(1), args.getString(2, null), immediate); break; case "clear": set(sender, null, args.getString(1, null), immediate); break; default: set(sender, arg, args.getString(1, null), immediate); break; } } }
Example 19
Source File: SnapshotCommands.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Command( aliases = {"list"}, usage = "[num]", desc = "List snapshots", min = 0, max = 1 ) @CommandPermissions("worldedit.snapshots.list") public void list(Player player, LocalSession session, CommandContext args) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); if (config.snapshotRepo == null) { player.printError("Snapshot/backup restore is not configured."); return; } try { List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, player.getWorld().getName()); if (!snapshots.isEmpty()) { int num = args.argsLength() > 0 ? Math.min(40, Math.max(5, args.getInteger(0))) : 5; BBC.SNAPSHOT_LIST_HEADER.send(player, player.getWorld().getName()); for (byte i = 0; i < Math.min(num, snapshots.size()); i++) { player.print(BBC.getPrefix() + (i + 1) + ". " + snapshots.get(i).getName()); } BBC.SNAPSHOT_LIST_FOOTER.send(player); } else { player.printError("No snapshots are available. See console for details."); // Okay, let's toss some debugging information! File dir = config.snapshotRepo.getDirectory(); try { logger.info("WorldEdit found no snapshots: looked in: " + dir.getCanonicalPath()); } catch (IOException e) { logger.info("WorldEdit found no snapshots: looked in " + "(NON-RESOLVABLE PATH - does it exist?): " + dir.getPath()); } } } catch (MissingWorldException ex) { player.printError("No snapshots were found for this world."); } }
Example 20
Source File: CommandUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static Duration getDuration(CommandContext args, int index, Duration def) throws CommandException { return args.argsLength() > index ? getDuration(args.getString(index), null) : def; }