Search in sources :

Example 1 with Flag

use of me.botsko.prism.api.commands.Flag in project Prism-Bukkit by prism.

the class FlagsCommand method help.

/**
 * Display param help.
 *
 * @param s CommandSender
 */
private void help(CommandSender s) {
    Prism.messenger.sendMessage(s, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("flag-help-header").color(NamedTextColor.GOLD)));
    Prism.messenger.sendMessage(s, Prism.messenger.playerMsg(Il8nHelper.getMessage("flag-help-1").color(NamedTextColor.GRAY)));
    Prism.messenger.sendMessage(s, Prism.messenger.playerMsg(Il8nHelper.getMessage("flag-help-2")));
    for (final Flag flag : Flag.values()) {
        Prism.messenger.sendMessage(s, Prism.messenger.playerMsg(Component.text(flag.getUsage().replace("_", "-")).color(NamedTextColor.LIGHT_PURPLE).append(Component.text(" " + Il8nHelper.getRawMessage(flag.getDescription())).color(NamedTextColor.GRAY))));
    }
}
Also used : Flag(me.botsko.prism.api.commands.Flag)

Example 2 with Flag

use of me.botsko.prism.api.commands.Flag in project Prism-Bukkit by prism.

the class FlagParameter method hasPermission.

@Override
public boolean hasPermission(String parameter, Permissible permissible) {
    final String[] flagComponents = parameter.substring(1).split("=");
    Flag flag;
    try {
        flag = Flag.valueOf(flagComponents[0].replace("-", "_").toUpperCase());
    } catch (final IllegalArgumentException ex) {
        return false;
    }
    return flag.hasPermission(permissible);
}
Also used : Flag(me.botsko.prism.api.commands.Flag)

Example 3 with Flag

use of me.botsko.prism.api.commands.Flag in project Prism-Bukkit by prism.

the class FlagParameter method process.

@Override
public void process(QueryParameters query, String parameter, CommandSender sender) {
    final String[] flagComponents = parameter.substring(1).split("=");
    Flag flag;
    try {
        flag = Flag.valueOf(flagComponents[0].replace("-", "_").toUpperCase());
    } catch (final IllegalArgumentException ex) {
        throw new IllegalArgumentException("Flag -" + flagComponents[0] + " not found", ex);
    }
    if (!(query.hasFlag(flag))) {
        query.addFlag(flag);
        // Flag has a value
        if (flagComponents.length > 1) {
            if (flag.equals(Flag.PER_PAGE)) {
                if (TypeUtils.isNumeric(flagComponents[1])) {
                    query.setPerPage(Integer.parseInt(flagComponents[1]));
                } else {
                    throw new IllegalArgumentException("Per-page flag value must be a number. Use /prism ? for help.");
                }
            } else if (flag.equals(Flag.SHARE)) {
                for (final String sharePlayer : flagComponents[1].split(",")) {
                    if (sharePlayer.equals(sender.getName())) {
                        throw new IllegalArgumentException("You can't share lookup results with yourself!");
                    }
                    final Player shareWith = Bukkit.getServer().getPlayer(sharePlayer);
                    if (shareWith != null) {
                        query.addSharedPlayer(shareWith);
                    } else {
                        throw new IllegalArgumentException("Can't share with " + sharePlayer + ". Are they online?");
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Flag(me.botsko.prism.api.commands.Flag)

Example 4 with Flag

use of me.botsko.prism.api.commands.Flag in project Prism-Bukkit by prism.

the class FlagParameter method tabComplete.

@Override
public List<String> tabComplete(String partialParameter, CommandSender sender) {
    final String[] flagComponents = partialParameter.substring(1).split("=", 2);
    Flag flag;
    final String name = flagComponents[0].replace("-", "_").toUpperCase();
    try {
        flag = Flag.valueOf(name);
    } catch (final IllegalArgumentException ex) {
        final List<String> completions = new ArrayList<>();
        for (final Flag possibleFlag : Flag.values()) {
            final String flagName = possibleFlag.toString();
            if (flagName.startsWith(name)) {
                completions.add("-" + flagName.replace('_', '-').toLowerCase());
            }
        }
        return completions;
    }
    // Flag has a value
    if (flagComponents.length <= 1) {
        return null;
    }
    String prefix = "-" + flag.toString().replace('_', '-').toLowerCase() + "=";
    if (flag.equals(Flag.SHARE)) {
        final String value = flagComponents[1];
        final int end = value.lastIndexOf(',');
        String partialName = value;
        if (end != -1) {
            partialName = value.substring(end + 1);
            prefix = prefix + value.substring(0, end) + ",";
        }
        partialName = partialName.toLowerCase();
        final List<String> completions = new ArrayList<>();
        for (final Player player : Bukkit.getOnlinePlayers()) {
            if (player.getName().toLowerCase().startsWith(partialName)) {
                completions.add(prefix + player.getName());
            }
        }
        return completions;
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Flag(me.botsko.prism.api.commands.Flag)

Aggregations

Flag (me.botsko.prism.api.commands.Flag)4 Player (org.bukkit.entity.Player)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1