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

The following examples show how to use com.sk89q.minecraft.util.commands.CommandContext#getInteger() . 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: FreeForAllCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"min"},
    desc = "Change the minimum number of players required to start the match.",
    min = 1,
    max = 1
)
@CommandPermissions("pgm.team.size")
public static void min(CommandContext args, CommandSender sender) throws CommandException {
    FreeForAllMatchModule ffa = CommandUtils.getMatchModule(FreeForAllMatchModule.class, sender);
    if("default".equals(args.getString(0))) {
        ffa.setMinPlayers(null);
    } else {
        int minPlayers = args.getInteger(0);
        if(minPlayers < 0) throw new CommandException("min-players cannot be less than 0");
        if(minPlayers > ffa.getMaxPlayers()) throw new CommandException("min-players cannot be greater than max-players");
        ffa.setMinPlayers(minPlayers);
    }

    sender.sendMessage(ChatColor.WHITE + "Minimum players is now " + ChatColor.AQUA + ffa.getMinPlayers());
}
 
Example 2
Source File: FreeForAllCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: AdminCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"skipto"},
    desc = "Skip to a certain point in the rotation",
    usage = "[n]",
    min = 1,
    max = 1
)
@CommandPermissions("pgm.skip")
public void skipto(CommandContext args, CommandSender sender) throws CommandException {
    RotationManager manager = PGM.getMatchManager().getRotationManager();
    RotationState rotation = manager.getRotation();

    int newNextId = args.getInteger(0) - 1;
    if(RotationState.isNextIdValid(rotation.getMaps(), newNextId)) {
        rotation = rotation.skipTo(newNextId);
        manager.setRotation(rotation);
        sender.sendMessage(ChatColor.GREEN + PGMTranslations.get().t("command.admin.skipto.success", sender, rotation.getNext().getInfo().getShortDescription(sender) + ChatColor.GREEN));
    } else {
        throw new CommandException(PGMTranslations.get().t("command.admin.skipto.invalidPoint", sender));
    }
}
 
Example 4
Source File: TeamCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"min"},
    desc = "Change the minimum size of a team.",
    usage = "<team> (default | <min-players>)",
    min = 2,
    max = 2
)
@CommandPermissions("pgm.team.size")
public void min(CommandContext args, CommandSender sender) throws CommandException, SuggestException {
    Team team = utils.teamArgument(args, 0);

    if("default".equals(args.getString(1))) {
        team.resetMinSize();
    } else {
        int minPlayers = args.getInteger(1);
        if(minPlayers < 0) throw new CommandException("min-players cannot be less than 0");
        team.setMinSize(minPlayers);
    }

    sender.sendMessage(team.getColoredName() +
                       ChatColor.WHITE + " now has min size " + ChatColor.AQUA + team.getMinPlayers());
}
 
Example 5
Source File: SelectionCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
private Vector[] getChangesForEachDir(CommandContext args) {
    List<Vector> changes = new ArrayList<Vector>(6);
    int change = args.getInteger(0);

    if (!args.hasFlag('h')) {
        changes.add((new Vector(0, 1, 0)).multiply(change));
        changes.add((new Vector(0, -1, 0)).multiply(change));
    }

    if (!args.hasFlag('v')) {
        changes.add((new Vector(1, 0, 0)).multiply(change));
        changes.add((new Vector(-1, 0, 0)).multiply(change));
        changes.add((new Vector(0, 0, 1)).multiply(change));
        changes.add((new Vector(0, 0, -1)).multiply(change));
    }

    return changes.toArray(new Vector[0]);
}
 
Example 6
Source File: NavigationCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"up"},
        usage = "<number>",
        desc = "Go upwards some distance",
        flags = "fg",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.navigation.up")
@Logging(POSITION)
public void up(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    final int distance = args.getInteger(0);

    final boolean alwaysGlass = getAlwaysGlass(args);
    if (player.ascendUpwards(distance, alwaysGlass)) {
        BBC.WHOOSH.send(player);
    } else {
        BBC.UP_FAIL.send(player);
    }
}
 
Example 7
Source File: SuperPickaxeCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"area"},
        usage = "<radius>",
        desc = "Enable the area super pickaxe pickaxe mode",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.superpickaxe.area")
