本文整理汇总了Java中com.sk89q.minecraft.util.commands.CommandContext.argsLength方法的典型用法代码示例。如果您正苦于以下问题:Java CommandContext.argsLength方法的具体用法?Java CommandContext.argsLength怎么用?Java CommandContext.argsLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sk89q.minecraft.util.commands.CommandContext
的用法示例。
在下文中一共展示了CommandContext.argsLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: max
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"max", "size"},
desc = "Change the maximum number of players allowed to participate in the match.",
min = 1,
max = 2
)
@CommandPermissions("pgm.team.size")
public static void max(CommandContext args, CommandSender sender) throws CommandException {
FreeForAllMatchModule ffa = CommandUtils.getMatchModule(FreeForAllMatchModule.class, sender);
if("default".equals(args.getString(0))) {
ffa.setMaxPlayers(null, null);
} else {
int maxPlayers = args.getInteger(0);
if(maxPlayers < 0) throw new CommandException("max-players cannot be less than 0");
int maxOverfill = args.argsLength() >= 2 ? args.getInteger(1) : maxPlayers;
if(maxOverfill < maxPlayers) throw new CommandException("max-overfill cannot be less than max-players");
if(maxPlayers < ffa.getMinPlayers()) throw new CommandException("max-players cannot be less than min-players");
ffa.setMaxPlayers(maxPlayers, maxOverfill);
}
sender.sendMessage(ChatColor.WHITE + "Maximum players is now " + ChatColor.AQUA + ffa.getMaxPlayers() +
ChatColor.WHITE + " and overfill is " + ChatColor.AQUA + ffa.getMaxOverfill());
}
示例2: stop
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@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");
}
}
}
示例3: force
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@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);
}
}
示例4: play
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = { "play", "replay" },
desc = "Play a game",
usage = "[game]",
min = 0,
max = -1
)
public List<String> play(final CommandContext args, final CommandSender sender) throws CommandException {
final String name = args.argsLength() > 0 ? args.getRemainingString(0) : "";
if(args.getSuggestionContext() != null) {
return StringUtils.complete(name, ticketBooth.allGames(sender).stream().map(Game::name));
}
ticketBooth.playGame(CommandUtils.senderToPlayer(sender), name);
return null;
}
示例5: session
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"session"},
desc = "Session status control",
usage = "[on|off|clear]",
max = 1
)
@CommandPermissions("bungeecord.command.session")
public void session(final CommandContext args, CommandSender sender) throws CommandException {
if (args.argsLength() == 1) {
String arg = args.getString(0);
SessionState newState = parseSessionStateCommand(arg);
if (newState == null) throw new CommandException("Unknown session state command: " + arg);
sender.sendMessage(new ComponentBuilder("Old Force Status: " + monitor.getForceState()).color(ChatColor.LIGHT_PURPLE).create());
monitor.setForceState(newState);
}
sender.sendMessage(new ComponentBuilder("Current Force Status: " + monitor.getForceState()).color(ChatColor.GOLD).create());
sender.sendMessage(new ComponentBuilder("Current Session Status: " + monitor.getDiscoveredState()).color(ChatColor.GOLD).create());
}
示例6: setnext
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"setnext", "sn"},
desc = "Sets the next map. Note that the rotation will go to this map then resume as normal.",
usage = "[map name]",
flags = "f",
min = 1,
max = -1
)
@CommandPermissions("pgm.next.set")
public List<String> setnext(CommandContext args, CommandSender sender) throws CommandException {
final String mapName = args.argsLength() > 0 ? args.getJoinedStrings(0) : "";
if(args.getSuggestionContext() != null) {
return CommandUtils.completeMapName(mapName);
}
MatchManager mm = PGM.getMatchManager();
boolean restartQueued = restartManager.isRestartRequested(ServerDoc.Restart.Priority.NORMAL);
if (restartQueued && !args.hasFlag('f')) {
throw new CommandException(PGMTranslations.get().t("command.admin.setNext.restartQueued", sender));
}
mm.setNextMap(CommandUtils.getMap(mapName, sender));
if (restartQueued) {
restartManager.cancelRestart();
sender.sendMessage(ChatColor.GREEN + PGMTranslations.get().t("command.admin.cancelRestart.restartUnqueued", sender));
}
sender.sendMessage(ChatColor.DARK_PURPLE + PGMTranslations.get().t("command.admin.set.success", sender, ChatColor.GOLD + mm.getNextMap().getInfo().name + ChatColor.DARK_PURPLE));
return null;
}
示例7: rate
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@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);
}
});
}
}
示例8: max
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"max", "size"},
desc = "Change the maximum size of a team. If max-overfill is not specified, it will be the same as max-players.",
usage = "<team> (default | <max-players> [max-overfill])",
min = 2,
max = 3
)
@CommandPermissions("pgm.team.size")
public void max(CommandContext args, CommandSender sender) throws CommandException, SuggestException {
Team team = utils.teamArgument(args, 0);
if("default".equals(args.getString(1))) {
team.resetMaxSize();
} else {
int maxPlayers = args.getInteger(1);
if(maxPlayers < 0) throw new CommandException("max-players cannot be less than 0");
Integer maxOverfill = null;
if(args.argsLength() == 3) {
maxOverfill = args.getInteger(2);
if(maxOverfill < maxPlayers) throw new CommandException("max-overfill cannot be less than max-players");
}
team.setMaxSize(maxPlayers, maxOverfill != null ? maxOverfill : maxPlayers);
}
sender.sendMessage(team.getColoredName() +
ChatColor.WHITE + " now has max size " + ChatColor.AQUA + team.getMaxPlayers() +
ChatColor.WHITE + " and max overfill " + ChatColor.AQUA + team.getMaxOverfill());
}
示例9: join
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = { "join" },
desc = "Joins the current match",
usage = "[team] - defaults to random",
flags = "f",
min = 0,
max = -1
)
@CommandPermissions(JoinMatchModule.JOIN_PERMISSION)
public void join(CommandContext args, CommandSender sender) throws CommandException {
MatchPlayer player = CommandUtils.senderToMatchPlayer(sender);
Match match = player.getMatch();
JoinMatchModule jmm = match.needMatchModule(JoinMatchModule.class);
TeamMatchModule tmm = match.getMatchModule(TeamMatchModule.class);
boolean force = sender.hasPermission("pgm.join.force") && args.hasFlag('f');
Competitor chosenParty = null;
if(args.argsLength() > 0) {
if(args.getJoinedStrings(0).trim().toLowerCase().startsWith("obs")) {
observe(args, sender);
return;
} else if(tmm != null) {
// player wants to join a specific team
chosenParty = tmm.bestFuzzyMatch(args.getJoinedStrings(0));
if(chosenParty == null) throw new CommandException(PGMTranslations.get().t("command.teamNotFound", sender));
}
}
jmm.requestJoin(player, force ? JoinMethod.FORCE : JoinMethod.USER, chosenParty);
}
示例10: errorsCommand
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"errors", "xmlerrors"},
usage = "[-p page] [map name]",
desc = "Reads back XML errors",
min = 0,
max = -1,
flags = "p:"
)
@CommandPermissions(Permissions.MAPERRORS)
public List<String> errorsCommand(CommandContext args, final CommandSender sender) throws CommandException {
final String mapName = args.argsLength() > 0 ? args.getJoinedStrings(0) : "";
if(args.getSuggestionContext() != null) {
return tc.oc.pgm.commands.CommandUtils.completeMapName(mapName);
}
Multimap<MapDefinition, MapLogRecord> errors = mapErrorTracker.getErrors();
PGMMap filterMap = null;
if(!mapName.isEmpty()) {
filterMap = tc.oc.pgm.commands.CommandUtils.getMap(mapName, sender);
Multimap<MapDefinition, MapLogRecord> filtered = ArrayListMultimap.create();
filtered.putAll(filterMap, errors.get(filterMap));
errors = filtered;
}
new PrettyPaginatedResult<Map.Entry<MapDefinition, MapLogRecord>>(filterMap == null ? "Map Errors (" + errors.keySet().size() + " maps)"
: filterMap.getName() + " Errors") {
@Override
public String format(Map.Entry<MapDefinition, MapLogRecord> entry, int index) {
return entry.getValue().getLegacyFormattedMessage();
}
@Override
public String formatEmpty() {
return ChatColor.GREEN + PGMTranslations.get().t("command.development.listErrors.noErrors", sender);
}
}.display(new BukkitWrappedCommandSender(sender), errors.entries(), args.getFlagInteger('p', 1));
return null;
}
示例11: environment
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"environment", "env"},
desc = "Get/set map environment variables"
)
@CommandPermissions(Permissions.MAPDEV)
public void environment(CommandContext args, final CommandSender sender) throws CommandException {
final Audience audience = audiences.get(sender);
boolean reset = false;
Map<String, Boolean> vars = new HashMap<>();
Pattern pattern = Pattern.compile("([A-Za-z0-9_]+)=(true|false)");
for(int i = 0; i < args.argsLength(); i++) {
String arg = args.getString(i);
if("reset".equals(arg)) {
reset = true;
} else {
Matcher matcher = pattern.matcher(arg);
if(!matcher.matches()) {
throw new CommandException("Can't understand variable assignment '" + arg + "'");
}
vars.put(matcher.group(1).toLowerCase(), "true".equals(matcher.group(2)));
}
}
if(reset) mapEnvironment.clear();
mapEnvironment.putAll(vars);
for(Map.Entry<String, Boolean> entry : mapEnvironment.entrySet()) {
audience.sendMessage(
new Component(ChatColor.GRAY)
.extra(new Component(entry.getKey(), ChatColor.WHITE))
.extra("=")
.extra(new Component(String.valueOf(entry.getValue()), ChatColor.BLUE))
);
}
}
示例12: cycle
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"cycle"},
desc = "Queues a cycle to the next map in a certain amount of seconds",
usage = "[seconds] [mapname]",
flags = "f"
)
@CommandPermissions(PERMISSION)
public List<String> cycle(CommandContext args, CommandSender sender) throws CommandException {
if(args.getSuggestionContext() != null) {
if(args.getSuggestionContext().getIndex() >= 1) {
return CommandUtils.completeMapName(args.getJoinedStrings(1));
}
return null;
}
// Try to parse "<seconds> [mapname]", fall back to "<mapname>"
// So the map can be given without the time
Duration countdown;
try {
countdown = tc.oc.commons.bukkit.commands.CommandUtils.getDuration(args, 0);
} catch(CommandException e) {
countdown = null;
}
int index = countdown == null ? 0 : 1;
String mapName = index < args.argsLength() ? args.getJoinedStrings(index) : null;
cycle(sender, countdown, mapName == null ? null : CommandUtils.getMap(mapName, sender), args.hasFlag('f'));
return null;
}
示例13: channel
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = "t",
desc = "Sends a message to the team channel (or sets the team channel to your default channel).",
usage = "[message...]",
min = 0,
max = -1,
anyFlags = true
)
public static void teamChat(CommandContext args, CommandSender sender) throws CommandException {
MatchPlayer player = CommandUtils.senderToMatchPlayer(sender);
if (player.getBukkit().hasPermission(ChannelMatchModule.TEAM_SEND_PERMISSION)) {
ChannelMatchModule cmm = player.getMatch().needMatchModule(ChannelMatchModule.class);
if (args.argsLength() == 0) {
cmm.setTeamChat(player, true);
player.sendMessage(new TranslatableComponent("command.chat.team.switchSuccess"));
} else {
Channel channel = cmm.getChannel(player.getParty());
channel.sendMessage(args.getJoinedStrings(0), player.getBukkit());
if (!player.getBukkit().hasPermission(channel.getListeningPermission())) {
sender.sendMessage(ChatColor.YELLOW + PGMTranslations.t("command.chat.team.success", player));
}
}
} else {
throw new CommandPermissionsException();
}
}
示例14: roster
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@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"));
})
);
}
示例15: getPlayer
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
/**
* 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));
}
}