Search in sources :

Example 51 with Minigame

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

the class EndCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args == null && sender instanceof Player) {
        MinigamePlayer ply = plugin.pdata.getMinigamePlayer((Player) sender);
        if (ply.isInMinigame()) {
            if (ply.getMinigame().getType() != MinigameType.SINGLEPLAYER) {
                List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(1);
                List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(ply.getMinigame().getPlayers().size());
                w.add(ply);
                l.addAll(ply.getMinigame().getPlayers());
                l.remove(ply);
                plugin.pdata.endMinigame(ply.getMinigame(), w, l);
                sender.sendMessage(ChatColor.GRAY + "You forced " + ply.getName() + " to win the Minigame.");
            } else {
                plugin.pdata.endMinigame(ply);
                sender.sendMessage(ChatColor.GRAY + "You forced " + ply.getName() + " to win the Minigame.");
            }
        } else {
            sender.sendMessage(ChatColor.RED + "Error: You are not in a minigame!");
        }
        return true;
    } else if (args != null) {
        Player player = null;
        if (sender instanceof Player) {
            player = (Player) sender;
        }
        if (player == null || player.hasPermission("minigame.end.other")) {
            List<Player> players = plugin.getServer().matchPlayer(args[0]);
            MinigamePlayer ply = null;
            Team team = null;
            Minigame mgm = null;
            if (args.length == 2 && plugin.mdata.hasMinigame(args[1])) {
                TeamColor color = TeamColor.matchColor(args[0]);
                mgm = plugin.mdata.getMinigame(args[1]);
                if (mgm == null) {
                    sender.sendMessage(ChatColor.RED + "No minigme found by the name " + args[1]);
                    return true;
                }
                if (TeamsModule.getMinigameModule(mgm).hasTeam(color)) {
                    team = TeamsModule.getMinigameModule(mgm).getTeam(color);
                } else {
                    sender.sendMessage(ChatColor.RED + "No team found by the name " + args[0] + " in " + mgm.getName(false));
                    return true;
                }
            } else if (args.length == 2 && !plugin.mdata.hasMinigame(args[1])) {
                sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[1]);
                return true;
            } else if (!players.isEmpty()) {
                ply = plugin.pdata.getMinigamePlayer(players.get(0));
            } else {
                sender.sendMessage(ChatColor.RED + "No player found by the name " + args[0]);
                return true;
            }
            if (ply != null && ply.isInMinigame()) {
                if (ply.getMinigame().getType() != MinigameType.SINGLEPLAYER) {
                    List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(1);
                    List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(ply.getMinigame().getPlayers().size());
                    w.add(ply);
                    l.addAll(ply.getMinigame().getPlayers());
                    l.remove(ply);
                    plugin.pdata.endMinigame(ply.getMinigame(), w, l);
                    sender.sendMessage(ChatColor.GRAY + "You forced " + ply.getName() + " to win the Minigame.");
                } else {
                    plugin.pdata.endMinigame(ply);
                    sender.sendMessage(ChatColor.GRAY + "You forced " + ply.getName() + " to win the Minigame.");
                }
            } else if (args.length >= 2 && team != null && mgm != null) {
                if (mgm.hasPlayers()) {
                    List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(team.getPlayers());
                    int lcount = 0;
                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                        if (t != team) {
                            lcount += t.getPlayers().size();
                        }
                    }
                    List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(lcount);
                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                        if (t != team) {
                            l.addAll(t.getPlayers());
                        }
                    }
                    plugin.pdata.endMinigame(mgm, w, l);
                    sender.sendMessage(ChatColor.GRAY + "You forced " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + " to win the Minigame.");
                } else {
                    sender.sendMessage(ChatColor.RED + "This Minigame has no players!");
                }
            } else {
                sender.sendMessage(ChatColor.RED + "This player is not playing a Minigame.");
            }
        } else if (player != null) {
            sender.sendMessage(ChatColor.RED + "Error: You don't have permission to force end another players Minigame!");
            sender.sendMessage(ChatColor.RED + "minigame.end.other");
        }
        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) List(java.util.List) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 52 with Minigame

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