public void area(Player player, LocalSession session, CommandContext args) throws WorldEditException {

    LocalConfiguration config = we.getConfiguration();
    int range = args.getInteger(0);

    if (range > config.maxSuperPickaxeSize) {
        BBC.TOOL_RANGE_ERROR.send(player, config.maxSuperPickaxeSize);
        return;
    }

    session.setSuperPickaxe(new AreaPickaxe(range));
    session.enableSuperPickAxe();
    BBC.SUPERPICKAXE_AREA_ENABLED.send(player);
}
 
Example 8
Source File: SettingCommands.java    From CardinalPGM with MIT License 6 votes vote down vote up
@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 9
Source File: AdminCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Command(
    aliases = {"skip"},
    desc = "Skip maps in the rotation",
    usage = "[n] - defaults to 1",
    min = 0,
    max = 1
)
@CommandPermissions("pgm.skip")
public void skip(CommandContext args, CommandSender sender) throws CommandException {
    RotationManager manager = PGM.getMatchManager().getRotationManager();
    RotationState rotation = manager.getRotation();

    if(args.argsLength() > 0) {
        int n = args.getInteger(0, 1);
        rotation = rotation.skip(n);
        sender.sendMessage(
                ChatColor.GREEN +
                PGMTranslations.get().t("command.admin.skip.successMultiple", sender,
                        PGMTranslations.get().t(n == 1 ? "maps.singularCompound" : "maps.pluralCompound", sender, n),
                        rotation.getNext().getInfo().getShortDescription(sender) + ChatColor.GREEN
                )
        );
    } else {
        PGMMap skippedMap = rotation.getNext();
        rotation = rotation.skip(1);
        sender.sendMessage(ChatColor.GREEN + PGMTranslations.get().t("command.admin.skip.success", sender, skippedMap.getInfo().getShortDescription(sender) + ChatColor.GREEN));
    }

    manager.setRotation(rotation);
}
 
Example 10
Source File: MapRatingsCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 11
Source File: TeamCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example 12
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static int getInteger(CommandContext args, CommandSender sender, int index, int def) throws CommandException {
    try {
        return args.getInteger(index, def);
    }
    catch(NumberFormatException e) {
        throw new CommandException(ComponentRenderers.toLegacyText(new TranslatableComponent("command.error.invalidNumber", args.getString(index)), sender));
    }
}
 
Example 13
Source File: UserCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Command(
    aliases = { "friends", "fr", "fs" },
    usage = "[page #]",
    desc = "Shows what servers your friends are on",
    min = 0,
    max = 1
)
@CommandPermissions("projectares.friends.view")
public void friends(final CommandContext args, final CommandSender sender) throws CommandException {
    final PlayerId playerId = Users.playerId(CommandUtils.senderToPlayer(sender));
    final int page = args.getInteger(0, 1);

    syncExecutor.callback(
        sessionService.friends(playerId),
        CommandFutureCallback.onSuccess(sender, args, result -> {
            if(result.documents().isEmpty()) {
                throw new TranslatableCommandException("command.friends.none");
            }

            new ComponentPaginator() {
                @Override protected BaseComponent title() {
                    return new TranslatableComponent("command.friends.title");
                }
            }.display(sender, userFormatter.formatSessions(result.documents()), page);
        })
    );
}
 
Example 14
Source File: SelectionCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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 15
Source File: BiomeCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(
        aliases = {"biomelist", "biomels"},
        usage = "[page]",
        desc = "Gets all biomes available.",
        max = 1
)
@CommandPermissions("worldedit.biome.list")
public void biomeList(Player player, CommandContext args) throws WorldEditException {
    int page;
    int offset;
    int count = 0;

    if (args.argsLength() == 0 || (page = args.getInteger(0)) < 2) {
        page = 1;
        offset = 0;
    } else {
        offset = (page - 1) * 18;
    }

    BiomeRegistry biomeRegistry = player.getWorld().getWorldData().getBiomeRegistry();
    List<BaseBiome> biomes = biomeRegistry.getBiomes();
    int totalPages = biomes.size() / 19 + 1;
    Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages);
    String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome");
    for (BaseBiome biome : biomes) {
        if (offset > 0) {
            offset--;
        } else {
            BiomeData data = biomeRegistry.getData(biome);
            if (data != null) {
                msg.newline().text(data.getName()).cmdTip(setBiome + " " + data.getName());
            } else {
                msg.newline().text("<? #" + biome.getId() + ">").cmdTip(setBiome + " " + biome.getId());
            }
            if (++count == 18) {
                break;
            }
        }
    }
    msg.newline().paginate(getCommand().aliases()[0], page, totalPages);
    msg.send(player);
}