Search in sources :

Example 1 with CommandException

use of net.warvale.core.exceptions.CommandException in project GameCore by Warvale.

the class StartCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) throws CommandException {
    if (!(sender instanceof Player)) {
        throw new CommandException("Only players can execute this command.");
    }
    Player player = (Player) sender;
    player.sendMessage(ChatColor.GRAY + "Starting the game automatically..");
    Game.start(null, null);
    return true;
}
Also used : Player(org.bukkit.entity.Player) CommandException(net.warvale.core.exceptions.CommandException)

Example 2 with CommandException

use of net.warvale.core.exceptions.CommandException in project GameCore by Warvale.

the class JoinCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        return false;
    }
    if (!(sender instanceof Player)) {
        throw new CommandException("Only players can execute this command.");
    }
    Player player = (Player) sender;
    String team = args[0];
    if (team.equalsIgnoreCase("blue")) {
        if (Main.getTeams().getBlueTeam().getEntries().contains(player.getName())) {
            throw new CommandException(ChatColor.GRAY + "You're already on the " + ChatColor.DARK_AQUA + "blue team");
        } else {
            // Join the team
            if (Main.getTeams().getRedTeam().getEntries().contains(player.getName())) {
                throw new CommandException(ChatColor.GRAY + "You may not change teams at this time.");
            }
            Main.getTeams().getBlueTeam().addEntry(player.getName());
            player.sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.DARK_AQUA + "blue");
            for (PotionEffect effect : player.getActivePotionEffects()) {
                player.removePotionEffect(effect.getType());
            }
            return true;
        }
    }
    if (team.equalsIgnoreCase("red")) {
        if (Main.getTeams().getRedTeam().getEntries().contains(player.getName())) {
            throw new CommandException(ChatColor.GRAY + "You're already on the " + ChatColor.RED + "red team");
        } else {
            // Join the team
            if (Main.getTeams().getBlueTeam().getEntries().contains(player.getName())) {
                throw new CommandException(ChatColor.GRAY + "You may not change teams at this time.");
            }
            Main.getTeams().getRedTeam().addEntry(player.getName());
            sender.sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.RED + "red");
            for (PotionEffect effect : player.getActivePotionEffects()) {
                player.removePotionEffect(effect.getType());
            }
            return true;
        }
    }
    if (team.equalsIgnoreCase("spectator")) {
        if (Main.getTeams().getSpectatorTeam().getEntries().contains(player.getName())) {
            throw new CommandException(ChatColor.GRAY + "You're already spectating!");
        } else {
            // Join the team
            if (!player.hasPermission("warvale.mod")) {
                throw new CommandException(ChatColor.GRAY + "You may not spectate at this time.");
            }
            return true;
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) CommandException(net.warvale.core.exceptions.CommandException)

Aggregations

CommandException (net.warvale.core.exceptions.CommandException)2 Player (org.bukkit.entity.Player)2 PotionEffect (org.bukkit.potion.PotionEffect)1