Search in sources :

Example 1 with TeamColor

use of au.com.mineauz.minigames.minigame.TeamColor in project Minigames by AddstarMC.

the class MenuItemAddTeam method checkValidEntry.

@Override
public void checkValidEntry(String entry) {
    entry = entry.toUpperCase().replace(" ", "_");
    if (TeamColor.matchColor(entry) != null) {
        TeamColor col = TeamColor.matchColor(entry);
        if (!tm.hasTeam(col)) {
            tm.addTeam(col);
            Team t = tm.getTeam(col);
            getContainer().addItem(new MenuItemTeam(t.getChatColor() + t.getDisplayName(), t));
        } else {
            getContainer().getViewer().sendMessage(ChatColor.RED + "A team already exists using that color!");
        }
        List<String> teams = new ArrayList<String>(tm.getTeams().size() + 1);
        for (Team t : tm.getTeams()) {
            teams.add(MinigameUtils.capitalize(t.getColor().toString().replace("_", " ")));
        }
        teams.add("None");
        getContainer().removeItem(0);
        getContainer().addItem(new MenuItemList("Default Winning Team", Material.PAPER, tm.getDefaultWinnerCallback(), teams), 0);
        getContainer().cancelReopenTimer();
        getContainer().displayMenu(getContainer().getViewer());
        return;
    }
    getContainer().cancelReopenTimer();
    getContainer().displayMenu(getContainer().getViewer());
    getContainer().getViewer().sendMessage("There is no team color by the name of " + entry.toLowerCase().replace("_", " "), "error");
}
Also used : ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) Team(au.com.mineauz.minigames.minigame.Team)

Example 2 with TeamColor

use of au.com.mineauz.minigames.minigame.TeamColor in project Minigames by AddstarMC.

the class MenuItemAddTeam method onClick.

@Override
public ItemStack onClick() {
    MinigamePlayer ply = getContainer().getViewer();
    ply.setNoClose(true);
    ply.getPlayer().closeInventory();
    ply.sendMessage("Enter the color of the team you wish to add. All colors available below:", null);
    List<String> teams = new ArrayList<String>();
    for (TeamColor col : TeamColor.values()) teams.add(col.getColor() + MinigameUtils.capitalize(col.toString().replace("_", " ")));
    ply.sendMessage(MinigameUtils.listToString(teams));
    ply.setManualEntry(this);
    getContainer().startReopenTimer(30);
    return null;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor)

Example 3 with TeamColor

use of au.com.mineauz.minigames.minigame.TeamColor in project Minigames by AddstarMC.

the class MenuItemDisplayLoadout method onClick.

