Java Code Examples for com.sk89q.minecraft.util.commands.CommandContext#getSuggestionContext()

The following examples show how to use com.sk89q.minecraft.util.commands.CommandContext#getSuggestionContext() . 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: ModelCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = "all",
    usage = "<model>",
    desc = "List all stored instances of a model",
    min = 1,
    max = 1
)
public List<String> all(CommandContext args, CommandSender sender) throws CommandException {
    final String modelName = args.getString(0, "");

    if(args.getSuggestionContext() != null) {
        return completeModel(modelName);
    }
    for(Model doc : parseModel(modelName).store().get().set()) {
        sender.sendMessage(new Component(doc._id() + " " + doc.toShortString()));
    }
    return null;
}
 
Example 2
Source File: ModelCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = "refresh",
    usage = "<model>",
    desc = "Refresh a model store from the API",
    min = 1,
    max = 1
)
public List<String> refresh(CommandContext args, CommandSender sender) throws CommandException {
    final String modelName = args.getString(0, "");

    if(args.getSuggestionContext() != null) {
        return completeModel(modelName);
    }

    final ModelMeta<?, ?> model = parseModel(modelName);
    sender.sendMessage("Refreshing model " + model.name() + "...");
    syncExecutor.callback(
        model.store().get().refreshAll(),
        response -> sender.sendMessage("Refreshed " + response.documents().size() + " " + model.name() + " document(s)")
    );
    return null;
}
 
Example 3
Source File: TicketCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: TicketCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = { "watch" },
    desc = "Spectate a game",
    usage = "[game]",
    min = 0,
    max = -1
)
public List<String> watch(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.watchGame(CommandUtils.senderToPlayer(sender), name);
    return null;
}
 
Example 5
Source File: AdminCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: MapDevelopmentCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: CycleCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}