Search in sources :

Example 1 with ArenaPlayer

use of com.elmakers.mine.bukkit.arena.ArenaPlayer in project MagicPlugin by elBukkit.

the class ArenaListener method onPlayerQuit.

@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
    Player player = e.getPlayer();
    ArenaPlayer leftPlayer = controller.leave(player);
    if (leftPlayer != null) {
        leftPlayer.quit();
        Arena arena = leftPlayer.getArena();
        arena.announce(arena.getAnnouncePlayerMessage("quit", leftPlayer));
    }
}
Also used : Player(org.bukkit.entity.Player) ArenaPlayer(com.elmakers.mine.bukkit.arena.ArenaPlayer) ArenaPlayer(com.elmakers.mine.bukkit.arena.ArenaPlayer) Arena(com.elmakers.mine.bukkit.arena.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ArenaPlayer

use of com.elmakers.mine.bukkit.arena.ArenaPlayer in project MagicPlugin by elBukkit.

the class ArenaListener method onSpellPreCast.

@EventHandler
public void onSpellPreCast(PreCastEvent event) {
    Mage mage = event.getMage();
    Player player = mage.getPlayer();
    if (player == null) {
        return;
    }
    ArenaPlayer arenaPlayer = controller.getArenaPlayer(player);
    if (arenaPlayer == null || !arenaPlayer.isBattling()) {
        return;
    }
    Arena arena = arenaPlayer.getArena();
    if (arena != null && arena.hasOpCheck()) {
        Wand wand = arenaPlayer.getMage().getActiveWand();
        boolean op = wand != null && (wand.isSuperPowered() || wand.isSuperProtected() || wand.getPower() > 1 || wand.getHealthRegeneration() > 0 || wand.getCooldownReduction() > 1);
        if (op) {
            event.setCancelled(true);
            mage.sendMessage("You're too OP!!");
            controller.leave(player);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ArenaPlayer(com.elmakers.mine.bukkit.arena.ArenaPlayer) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ArenaPlayer(com.elmakers.mine.bukkit.arena.ArenaPlayer) Arena(com.elmakers.mine.bukkit.arena.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ArenaPlayer

use of com.elmakers.mine.bukkit.arena.ArenaPlayer in project MagicPlugin by elBukkit.

the class ArenaCommandExecutor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!command.getName().equalsIgnoreCase("marena")) {
        return false;
    }
    if (!sender.hasPermission("magic.commands.marena")) {
        sendNoPermission(sender);
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(ChatColor.YELLOW + "---------" + ChatColor.WHITE + "Help: MagicArenas " + ChatColor.YELLOW + "--------");
        sender.sendMessage("/marena add [name] <type> : Add a new arena");
        sender.sendMessage("/marena remove [name] : Remove an existing arena");
        sender.sendMessage("/marena start [name] : Manually start an arena");
        sender.sendMessage("/marena stop [name] : Manually stop an arena");
        sender.sendMessage("/marena describe [name] : List properties of an arena");
        sender.sendMessage("/marena join [name] <player> : Force a player to join an arena");
        sender.sendMessage("/marena leave [name] <player> : Force a player to leave an arena");
        sender.sendMessage("/marena configure [name] [property] <value> : Reconfigure an arena");
        sender.sendMessage("/marena stage [name] [command] <value> : Display or configure mob arena stages");
        sender.sendMessage("/marena import : Import arenas from MagicArenas");
        sender.sendMessage(ChatColor.YELLOW + "-----------------------------------------------");
        return true;
    }
    String subCommand = args[0];
    if (!sender.hasPermission("magic.commands.marena." + subCommand)) {
        sendNoPermission(sender);
        return true;
    }
    if (subCommand.equalsIgnoreCase("import")) {
        arenaController.importArenas(sender);
        return true;
    }
    if (subCommand.equalsIgnoreCase("describe") && args.length < 2) {
        Collection<Arena> arenas = arenaController.getArenas();
        sender.sendMessage(ChatColor.BLUE + "Arenas: " + ChatColor.DARK_AQUA + arenas.size());
        for (Arena arena : arenas) {
            String arenaMessage = ChatColor.AQUA + arena.getName() + ChatColor.GRAY + " (" + arena.getKey() + ")";
            if (arena.isStarted()) {
                arenaMessage = arenaMessage + ChatColor.GREEN + " ACTIVE";
            }
            int minPlayers = arena.getMinPlayers();
            int maxPlayers = arena.getMaxPlayers();
            int queuedPlayers = arena.getQueuedPlayers();
            int inGamePlayers = arena.getInGamePlayers();
            arenaMessage = arenaMessage + ChatColor.WHITE + " (" + ChatColor.GREEN + inGamePlayers + ChatColor.WHITE + ", " + ChatColor.YELLOW + queuedPlayers + ChatColor.WHITE + " / " + ChatColor.GRAY + minPlayers + "-" + maxPlayers + ChatColor.WHITE + ")";
            sender.sendMessage(arenaMessage);
        }
        return true;
    }
    if (subCommand.equalsIgnoreCase("leave")) {
        Player player = null;
        String playerName = null;
        if (args.length > 1) {
            playerName = args[1];
            player = Bukkit.getPlayer(playerName);
        } else if (sender instanceof Player) {
            player = (Player) sender;
            playerName = player.getName();
        }
        if (player == null) {
            if (playerName != null) {
                sender.sendMessage(ChatColor.RED + "Unknown player: " + playerName);
            } else {
                sender.sendMessage(ChatColor.RED + "You must specify a player name");
            }
            return true;
        }
        ArenaPlayer leftPlayer = arenaController.leave(player);
        if (leftPlayer != null) {
            sender.sendMessage(ChatColor.AQUA + leftPlayer.getDisplayName() + " has left " + leftPlayer.getArena().getName());
        } else {
            sender.sendMessage(ChatColor.AQUA + playerName + ChatColor.RED + " is not in an arena");
        }
        return true;
    }
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "You must provide an arena name");
        return true;
    }
    String arenaName = args[1];
    boolean isAllArenas = arenaName.equalsIgnoreCase("ALL");
    Arena arena = isAllArenas ? null : arenaController.getArena(arenaName);
    if (subCommand.equalsIgnoreCase("add")) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "Must be used in-game");
            return true;
        }
        Player player = (Player) sender;
        Location location = player.getLocation();
        ArenaTemplate template = null;
        if (args.length > 2) {
            template = arenaController.getTemplate(args[2]);
            if (template == null) {
                sender.sendMessage(ChatColor.RED + "Unknown arena template: " + ChatColor.WHITE + args[2]);
                return true;
            }
        } else {
            template = arenaController.getTemplate(arenaName);
        }
        if (arena == null) {
            arena = arenaController.addArena(arenaName, template, location);
            player.sendMessage(ChatColor.AQUA + "Arena Created: " + arena.getName());
        } else {
            sender.sendMessage(ChatColor.AQUA + "Arena already exists!");
        }
        return true;
    }
    if (arena == null && !isAllArenas) {
        sender.sendMessage(ChatColor.RED + "Unknown arena: " + arenaName);
        return true;
    }
    if (subCommand.equalsIgnoreCase("reset")) {
        Player player = null;
        String playerName = null;
        if (args.length > 2) {
            playerName = args[2];
            player = Bukkit.getPlayer(playerName);
        } else {
            if (isAllArenas) {
                arenaController.reset();
                sender.sendMessage(ChatColor.AQUA + "All arenas" + ChatColor.GRAY + " have been " + ChatColor.RED + " reset");
            } else {
                arena.reset();
                sender.sendMessage(ChatColor.AQUA + arena.getName() + ChatColor.GRAY + " has been " + ChatColor.RED + " reset");
            }
        }
        if (player == null) {
            if (playerName != null) {
                sender.sendMessage(ChatColor.RED + "Unknown player: " + playerName);
            } else {
                sender.sendMessage(ChatColor.RED + "You must specify a player name");
            }
            return true;
        }
        if (isAllArenas) {
            arenaController.reset(player);
            sender.sendMessage(ChatColor.AQUA + playerName + ChatColor.GRAY + " has been " + ChatColor.RED + " reset from ALL arenas");
        } else {
            arena.reset(player);
            sender.sendMessage(ChatColor.AQUA + playerName + ChatColor.GRAY + " has been " + ChatColor.RED + " reset from " + ChatColor.GOLD + arena.getName());
        }
        return true;
    }
    if (isAllArenas) {
        sender.sendMessage(ChatColor.RED + "ALL not applicable here.");
        return true;
    }
    if (subCommand.equalsIgnoreCase("remove")) {
        arenaController.remove(arenaName);
        sender.sendMessage(ChatColor.RED + "Arena Removed: " + ChatColor.DARK_RED + arena.getName());
        return true;
    }
    if (subCommand.equalsIgnoreCase("start")) {
        arena.startCountdown();
        return true;
    }
    if (subCommand.equalsIgnoreCase("describe")) {
        arena.describe(sender);
        return true;
    }
    if (subCommand.equalsIgnoreCase("stop")) {
        if (arena.stop()) {
            sender.sendMessage(ChatColor.AQUA + "Match stopped!");
        } else {
            sender.sendMessage(ChatColor.AQUA + "Arena not active");
        }
        return true;
    }
    if (subCommand.equalsIgnoreCase("stats")) {
        if (args.length > 2) {
            String playerName = args[2];
            Player player = Bukkit.getPlayer(playerName);
            if (player == null) {
                sender.sendMessage(ChatColor.RED + "Unknown player: " + playerName);
                return true;
            }
            arena.describeStats(sender, player);
        } else {
            arena.describeLeaderboard(sender);
        }
        return true;
    }
    if (subCommand.equalsIgnoreCase("join")) {
        Player player = null;
        String playerName = null;
        if (args.length > 2) {
            playerName = args[2];
            player = Bukkit.getPlayer(playerName);
        } else if (sender instanceof Player) {
            player = (Player) sender;
        }
        if (player == null) {
            if (playerName != null) {
                sender.sendMessage(ChatColor.RED + "Unknown player: " + playerName);
            } else {
                sender.sendMessage(ChatColor.RED + "You must specify a player name");
            }
            return true;
        }
        arena.join(player);
        return true;
    }
    if (subCommand.equalsIgnoreCase("configure")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Must specify a property name: ");
            sender.sendMessage(ChatColor.YELLOW + StringUtils.join(ARENA_PROPERTIES, ','));
            return true;
        }
        String propertyName = args[2];
        String[] configureArgs;
        if (args.length > 3) {
            configureArgs = new String[args.length - 3];
            System.arraycopy(args, 3, configureArgs, 0, args.length - 3);
        } else {
            configureArgs = new String[0];
        }
        onConfigureArena(sender, arena, propertyName, configureArgs);
        return true;
    }
    if (subCommand.equalsIgnoreCase("stage")) {
        if (args.length < 3) {
            sender.sendMessage("TODO: Stage overview for arena");
            return true;
        }
        String stageCommand = args[2];
        args = Arrays.copyOfRange(args, 3, args.length);
        onArenaStage(sender, arena, stageCommand, args);
        return true;
    }
    sender.sendMessage(ChatColor.RED + "Not a valid option: " + subCommand);
    sender.sendMessage(ChatColor.AQUA + "Options: " + StringUtils.join(SUB_COMMANDS, ", "));
    return true;
}
Also used : Player(org.bukkit.entity.Player) ArenaPlayer(com.elmakers.mine.bukkit.arena.ArenaPlayer) ArenaTemplate(com.elmakers.mine.bukkit.arena.ArenaTemplate) Arena(com.elmakers.mine.bukkit.arena.Arena) ArenaPlayer(com.elmakers.mine.bukkit.arena.ArenaPlayer) Location(org.bukkit.Location)

Aggregations

Arena (com.elmakers.mine.bukkit.arena.Arena)3 ArenaPlayer (com.elmakers.mine.bukkit.arena.ArenaPlayer)3 Player (org.bukkit.entity.Player)3 EventHandler (org.bukkit.event.EventHandler)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 ArenaTemplate (com.elmakers.mine.bukkit.arena.ArenaTemplate)1 Location (org.bukkit.Location)1