@Override
public ItemStack onClick() {
    Menu loadoutMenu = new Menu(5, loadout.getName(false), getContainer().getViewer());
    Menu loadoutSettings = new Menu(6, loadout.getName(false), getContainer().getViewer());
    loadoutSettings.setPreviousPage(loadoutMenu);
    List<MenuItem> mItems = new ArrayList<MenuItem>();
    if (!loadout.getName(false).equals("default"))
        mItems.add(new MenuItemBoolean("Use Permissions", MinigameUtils.stringToList("Permission:;minigame.loadout." + loadout.getName(false).toLowerCase()), Material.GOLD_INGOT, loadout.getUsePermissionsCallback()));
    MenuItemString disName = new MenuItemString("Display Name", Material.PAPER, loadout.getDisplayNameCallback());
    disName.setAllowNull(true);
    mItems.add(disName);
    mItems.add(new MenuItemBoolean("Allow Fall Damage", Material.LEATHER_BOOTS, loadout.getFallDamageCallback()));
    mItems.add(new MenuItemBoolean("Allow Hunger", Material.APPLE, loadout.getHungerCallback()));
    mItems.add(new MenuItemInteger("XP Level", MinigameUtils.stringToList("Use -1 to not;use loadout levels"), Material.EXP_BOTTLE, loadout.getLevelCallback(), -1, null));
    mItems.add(new MenuItemBoolean("Lock Inventory", Material.DIAMOND_SWORD, loadout.getInventoryLockedCallback()));
    mItems.add(new MenuItemBoolean("Lock Armour", Material.DIAMOND_CHESTPLATE, loadout.getArmourLockedCallback()));
    mItems.add(new MenuItemBoolean("Allow Offhand", Material.SHIELD, loadout.getAllowOffHandCallback()));
    mItems.add(new MenuItemBoolean("Display in Loadout Menu", Material.THIN_GLASS, loadout.getDisplayInMenuCallback()));
    List<String> teams = new ArrayList<String>();
    teams.add("None");
    for (TeamColor col : TeamColor.values()) teams.add(MinigameUtils.capitalize(col.toString()));
    mItems.add(new MenuItemList("Lock to Team", Material.LEATHER_CHESTPLATE, loadout.getTeamColorCallback(), teams));
    loadoutSettings.addItems(mItems);
    if (mgm == null) {
        MenuItemDisplayLoadout dl = new MenuItemDisplayLoadout("Back", Material.REDSTONE_TORCH_ON, loadout);
        dl.setAltMenu(getContainer());
        loadoutSettings.addItem(dl, getContainer().getSize() - 9);
    } else {
        MenuItemDisplayLoadout dl = new MenuItemDisplayLoadout("Back", Material.REDSTONE_TORCH_ON, loadout, mgm);
        dl.setAltMenu(getContainer());
        loadoutSettings.addItem(dl, getContainer().getSize() - 9);
    }
    LoadoutModule.addAddonMenuItems(loadoutSettings, loadout);
    Menu potionMenu = new Menu(5, getContainer().getName(), getContainer().getViewer());
    potionMenu.setPreviousPage(loadoutMenu);
    potionMenu.addItem(new MenuItemPotionAdd("Add Potion", Material.ITEM_FRAME, loadout), 44);
    if (mgm == null) {
        MenuItemDisplayLoadout dl = new MenuItemDisplayLoadout("Back", Material.REDSTONE_TORCH_ON, loadout);
        dl.setAltMenu(getContainer());
        potionMenu.addItem(dl, 45 - 9);
    } else {
        MenuItemDisplayLoadout dl = new MenuItemDisplayLoadout("Back", Material.REDSTONE_TORCH_ON, loadout, mgm);
        dl.setAltMenu(getContainer());
        potionMenu.addItem(dl, 45 - 9);
    }
    List<String> des = new ArrayList<String>();
    des.add("Shift + Right Click to Delete");
    List<MenuItem> potions = new ArrayList<MenuItem>();
    for (PotionEffect eff : loadout.getAllPotionEffects()) {
        potions.add(new MenuItemPotion(MinigameUtils.capitalize(eff.getType().getName().replace("_", " ")), des, Material.POTION, eff, loadout));
    }
    potionMenu.addItems(potions);
    loadoutMenu.setAllowModify(true);
    if (altMenu == null)
        loadoutMenu.setPreviousPage(getContainer());
    else
        loadoutMenu.setPreviousPage(altMenu);
    loadoutMenu.addItem(new MenuItemSaveLoadout("Loadout Settings", Material.CHEST, loadout, loadoutSettings), 42);
    loadoutMenu.addItem(new MenuItemSaveLoadout("Edit Potion Effects", Material.POTION, loadout, potionMenu), 43);
    loadoutMenu.addItem(new MenuItemSaveLoadout("Save Loadout", Material.REDSTONE_TORCH_ON, loadout), 44);
    for (int i = 40; i < 42; i++) {
        loadoutMenu.addItem(new MenuItem("", null), i);
    }
    loadoutMenu.displayMenu(getContainer().getViewer());
    for (Integer item : loadout.getItems()) {
        if (item < 100)
            loadoutMenu.addItemStack(loadout.getItem(item), item);
        else if (item == 100)
            loadoutMenu.addItemStack(loadout.getItem(item), 39);
        else if (item == 101)
            loadoutMenu.addItemStack(loadout.getItem(item), 38);
        else if (item == 102)
            loadoutMenu.addItemStack(loadout.getItem(item), 37);
        else if (item == 103)
            loadoutMenu.addItemStack(loadout.getItem(item), 36);
    }
    return null;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor)

