Search in sources :

Example 41 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class ScoreCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null && args.length >= 2) {
        MinigamePlayer ply = null;
        TeamColor color = TeamColor.matchColor(args[1]);
        if (color == null) {
            List<Player> plys = plugin.getServer().matchPlayer(args[1]);
            if (!plys.isEmpty()) {
                ply = plugin.getPlayerManager().getMinigamePlayer(plys.get(0));
            } else {
                sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[1]);
                return true;
            }
        }
        if (args[0].equalsIgnoreCase("get") && args.length >= 2) {
            if (ply != null) {
                if (ply.isInMinigame()) {
                    sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s Score: " + ChatColor.GREEN + ply.getScore());
                } else {
                    sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
                }
            } else if (color != null) {
                if (args.length >= 3) {
                    Minigame mg = null;
                    if (plugin.getMinigameManager().hasMinigame(args[2])) {
                        mg = plugin.getMinigameManager().getMinigame(args[2]);
                    } else {
                        sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]);
                        return true;
                    }
                    TeamsModule tmod = TeamsModule.getMinigameModule(mg);
                    if (mg.isTeamGame()) {
                        if (tmod.hasTeam(color)) {
                            Team t = tmod.getTeam(color);
                            sender.sendMessage(color.getColor() + t.getDisplayName() + ChatColor.GRAY + " score in " + mg.getName(false) + ": " + ChatColor.GREEN + t.getScore());
                        } else {
                            sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
                        }
                    } else {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!");
                }
            }
            return true;
        } else if (args[0].equalsIgnoreCase("set") && args.length >= 3) {
            int score = 0;
            if (args[2].matches("-?[0-9]+")) {
                score = Integer.parseInt(args[2]);
            } else {
                sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!");
                return true;
            }
            if (ply != null) {
                if (ply.isInMinigame()) {
                    ply.setScore(score);
                    ply.getMinigame().setScore(ply, ply.getScore());
                    sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s score has been set to " + score);
                    if (ply.getMinigame().getMaxScore() != 0 && score >= ply.getMinigame().getMaxScorePerPlayer()) {
                        plugin.getPlayerManager().endMinigame(ply);
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
                }
            } else if (color != null) {
                if (args.length >= 4) {
                    Minigame mg = null;
                    if (plugin.getMinigameManager().hasMinigame(args[3])) {
                        mg = plugin.getMinigameManager().getMinigame(args[3]);
                    } else {
                        sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]);
                        return true;
                    }
                    TeamsModule tmod = TeamsModule.getMinigameModule(mg);
                    if (mg.isTeamGame() && mg.hasPlayers()) {
                        Team t = null;
                        if (tmod.hasTeam(color)) {
                            t = tmod.getTeam(color);
                            t.setScore(score);
                            sender.sendMessage(t.getChatColor() + t.getDisplayName() + ChatColor.GRAY + " score has been set to " + score);
                        } else {
                            sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
                            return true;
                        }
                        if (mg.getMaxScore() != 0 && score >= mg.getMaxScorePerPlayer()) {
                            List<MinigamePlayer> w = new ArrayList<>(t.getPlayers());
                            List<MinigamePlayer> l = new ArrayList<>(mg.getPlayers().size() - t.getPlayers().size());
                            for (Team te : tmod.getTeams()) {
                                if (te != t) {
                                    l.addAll(te.getPlayers());
                                }
                            }
                            plugin.getPlayerManager().endMinigame(mg, w, l);
                        }
                    } else if (!mg.hasPlayers()) {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!");
                    } else {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!");
                }
            }
            return true;
        } else if (args[0].equalsIgnoreCase("add") && args.length >= 3) {
            int score = 0;
            if (args[2].matches("-?[0-9]+")) {
                score = Integer.parseInt(args[2]);
            } else {
                score = 1;
            }
            if (ply != null) {
                if (ply.isInMinigame()) {
                    ply.addScore(score);
                    ply.getMinigame().setScore(ply, ply.getScore());
                    sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + ply.getName() + "'s score, new score: " + ply.getScore());
                    if (ply.getMinigame().getMaxScore() != 0 && ply.getScore() >= ply.getMinigame().getMaxScorePerPlayer()) {
                        plugin.getPlayerManager().endMinigame(ply);
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
                }
            } else if (color != null) {
                Minigame mg = null;
                String mgName = null;
                if (args.length == 4) {
                    mgName = args[3];
                } else {
                    mgName = args[2];
                }
                if (plugin.getMinigameManager().hasMinigame(mgName)) {
                    mg = plugin.getMinigameManager().getMinigame(mgName);
                } else {
                    sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + mgName);
                    return true;
                }
                TeamsModule tmod = TeamsModule.getMinigameModule(mg);
                if (mg.isTeamGame() && mg.hasPlayers()) {
                    Team team = null;
                    if (tmod.hasTeam(color)) {
                        team = tmod.getTeam(color);
                        team.addScore(score);
                        sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + " score, new score: " + team.getScore());
                    } else {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
                        return true;
                    }
                    if (mg.getMaxScore() != 0 && team.getScore() >= mg.getMaxScorePerPlayer()) {
                        List<MinigamePlayer> w = new ArrayList<>(team.getPlayers());
                        List<MinigamePlayer> l = new ArrayList<>(mg.getPlayers().size() - team.getPlayers().size());
                        for (Team te : tmod.getTeams()) {
                            if (te != team) {
                                l.addAll(te.getPlayers());
                            }
                        }
                        plugin.getPlayerManager().endMinigame(mg, w, l);
                    }
                } else if (!mg.hasPlayers()) {
                    sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!");
                } else {
                    sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) TeamsModule(au.com.mineauz.minigames.minigame.modules.TeamsModule) Team(au.com.mineauz.minigames.minigame.Team) List(java.util.List) ArrayList(java.util.ArrayList) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 42 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class SpectateCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        if (plugin.getMinigameManager().hasMinigame(args[0])) {
            MinigamePlayer ply = plugin.getPlayerManager().getMinigamePlayer((Player) sender);
            Minigame mgm = plugin.getMinigameManager().getMinigame(args[0]);
            plugin.getPlayerManager().spectateMinigame(ply, mgm);
        } else {
            sender.sendMessage(ChatColor.RED + "No Minigame found by the name: " + args[0]);
        }
        return true;
    }
    return false;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 43 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class GlobalLoadoutCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    MinigamePlayer player = Minigames.getPlugin().getPlayerManager().getMinigamePlayer((Player) sender);
    Menu loadouts = new Menu(6, getName(), player);
    List<String> des = new ArrayList<>();
    des.add("Shift + Right Click to Delete");
    List<MenuItem> mi = new ArrayList<>();
    for (String ld : mdata.getLoadouts()) {
        Material item = Material.WHITE_STAINED_GLASS_PANE;
        if (mdata.getLoadout(ld).getItems().size() != 0) {
            item = mdata.getLoadout(ld).getItem((Integer) mdata.getLoadout(ld).getItems().toArray()[0]).getType();
        }
        mi.add(new MenuItemDisplayLoadout(ld, des, item, mdata.getLoadout(ld)));
    }
    loadouts.addItem(new MenuItemLoadoutAdd("Add Loadout", Material.ITEM_FRAME, mdata.getLoadoutMap()), 53);
    loadouts.addItems(mi);
    loadouts.displayMenu(player);
    return true;
}
Also used : MenuItemDisplayLoadout(au.com.mineauz.minigames.menu.MenuItemDisplayLoadout) MenuItemLoadoutAdd(au.com.mineauz.minigames.menu.MenuItemLoadoutAdd) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) MenuItem(au.com.mineauz.minigames.menu.MenuItem) Material(org.bukkit.Material) Menu(au.com.mineauz.minigames.menu.Menu)