the class SetCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    Player ply = null;
    if (sender instanceof Player) {
        ply = (Player) sender;
    }
    if (args != null) {
        ICommand comd = null;
        Minigame mgm = null;
        String[] shortArgs = null;
        if (args.length >= 1) {
            if (plugin.mdata.hasMinigame(args[0])) {
                mgm = plugin.mdata.getMinigame(args[0]);
            }
            if (args.length >= 2) {
                if (parameterList.containsKey(args[1].toLowerCase())) {
                    comd = parameterList.get(args[1].toLowerCase());
                } else {
                    AliasCheck: for (ICommand com : parameterList.values()) {
                        if (com.getAliases() != null) {
                            for (String alias : com.getAliases()) {
                                if (args[1].equalsIgnoreCase(alias)) {
                                    comd = com;
                                    break AliasCheck;
                                }
                            }
                        }
                    }
                }
            }
            if (args != null && args.length > 2) {
                shortArgs = new String[args.length - 2];
                for (int i = 2; i < args.length; i++) {
                    shortArgs[i - 2] = args[i];
                }
            }
        }
        if (comd != null && mgm != null) {
            if ((ply == null && comd.canBeConsole()) || ply != null) {
                if (ply == null || (comd.getPermission() == null || ply.hasPermission(comd.getPermission()))) {
                    boolean returnValue = comd.onCommand(sender, mgm, label, shortArgs);
                    if (!returnValue) {
                        sender.sendMessage(ChatColor.GREEN + "------------------Command Info------------------");
                        sender.sendMessage(ChatColor.BLUE + "Description: " + ChatColor.WHITE + comd.getDescription());
                        if (comd.getParameters() != null) {
                            String parameters = "";
                            boolean switchColour = false;
                            for (String par : comd.getParameters()) {
                                if (switchColour) {
                                    parameters += ChatColor.WHITE + par;
                                    if (!par.equalsIgnoreCase(comd.getParameters()[comd.getParameters().length - 1])) {
                                        parameters += ChatColor.WHITE + ", ";
                                    }
                                    switchColour = false;
                                } else {
                                    parameters += ChatColor.GRAY + par;
                                    if (!par.equalsIgnoreCase(comd.getParameters()[comd.getParameters().length - 1])) {
                                        parameters += ChatColor.WHITE + ", ";
                                    }
                                    switchColour = true;
                                }
                            }
                            sender.sendMessage(ChatColor.BLUE + "Parameters: " + parameters);
                        }
                        sender.sendMessage(ChatColor.BLUE + "Usage: ");
                        sender.sendMessage(comd.getUsage());
                        if (comd.getAliases() != null) {
                            String aliases = "";
                            boolean switchColour = false;
                            for (String alias : comd.getAliases()) {
                                if (switchColour) {
                                    aliases += ChatColor.WHITE + alias;
                                    if (!alias.equalsIgnoreCase(comd.getAliases()[comd.getAliases().length - 1])) {
                                        aliases += ChatColor.WHITE + ", ";
                                    }
                                    switchColour = false;
                                } else {
                                    aliases += ChatColor.GRAY + alias;
                                    if (!alias.equalsIgnoreCase(comd.getAliases()[comd.getAliases().length - 1])) {
                                        aliases += ChatColor.WHITE + ", ";
                                    }
                                    switchColour = true;
                                }
                            }
                            sender.sendMessage(ChatColor.BLUE + "Aliases: " + aliases);
                        }
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + comd.getPermissionMessage());
                    sender.sendMessage(ChatColor.RED + comd.getPermission());
                }
                return true;
            } else {
                sender.sendMessage(ChatColor.RED + "You must be a player to execute this command!");
                return true;
            }
        } else if (mgm == null) {
            sender.sendMessage(ChatColor.RED + "There is no Minigame by the name \"" + args[0] + "\"");
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) ICommand(au.com.mineauz.minigames.commands.ICommand) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 53 with Minigame

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

the class SetCommand method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Minigame minigame, String alias, String[] args) {
    if (args != null && args.length > 0) {
        Player ply = null;
        if (sender instanceof Player) {
            ply = (Player) sender;
        }
        ICommand comd = null;
        String[] shortArgs = null;
        Minigame mgm = null;
        if (plugin.mdata.hasMinigame(args[0])) {
            mgm = plugin.mdata.getMinigame(args[0]);
        }
        if (args.length > 1 && mgm != null) {
            if (parameterList.containsKey(args[1].toLowerCase())) {
                comd = parameterList.get(args[1].toLowerCase());
            }
            shortArgs = new String[args.length - 2];
            for (int i = 2; i < args.length; i++) {
                shortArgs[i - 2] = args[i];
            }
            if (comd != null) {
                if (ply != null) {
                    List<String> l = comd.onTabComplete(sender, mgm, alias, shortArgs);
                    if (l != null)
                        return l;
                    else
                        return MinigameUtils.stringToList("");
                }
            } else {
                List<String> ls = new ArrayList<String>(parameterList.keySet());
                return MinigameUtils.tabCompleteMatch(ls, args[1]);
            }
        } else if (args.length == 1) {
            List<String> ls = new ArrayList<String>(plugin.mdata.getAllMinigames().keySet());
            return MinigameUtils.tabCompleteMatch(ls, args[0]);
        }
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) ICommand(au.com.mineauz.minigames.commands.ICommand) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 54 with Minigame

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

the class StopCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        Minigame mgm = plugin.mdata.getMinigame(args[0]);
        if (mgm != null && mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
            MinigamePlayer caller = null;
            if (sender instanceof Player)
                caller = plugin.pdata.getMinigamePlayer((Player) sender);
            plugin.mdata.stopGlobalMinigame(mgm, caller);
        } else if (mgm == null || mgm.getType() != MinigameType.GLOBAL) {
            sender.sendMessage(ChatColor.RED + "There is no Global Minigame by the name \"" + args[0] + "\"");
        } else {
            sender.sendMessage(ChatColor.RED + mgm.getName(false) + " is not running!");
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 55 with Minigame

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

the class ToggleTimerCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        Minigame mgm = plugin.mdata.getMinigame(args[0]);
        if (mgm != null) {
            if (mgm.getMpTimer() != null) {
                if (mgm.getMpTimer().isPaused()) {
                    mgm.getMpTimer().resumeTimer();
                    sender.sendMessage(ChatColor.GRAY + "Resumed " + mgm.getName(false) + "'s countdown timer.");
                } else {
                    mgm.getMpTimer().pauseTimer(sender.getName() + " forced countdown pause.");
                    sender.sendMessage(ChatColor.GRAY + "Paused " + mgm.getName(false) + "'s countdown timer. (" + mgm.getMpTimer().getPlayerWaitTimeLeft() + "s)");
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Error: This minigame does not have a timer running!");
            }
        } else {
            sender.sendMessage(ChatColor.RED + "Error: The Minigame " + args[0] + " does not exist!");
        }
        return true;
    }
    return false;
}
Also used : Minigame(au.com.mineauz.minigames.minigame.Minigame)

Aggregations

Minigame (au.com.mineauz.minigames.minigame.Minigame)64 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)33 EventHandler (org.bukkit.event.EventHandler)29 ArrayList (java.util.ArrayList)19 Player (org.bukkit.entity.Player)16 Team (au.com.mineauz.minigames.minigame.Team)15 List (java.util.List)7 Location (org.bukkit.Location)7 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)4 Sign (org.bukkit.block.Sign)4 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)3 Block (org.bukkit.block.Block)3 ItemStack (org.bukkit.inventory.ItemStack)3 PotionEffect (org.bukkit.potion.PotionEffect)3 CTFFlag (au.com.mineauz.minigames.CTFFlag)2 MinigameData (au.com.mineauz.minigames.MinigameData)2 MultiplayerTimer (au.com.mineauz.minigames.MultiplayerTimer)2 ICommand (au.com.mineauz.minigames.commands.ICommand)2 TakeFlagEvent (au.com.mineauz.minigames.events.TakeFlagEvent)2 ScoreboardDisplay (au.com.mineauz.minigames.minigame.ScoreboardDisplay)2