Example 4 with TeamColor

use of au.com.mineauz.minigames.minigame.TeamColor 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.pdata.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.mdata.hasMinigame(args[2])) {
                        mg = plugin.mdata.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.pdata.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.mdata.hasMinigame(args[3])) {
                        mg = plugin.mdata.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<MinigamePlayer>(t.getPlayers());
                            List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mg.getPlayers().size() - t.getPlayers().size());
                            for (Team te : tmod.getTeams()) {
                                if (te != t) {
                                    l.addAll(te.getPlayers());
                                }
                            }
                            plugin.pdata.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.pdata.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.mdata.hasMinigame(mgName)) {
                    mg = plugin.mdata.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<MinigamePlayer>(team.getPlayers());
                        List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mg.getPlayers().size() - team.getPlayers().size());
                        for (Team te : tmod.getTeams()) {
                            if (te != team) {
                                l.addAll(te.getPlayers());
                            }
                        }
                        plugin.pdata.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.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.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 5 with TeamColor

use of au.com.mineauz.minigames.minigame.TeamColor in project Minigames by AddstarMC.

the class SetTeamCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        TeamsModule tmod = TeamsModule.getMinigameModule(minigame);
        if (args[0].equalsIgnoreCase("add")) {
            if (args.length >= 2) {
                TeamColor col = TeamColor.matchColor(args[1]);
                String name = null;
                if (col != null) {
                    if (args.length > 2) {
                        name = "";
                        for (int i = 2; i < args.length; i++) {
                            name += args[i];
                            if (i != args.length - 1)
                                name += " ";
                        }
                    }
                    if (name != null) {
                        tmod.addTeam(col, name);
                        sender.sendMessage(ChatColor.GRAY + "Added " + MinigameUtils.capitalize(col.toString()) + " team to " + minigame.getName(false) + " with the display name " + name);
                    } else {
                        tmod.addTeam(col);
                        sender.sendMessage(ChatColor.GRAY + "Added " + MinigameUtils.capitalize(col.toString()) + " team to " + minigame.getName(false));
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "Invalid team color! Valid options:");
                    List<String> cols = new ArrayList<String>(TeamColor.values().length);
                    for (TeamColor c : TeamColor.values()) {
                        cols.add(c.toString());
                    }
                    sender.sendMessage(MinigameUtils.listToString(cols));
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Valid team color options:");
                List<String> cols = new ArrayList<String>(TeamColor.values().length);
                for (TeamColor c : TeamColor.values()) {
                    cols.add(c.toString());
                }
                sender.sendMessage(MinigameUtils.listToString(cols));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("list")) {
            List<String> teams = new ArrayList<String>(tmod.getTeams().size());
            for (Team t : tmod.getTeams()) {
                teams.add(t.getChatColor() + t.getColor().toString() + ChatColor.GRAY + "(" + t.getChatColor() + t.getDisplayName() + ChatColor.GRAY + ")");
            }
            String teamsString = "";
            for (String t : teams) {
                teamsString += t;
                if (!t.equals(teams.get(teams.size() - 1)))
                    teamsString += ", ";
            }
            sender.sendMessage(ChatColor.GRAY + "List of teams in " + minigame.getName(false) + ":");
            sender.sendMessage(teamsString);
            return true;
        } else if (args[0].equalsIgnoreCase("remove")) {
            if (args.length >= 2) {
                TeamColor col = TeamColor.matchColor(args[1]);
                if (col != null) {
                    if (tmod.hasTeam(col)) {
                        tmod.removeTeam(col);
                        sender.sendMessage(ChatColor.GRAY + "Removed " + MinigameUtils.capitalize(col.toString()) + " from " + minigame.getName(false));
                    } else {
                        sender.sendMessage(ChatColor.RED + minigame.getName(false) + " does not have the team " + MinigameUtils.capitalize(col.toString()));
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "Invalid team color! Valid options:");
                    List<String> cols = new ArrayList<String>(TeamColor.values().length);
                    for (Team c : tmod.getTeams()) {
                        cols.add(c.getColor().toString());
                    }
                    sender.sendMessage(MinigameUtils.listToString(cols));
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Valid teams:");
                List<String> cols = new ArrayList<String>(TeamColor.values().length);
                for (Team c : tmod.getTeams()) {
                    cols.add(c.getColor().toString());
                }
                sender.sendMessage(MinigameUtils.listToString(cols));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("rename")) {
            if (args.length > 2) {
                TeamColor col = TeamColor.matchColor(args[1]);
                String name = "";
                for (int i = 2; i < args.length; i++) {
                    name += args[i];
                    if (i != args.length - 1)
                        name += " ";
                }
                if (col != null) {
                    if (tmod.hasTeam(col)) {
                        tmod.getTeam(col).setDisplayName(name);
                        sender.sendMessage(ChatColor.GRAY + "Set " + MinigameUtils.capitalize(col.toString()) + " display name to " + name + " for " + minigame.getName(false));
                    } else {
                        sender.sendMessage(ChatColor.RED + minigame.getName(false) + " does not have the team " + MinigameUtils.capitalize(col.toString()));
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "Invalid team color! Valid options:");
                    List<String> cols = new ArrayList<String>(TeamColor.values().length);
                    for (Team c : tmod.getTeams()) {
                        cols.add(c.getColor().toString());
                    }
                    sender.sendMessage(MinigameUtils.listToString(cols));
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Valid teams:");
                List<String> cols = new ArrayList<String>(TeamColor.values().length);
                for (Team c : tmod.getTeams()) {
                    cols.add(c.getColor().toString());
                }
                sender.sendMessage(MinigameUtils.listToString(cols));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("maxplayers") && args.length == 3) {
            if (TeamColor.matchColor(args[1]) != null) {
                TeamColor col = TeamColor.matchColor(args[1]);
                if (tmod.hasTeam(col)) {
                    if (args[2].matches("[0-9]+")) {
                        int val = Integer.valueOf(args[2]);
                        tmod.getTeam(col).setMaxPlayers(Integer.valueOf(args[2]));
                        sender.sendMessage(ChatColor.GRAY + "Maximum players for the team " + tmod.getTeam(col).getDisplayName() + " has been set to " + val);
                    } else {
                        sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!");
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "There is no " + MinigameUtils.capitalize(col.toString()) + " Team in " + minigame);
                }
            } else {
                sender.sendMessage(ChatColor.RED + args[1] + " is not a valid team color!");
            }
            return true;
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) List(java.util.List) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) TeamsModule(au.com.mineauz.minigames.minigame.modules.TeamsModule)

Aggregations

TeamColor (au.com.mineauz.minigames.minigame.TeamColor)16 ArrayList (java.util.ArrayList)13 Menu (au.com.mineauz.minigames.menu.Menu)6 Team (au.com.mineauz.minigames.minigame.Team)6 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)5 Callback (au.com.mineauz.minigames.menu.Callback)5 MenuItemList (au.com.mineauz.minigames.menu.MenuItemList)5 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)5 Minigame (au.com.mineauz.minigames.minigame.Minigame)3 List (java.util.List)3 TeamsModule (au.com.mineauz.minigames.minigame.modules.TeamsModule)2 Player (org.bukkit.entity.Player)2 InteractionInterface (au.com.mineauz.minigames.menu.InteractionInterface)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemAddTeam (au.com.mineauz.minigames.menu.MenuItemAddTeam)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemInteger (au.com.mineauz.minigames.menu.MenuItemInteger)1 MenuItemNewLine (au.com.mineauz.minigames.menu.MenuItemNewLine)1 MenuItemTeam (au.com.mineauz.minigames.menu.MenuItemTeam)1 MenuItemToolMode (au.com.mineauz.minigames.menu.MenuItemToolMode)1