Search in sources :

Example 1 with ICommand

use of au.com.mineauz.minigames.commands.ICommand 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.getMinigameManager().hasMinigame(args[0])) {
                mgm = plugin.getMinigameManager().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];
                System.arraycopy(args, 2, shortArgs, 0, args.length - 2);
            }
        }
        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 2 with ICommand

use of au.com.mineauz.minigames.commands.ICommand 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.getMinigameManager().hasMinigame(args[0])) {
            mgm = plugin.getMinigameManager().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];
            System.arraycopy(args, 2, shortArgs, 0, args.length - 2);
            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<>(parameterList.keySet());
                return MinigameUtils.tabCompleteMatch(ls, args[1]);
            }
        } else if (args.length == 1) {
            List<String> ls = new ArrayList<>(plugin.getMinigameManager().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)

Aggregations

ICommand (au.com.mineauz.minigames.commands.ICommand)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 Player (org.bukkit.entity.Player)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1