本文整理汇总了Java中com.sk89q.minecraft.util.commands.CommandContext.hasFlag方法的典型用法代码示例。如果您正苦于以下问题:Java CommandContext.hasFlag方法的具体用法?Java CommandContext.hasFlag怎么用?Java CommandContext.hasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sk89q.minecraft.util.commands.CommandContext
的用法示例。
在下文中一共展示了CommandContext.hasFlag方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restart
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"restart"},
desc = "Queues a server restart after a certain amount of time",
usage = "[seconds] - defaults to 30 seconds",
flags = "f",
min = 0,
max = 1
)
@CommandPermissions("server.restart")
public void restart(CommandContext args, CommandSender sender) throws CommandException {
// Countdown defers automatic restart, so don't allow excessively long times
Duration countdown = TimeUtils.min(
tc.oc.commons.bukkit.commands.CommandUtils.getDuration(args, 0, Duration.ofSeconds(30)),
Duration.ofMinutes(5)
);
final Match match = CommandUtils.getMatch(sender);
if(!match.canAbort() && !args.hasFlag('f')) {
throw new CommandException(PGMTranslations.get().t("command.admin.restart.matchRunning", sender));
}
restartListener.queueRestart(match, countdown, "/restart command");
}
示例2: beginVote
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"beginvote", "startvote"},
desc = "Begins a map selection vote.",
min = 0,
max = 0,
flags = "ct:"
)
@Console
@CommandPermissions("tourney.map.beginvote")
public void beginVote(CommandContext args, CommandSender sender) throws CommandException {
if (!tourney.getState().equals(TourneyState.ENABLED_WAITING_FOR_READY)) {
throw new CommandException("This match is not in a state that is eligible for map selection.");
} else if (voteContext.voteInProgress()) {
throw new CommandException("There is already a map selection vote in progress.");
} else if (!args.hasFlag('c')) {
throw new CommandException("Re-run command with -c to confirm. Map selection may not be ended pre-maturely.");
}
if (args.hasFlag('t')) {
MapClassification classification = classificationManager.classificationFromSearch(args.getFlag('t'));
if (classification == null) throw new CommandException("No classification matched query.");
voteContext.startVote(Collections.singleton(classification));
} else {
voteContext.startVote(classificationManager.getClassifications());
}
}
示例3: invalidate
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"invalidate", "nosave", "norecord"},
desc = "Indicates that the current match should not be saved to the database.",
min = 0,
max = 0,
flags = "c"
)
@Console
@CommandPermissions("tourney.invalidate")
public static void invalidate(final CommandContext args, final CommandSender sender) throws CommandException {
Tourney plugin = Tourney.get();
if (!Arrays.asList(TourneyState.ENABLED_RUNNING, TourneyState.ENABLED_FINISHED).contains(plugin.getState())) {
throw new CommandException("This match may not be invalidated at this time.");
}
if (plugin.isRecordQueued()) {
if (args.hasFlag('c')) {
plugin.setRecordQueued(false);
sender.sendMessage(ChatColor.YELLOW + "Match successfully invalidated.");
} else {
throw new CommandException("Match is eligible for invalidation. Re-run command with -c to confirm. Invalidation may not be reversed.");
}
} else {
throw new CommandException("This match is not queued to be recorded.");
}
}
示例4: queueRestart
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"gqueuerestart", "gqr"},
usage = "[-c]",
desc = "Shutdown the next time the server is inactive and empty",
flags = "c",
help = "The -c flag cancels a previously queued restart"
)
@CommandPermissions("bungeecord.command.restart")
public void queueRestart(final CommandContext args, final CommandSender sender) throws CommandException {
if(restartManager == null) {
throw new CommandException("Scheduled restarts are not enabled");
} else {
if(args.hasFlag('c')) {
sender.sendMessage(new TextComponent("Restart cancelled"));
restartManager.cancelRestart();
} else {
sender.sendMessage(new TextComponent("Restart queued"));
restartManager.requestRestart("/gqr command by " + sender.getName());
}
}
}
示例5: throwError
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = "throw",
desc = "Throw a test RuntimeException",
usage = "[message]",
flags = "tr",
min = 0,
max = 1
)
@CommandPermissions(Permissions.DEVELOPER)
public void throwError(CommandContext args, CommandSender sender) throws CommandException {
if(args.hasFlag('r')) {
Logger.getLogger("").severe("Test root logger error from " + sender.getName());
} else if(args.hasFlag('t')) {
scheduler.createTask(() -> {
throwError(args, sender, "task");
});
} else {
throwError(args, sender, "command");
}
}
示例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: 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);
}
示例8: ping
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"ping"},
desc = "Send a Ping message to the direct exchange, -r to wait for a reply",
usage = "<routing key> [-s | -f | -e]",
flags = "sfe",
min = 1,
max = 1
)
public void ping(CommandContext args, CommandSender sender) throws CommandException {
final String routingKey = args.getString(0);
final Audience audience = audiences.get(sender);
audience.sendMessage("ping " + routingKey);
final Ping.ReplyWith replyWith;
if(args.hasFlag('s')) {
replyWith = Ping.ReplyWith.success;
} else if(args.hasFlag('f')) {
replyWith = Ping.ReplyWith.failure;
} else if(args.hasFlag('e')) {
replyWith = Ping.ReplyWith.exception;
} else {
replyWith = null;
}
if(replyWith == null) {
exchange.publishAsync(new Ping(), routingKey);
} else {
final Transaction<Reply> transaction = transactions.request(new Ping(replyWith), routingKey);
syncExecutor.callback(
transaction,
CommandFutureCallback.onSuccess(sender, args, reply -> {
audience.sendMessage(reply.getClass().getSimpleName() + String.format(" (%.3fms)", transaction.elapsedTimeMillis()));
})
);
}
}
示例9: mapFeaturesCommand
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"mapfeatures", "mapf"},
desc = "Lists all map features by ID and type",
usage = "[-a(nonymous)] [-v(erbose)] [-l(ocations)] [-t type] [-i id]",
flags = "avlt:i:",
min = 0,
max = 0
)
@CommandPermissions(Permissions.MAPDEV)
public void mapFeaturesCommand(CommandContext args, CommandSender sender) throws CommandException {
final PGMMap map = tc.oc.pgm.commands.CommandUtils.getMatch(sender).getMap();
final boolean verbose = args.hasFlag('v');
final boolean locate = args.hasFlag('l');
final boolean anonymous = args.hasFlag('a');
final Optional<String> typeFilter = CommandUtils.flag(args, 't').map(String::toLowerCase);
final Optional<String> idFilter = CommandUtils.flag(args, 'i').map(String::toLowerCase);
Stream<? extends FeatureDefinition> features = map.getContext().features().all();
if(typeFilter.isPresent()) {
features = features.filter(f -> f.inspectType().toLowerCase().contains(typeFilter.get()));
}
if(idFilter.isPresent()) {
features = features.filter(f -> f instanceof FeatureProxy &&
((FeatureProxy) f).getId().toLowerCase().contains(idFilter.get()));
} else if(!anonymous) {
features = features.filter(f -> f instanceof FeatureProxy);
}
features.forEach(feature -> {
final Component c = new Component(feature.inspectType(), ChatColor.BLUE);
feature.inspectIdentity().ifPresent(id -> c.extra(" ").extra(new Component(id, ChatColor.YELLOW)));
if(locate) {
final Element element = map.getContext().features().definitionNode(feature);
if(element != null) {
c.extra(" ").extra(new Component(new Node(element).describeWithLocation(), ChatColor.DARK_AQUA));
}
}
sender.sendMessage(c);
if(verbose) {
feature.inspect(new MultiLineTextInspector(), Inspection.defaults())
.forEach(line -> sender.sendMessage(new Component(" " + BukkitUtils.escapeColors(line), ChatColor.GOLD)));
}
});
}
示例10: queueRestart
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
aliases = {"queuerestart", "qr"},
desc = "Restart the server at the next safe opportunity",
usage = "[-l/h (low/high priority)]",
min = 0,
max = 0,
flags = "lh"
)
@CommandPermissions("server.queuerestart")
@Console
public void queueRestart(CommandContext args, final CommandSender sender) throws CommandException {
final Audience audience = audiences.get(sender);
final int priority;
if(args.hasFlag('l')) {
priority = ServerDoc.Restart.Priority.LOW;
} else if(args.hasFlag('h')) {
if(!sender.hasPermission("server.queuerestart.high")) {
throw new CommandPermissionsException();
}
priority = ServerDoc.Restart.Priority.HIGH;
} else {
priority = ServerDoc.Restart.Priority.NORMAL;
}
if(restartManager.isRestartRequested(priority)) {
audience.sendMessage(new TranslatableComponent("command.admin.queueRestart.restartQueued"));
return;
}
syncExecutor.callback(
restartManager.requestRestart("/queuerestart command", priority),
CommandFutureCallback.onSuccess(sender, args, result -> {
if(restartManager.isRestartDeferred()) {
audience.sendMessage(new TranslatableComponent("command.admin.queueRestart.restartQueued"));
} else {
audience.sendMessage(new TranslatableComponent("command.admin.queueRestart.restartingNow"));
}
})
);
}
示例11: nick
import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@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;
}
}
}