Example 44 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class HintCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer((Player) sender);
    if (args != null) {
        Minigame mgm = plugin.getMinigameManager().getMinigame(args[0]);
        if (mgm != null && mgm.getMinigameTimer() != null && mgm.getType() == MinigameType.GLOBAL && mgm.getMechanicName().equals("treasure_hunt")) {
            TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgm);
            if (thm.hasTreasureLocation() && !thm.isTreasureFound()) {
                thm.getHints(player);
            } else {
                player.sendInfoMessage(ChatColor.GRAY + mgm.getName(false) + " is currently not running.");
            }
        } else if (mgm == null || mgm.getType() != MinigameType.GLOBAL) {
            player.sendMessage(ChatColor.RED + "There is no treasure hunt running by the name \"" + args[0] + "\"", MinigameMessageType.ERROR);
        }
    } else {
        List<Minigame> mgs = new ArrayList<>();
        for (Minigame mg : plugin.getMinigameManager().getAllMinigames().values()) {
            if (mg.getType() == MinigameType.GLOBAL && mg.getMechanicName().equals("treasure_hunt")) {
                mgs.add(mg);
            }
        }
        if (!mgs.isEmpty()) {
            if (mgs.size() > 1) {
                player.sendInfoMessage(ChatColor.LIGHT_PURPLE + "Currently running Treasure Hunts:");
                String treasures = "";
                for (int i = 0; i < mgs.size(); i++) {
                    treasures += mgs.get(i).getName(false);
                    if (i != mgs.size() - 1) {
                        treasures += ", ";
                    }
                }
                player.sendInfoMessage(ChatColor.GRAY + treasures);
            } else {
                TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgs.get(0));
                if (thm.hasTreasureLocation() && !thm.isTreasureFound()) {
                    thm.getHints(player);
                } else {
                    player.sendInfoMessage(ChatColor.GRAY + mgs.get(0).getName(false) + " is currently not running.");
                }
            }
        } else if (mgs.isEmpty()) {
            player.sendInfoMessage(ChatColor.LIGHT_PURPLE + "There are no Treasure Hunt minigames currently running.");
        }
    }
    return true;
}
Also used : TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 45 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class QuitCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args == null && sender instanceof Player) {
        MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer((Player) sender);
        if (player.isInMinigame()) {
            plugin.getPlayerManager().quitMinigame(player, false);
        } else {
            sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.notPlaying"));
        }
        return true;
    } else if (args != null) {
        Player player = null;
        if (sender instanceof Player) {
            player = (Player) sender;
        }
        if (player == null || player.hasPermission("minigame.quit.other")) {
            List<Player> players = plugin.getServer().matchPlayer(args[0]);
            MinigamePlayer ply = null;
            if (args[0].equals("ALL")) {
                if (args.length > 1) {
                    if (plugin.getMinigameManager().hasMinigame(args[1])) {
                        Minigame mg = plugin.getMinigameManager().getMinigame(args[1]);
                        List<MinigamePlayer> pls = new ArrayList<>(mg.getPlayers());
                        for (MinigamePlayer pl : pls) {
                            plugin.getPlayerManager().quitMinigame(pl, true);
                        }
                        sender.sendMessage(ChatColor.GRAY + MinigameUtils.formStr("command.quit.quitAllMinigame", mg.getName(true)));
                    } else {
                        sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("minigame.error.noMinigameName", args[1]));
                    }
                } else {
                    for (MinigamePlayer pl : plugin.getPlayerManager().getAllMinigamePlayers()) {
                        if (pl.isInMinigame()) {
                            plugin.getPlayerManager().quitMinigame(pl, true);
                        }
                    }
                    sender.sendMessage(ChatColor.GRAY + MinigameUtils.getLang("command.quit.quitAll"));
                }
                return true;
            } else if (players.isEmpty()) {
                sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.quit.invalidPlayer", args[0]));
                return true;
            } else {
                ply = plugin.getPlayerManager().getMinigamePlayer(players.get(0));
            }
            if (ply != null && ply.isInMinigame()) {
                plugin.getPlayerManager().quitMinigame(ply, false);
                sender.sendMessage(ChatColor.GRAY + MinigameUtils.formStr("command.quit.quitOther", ply.getName()));
            } else {
                sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.quit.invalidPlayer", args[0]));
            }
        } else if (player != null) {
            sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.noPermissionOther"));
            sender.sendMessage(ChatColor.RED + "minigame.quit.other");
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) List(java.util.List) ArrayList(java.util.ArrayList) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Aggregations

MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)134 EventHandler (org.bukkit.event.EventHandler)46 Minigame (au.com.mineauz.minigames.minigame.Minigame)40 ArrayList (java.util.ArrayList)25 Team (au.com.mineauz.minigames.minigame.Team)24 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)15 Player (org.bukkit.entity.Player)15 Location (org.bukkit.Location)11 ItemStack (org.bukkit.inventory.ItemStack)8 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)7 Menu (au.com.mineauz.minigames.menu.Menu)5 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)5 List (java.util.List)5 PotionEffect (org.bukkit.potion.PotionEffect)5 ResourcePack (au.com.mineauz.minigames.objects.ResourcePack)4 Material (org.bukkit.Material)4 Sign (org.bukkit.block.Sign)4 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)3 MenuItem (au.com.mineauz.minigames.menu.MenuItem)2 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)2