Search in sources :

Example 26 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.

the class ArenaInventoryListener method onItemDrop.

/**
 * Manage item dropping.
 */
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
    // Check if player is in Arena
    Player player = event.getPlayer();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    if (arena == null) {
        return;
    }
    // Stop drops entirely if player not on team
    if ((arena.getTeam(player.getUniqueId()).equals("no team"))) {
        event.setCancelled(true);
        return;
    }
    // Stop drops of gear items
    MissileWarsPlayer mwPlayer = arena.getPlayerInArena(player.getUniqueId());
    if (mwPlayer.getDeck().getGear().contains(event.getItemDrop().getItemStack())) {
        event.setCancelled(true);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 27 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.

the class CustomItemListener method isRedTeam.

/**
 * Check if a given player is on the red team.
 *
 * @param player the player
 * @return true if they are on the red team, false otherwise (including if they are not on any team at all)
 */
private boolean isRedTeam(Player player) {
    // Find player's team (Default to blue)
    boolean redTeam = false;
    Arena arena = getPlayerArena(player);
    if (arena != null) {
        redTeam = arena.getTeam(player.getUniqueId()).equalsIgnoreCase(ChatColor.RED + "red" + ChatColor.RESET);
    }
    return redTeam;
}
Also used : Arena(com.leomelonseeds.missilewars.arenas.Arena)

Example 28 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.

the class MissileWarsPlaceholder method onRequest.

@Override
public String onRequest(OfflinePlayer player, String params) {
    // Stop trying to fetch placeholders if the plugin is disabled
    if (!MissileWarsPlugin.getPlugin().isEnabled()) {
        return null;
    }
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena playerArena = manager.getArena(player.getUniqueId());
    DecimalFormat df = new DecimalFormat("##.##");
    // General purpose placeholders
    if (params.equalsIgnoreCase("focus")) {
        return ConfigUtils.getFocusName(player);
    }
    if (params.equalsIgnoreCase("team")) {
        return playerArena == null ? "no team" : ChatColor.stripColor(playerArena.getTeam(player.getUniqueId()));
    }
    if (params.equalsIgnoreCase("deck")) {
        JSONObject json = MissileWarsPlugin.getPlugin().getJSON().getPlayer(player.getUniqueId());
        String deck = json.getString("Deck");
        ChatColor chatcolor = ChatColor.WHITE;
        switch(deck) {
            case "Vanguard":
                chatcolor = ChatColor.GOLD;
                break;
            case "Sentinel":
                chatcolor = ChatColor.AQUA;
                break;
            case "Berserker":
                chatcolor = ChatColor.RED;
        }
        return chatcolor + json.getString("Deck");
    }
    // Rank placeholders
    if (params.contains("rank_")) {
        int exp = MissileWarsPlugin.getPlugin().getSQL().getExpSync(player.getUniqueId());
        int level = RankUtils.getRankLevel(exp);
        int max = 10;
        if (params.equalsIgnoreCase("rank_exp_total")) {
            return Integer.toString(exp);
        }
        if (params.equalsIgnoreCase("rank_name")) {
            return RankUtils.getRankName(exp);
        }
        if (params.equalsIgnoreCase("rank_symbol")) {
            return RankUtils.getRankSymbol(exp);
        }
        if (params.equalsIgnoreCase("rank_exp")) {
            if (level >= max) {
                return "0";
            }
            return Integer.toString(RankUtils.getCurrentExp(exp));
        }
        if (params.equalsIgnoreCase("rank_exp_next")) {
            if (level >= max) {
                return "N/A";
            }
            return Integer.toString(RankUtils.getNextExp(exp));
        }
        if (params.equalsIgnoreCase("rank_progress_percentage")) {
            if (level >= max) {
                return "0%";
            }
            return df.format(RankUtils.getExpProgress(exp) * 100) + "%";
        }
        if (params.contains("rank_progress_bar")) {
            String[] args = params.split("_");
            int size = Integer.parseInt(args[3]);
            if (level >= max) {
                String result = "";
                for (int i = 0; i < size; i++) {
                    result = result + "|";
                }
                return ChatColor.GRAY + result;
            }
            return RankUtils.getProgressBar(exp, size);
        }
        return null;
    }
    // Stats placeholders. Includes top 10 placeholders, which includes top 10 exp values.
    if (params.contains("stats")) {
        SQLManager sql = MissileWarsPlugin.getPlugin().getSQL();
        String[] args = params.split("_");
        String gamemode = args[1];
        String stat = args[2];
        // stats_[gamemode/overall]_[stat]
        if (args.length == 3) {
            return Integer.toString(sql.getStatSync(player.getUniqueId(), stat, gamemode));
        }
        // # can be 1-10, nothing more or error
        if (args[3].equals("top")) {
            List<ArrayList<Object>> list = sql.getTopTenStat(stat, gamemode);
            int index = Integer.parseInt(args[4]) - 1;
            String playerName = RankUtils.getLeaderboardPlayer((OfflinePlayer) list.get(index).get(0));
            String playerStat = Integer.toString((int) list.get(index).get(1));
            return ChatColor.translateAlternateColorCodes('&', playerName + " &7- &f" + playerStat);
        }
        // Gets the player position in for that stat
        if (args[3].equals("rank")) {
            return Integer.toString(sql.getStatRank(player.getUniqueId(), stat, gamemode));
        }
        return null;
    }
    if (playerArena == null) {
        return null;
    }
    if (params.equalsIgnoreCase("arena")) {
        return playerArena.getName();
    }
    if (params.equalsIgnoreCase("gamemode")) {
        return ChatColor.GREEN + "Classic";
    }
    boolean inGame = playerArena.isRunning() || playerArena.isResetting();
    if (params.equalsIgnoreCase("ingame")) {
        return inGame ? "true" : "false";
    }
    if (params.equalsIgnoreCase("red_queue")) {
        return Integer.toString(playerArena.getRedQueue());
    }
    if (params.equalsIgnoreCase("blue_queue")) {
        return Integer.toString(playerArena.getBlueQueue());
    }
    if (!inGame) {
        return null;
    }
    // In-Game placeholders
    MissileWarsTeam redTeam = playerArena.getRedTeam();
    MissileWarsTeam blueTeam = playerArena.getBlueTeam();
    if (params.equalsIgnoreCase("map")) {
        return ConfigUtils.getMapText(playerArena.getMapType(), playerArena.getMapName(), "name");
    }
    if (params.equalsIgnoreCase("time_remaining")) {
        return playerArena.getTimeRemaining();
    }
    if (params.equalsIgnoreCase("red_shield_health")) {
        double health = Math.max(0, redTeam.getShieldHealth());
        ChatColor chatcolor;
        if (health >= 90) {
            chatcolor = ChatColor.DARK_GREEN;
        } else if (health >= 80) {
            chatcolor = ChatColor.GREEN;
        } else if (health >= 70) {
            chatcolor = ChatColor.YELLOW;
        } else if (health >= 60) {
            chatcolor = ChatColor.GOLD;
        } else if (health >= 50) {
            chatcolor = ChatColor.RED;
        } else {
            chatcolor = ChatColor.DARK_RED;
        }
        return chatcolor + df.format(health) + "%";
    }
    if (params.equalsIgnoreCase("blue_shield_health")) {
        double health = Math.max(0, blueTeam.getShieldHealth());
        ChatColor chatcolor;
        if (health >= 90) {
            chatcolor = ChatColor.DARK_GREEN;
        } else if (health >= 80) {
            chatcolor = ChatColor.GREEN;
        } else if (health >= 70) {
            chatcolor = ChatColor.YELLOW;
        } else if (health >= 60) {
            chatcolor = ChatColor.GOLD;
        } else if (health >= 50) {
            chatcolor = ChatColor.RED;
        } else {
            chatcolor = ChatColor.DARK_RED;
        }
        return chatcolor + df.format(health) + "%";
    }
    if (params.equalsIgnoreCase("red_team")) {
        return Integer.toString(redTeam.getSize());
    }
    if (params.equalsIgnoreCase("blue_team")) {
        return Integer.toString(blueTeam.getSize());
    }
    if (params.equalsIgnoreCase("red_portals")) {
        String firstPortal = redTeam.getFirstPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
        String secondPortal = redTeam.getSecondPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
        if (playerArena.getTeam(player.getUniqueId()).equalsIgnoreCase(ChatColor.RED + "red" + ChatColor.RESET)) {
            return firstPortal + secondPortal;
        }
        return secondPortal + firstPortal;
    }
    if (params.equalsIgnoreCase("blue_portals")) {
        String firstPortal = blueTeam.getFirstPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
        String secondPortal = blueTeam.getSecondPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
        if (playerArena.getTeam(player.getUniqueId()).equalsIgnoreCase(ChatColor.BLUE + "blue" + ChatColor.RESET)) {
            return secondPortal + firstPortal;
        }
        return firstPortal + secondPortal;
    }
    // Placeholder is unknown by the Expansion
    return null;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Arena(com.leomelonseeds.missilewars.arenas.Arena) JSONObject(org.json.JSONObject) ChatColor(org.bukkit.ChatColor) MissileWarsTeam(com.leomelonseeds.missilewars.teams.MissileWarsTeam)

Aggregations

Arena (com.leomelonseeds.missilewars.arenas.Arena)28 EventHandler (org.bukkit.event.EventHandler)21 Player (org.bukkit.entity.Player)20 ArenaManager (com.leomelonseeds.missilewars.arenas.ArenaManager)16 MissileWarsPlayer (com.leomelonseeds.missilewars.teams.MissileWarsPlayer)16 ItemStack (org.bukkit.inventory.ItemStack)6 Block (org.bukkit.block.Block)4 Projectile (org.bukkit.entity.Projectile)4 MissileWarsPlugin (com.leomelonseeds.missilewars.MissileWarsPlugin)3 Component (net.kyori.adventure.text.Component)2 Location (org.bukkit.Location)2 JSONObject (org.json.JSONObject)2 PlayerPostRespawnEvent (com.destroystokyo.paper.event.player.PlayerPostRespawnEvent)1 MissileWarsTeam (com.leomelonseeds.missilewars.teams.MissileWarsTeam)1 ConfigUtils (com.leomelonseeds.missilewars.utilities.ConfigUtils)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 ChatColor (org.bukkit.ChatColor)1 Material (org.bukkit.Material)1 Creeper (org.bukkit.entity.Creeper)1