Search in sources :

Example 1 with ConsoleCommandSender

use of org.bukkit.command.ConsoleCommandSender in project AuthMeReloaded by AuthMe.

the class BukkitServiceTest method shouldDispatchConsoleCommand.

@Test
public void shouldDispatchConsoleCommand() {
    // given
    ConsoleCommandSender consoleSender = mock(ConsoleCommandSender.class);
    given(server.getConsoleSender()).willReturn(consoleSender);
    String command = "my command";
    // when
    bukkitService.dispatchConsoleCommand(command);
    // then
    verify(server).dispatchCommand(consoleSender, command);
}
Also used : ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Test(org.junit.Test)

Example 2 with ConsoleCommandSender

use of org.bukkit.command.ConsoleCommandSender in project EliteMobs by MagmaGuy.

the class StatsCommandHandler method statsHandler.

public void statsHandler(CommandSender commandSender) {
    int mobLevelSavingsCount = 0;
    int totalMobCount = 0;
    int aggressiveCount = 0;
    int passiveCount = 0;
    int blazeCount = 0;
    int caveSpiderCount = 0;
    int creeperCount = 0;
    int endermanCount = 0;
    int endermiteCount = 0;
    int huskCount = 0;
    int ironGolemCount = 0;
    int pigZombieCount = 0;
    int polarBearCount = 0;
    int silverfishCount = 0;
    int skeletonCount = 0;
    int spiderCount = 0;
    int strayCount = 0;
    int witchCount = 0;
    int witherSkeletonCount = 0;
    int zombieCount = 0;
    int zombieVillagerCount = 0;
    int chickenCount = 0;
    int cowCount = 0;
    int mushroomCowCount = 0;
    int pigCount = 0;
    int sheepCount = 0;
    for (World world : worldList) {
        for (LivingEntity livingEntity : world.getLivingEntities()) {
            if (livingEntity.hasMetadata(MetadataHandler.ELITE_MOB_MD) || livingEntity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
                totalMobCount++;
                if (livingEntity.hasMetadata(MetadataHandler.ELITE_MOB_MD)) {
                    mobLevelSavingsCount += livingEntity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
                    aggressiveCount++;
                    switch(livingEntity.getType()) {
                        case ZOMBIE:
                            zombieCount++;
                            break;
                        case HUSK:
                            huskCount++;
                            break;
                        case ZOMBIE_VILLAGER:
                            zombieVillagerCount++;
                            break;
                        case SKELETON:
                            skeletonCount++;
                            break;
                        case WITHER_SKELETON:
                            witherSkeletonCount++;
                            break;
                        case STRAY:
                            strayCount++;
                            break;
                        case PIG_ZOMBIE:
                            pigZombieCount++;
                            break;
                        case CREEPER:
                            creeperCount++;
                            break;
                        case SPIDER:
                            spiderCount++;
                            break;
                        case ENDERMAN:
                            endermanCount++;
                            break;
                        case CAVE_SPIDER:
                            caveSpiderCount++;
                            break;
                        case SILVERFISH:
                            silverfishCount++;
                            break;
                        case BLAZE:
                            blazeCount++;
                            break;
                        case WITCH:
                            witchCount++;
                            break;
                        case ENDERMITE:
                            endermiteCount++;
                            break;
                        case POLAR_BEAR:
                            polarBearCount++;
                            break;
                        case IRON_GOLEM:
                            ironGolemCount++;
                            break;
                        default:
                            getLogger().info("Error: Couldn't assign custom mob name due to unexpected aggressive boss mob (talk to the dev!)");
                            getLogger().info("Missing mob type: " + livingEntity.getType());
                            break;
                    }
                } else if (livingEntity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
                    //passive EliteMobs only stack at 50 right now
                    //TODO: redo this count at some other stage of this plugin's development
                    mobLevelSavingsCount += ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount");
                    passiveCount++;
                    switch(livingEntity.getType()) {
                        case CHICKEN:
                            chickenCount++;
                            break;
                        case COW:
                            cowCount++;
                            break;
                        case MUSHROOM_COW:
                            mushroomCowCount++;
                            break;
                        case PIG:
                            pigCount++;
                            break;
                        case SHEEP:
                            sheepCount++;
                            break;
                        default:
                            getLogger().info("Error: Couldn't assign custom mob name due to unexpected passive boss mob (talk to the dev!)");
                            getLogger().info("Missing mob type: " + livingEntity.getType());
                            break;
                    }
                }
            }
        }
    }
    if (commandSender instanceof Player) {
        Player player = (Player) commandSender;
        player.sendMessage("§5§m-----------------------------------------------------");
        player.sendMessage("§a§lEliteMobs stats:");
        player.sendMessage("There are currently §l§6" + totalMobCount + " §f§rEliteMobs replacing §l§e" + mobLevelSavingsCount + " §f§rregular mobs.");
        if (aggressiveCount > 0) {
            String aggressiveCountMessage = "§c" + aggressiveCount + " §4Aggressive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, blazeCount, "blazes");
            unsortedMobCountFilter(unsortedMobCount, caveSpiderCount, "cave spiders");
            unsortedMobCountFilter(unsortedMobCount, creeperCount, "creepers");
            unsortedMobCountFilter(unsortedMobCount, endermanCount, "endermen");
            unsortedMobCountFilter(unsortedMobCount, endermiteCount, "endermites");
            unsortedMobCountFilter(unsortedMobCount, huskCount, "husks");
            unsortedMobCountFilter(unsortedMobCount, pigZombieCount, "zombiepigmen");
            unsortedMobCountFilter(unsortedMobCount, polarBearCount, "polar bears");
            unsortedMobCountFilter(unsortedMobCount, silverfishCount, "silverfish");
            unsortedMobCountFilter(unsortedMobCount, skeletonCount, "skeletons");
            unsortedMobCountFilter(unsortedMobCount, spiderCount, "spiders");
            unsortedMobCountFilter(unsortedMobCount, strayCount, "strays");
            unsortedMobCountFilter(unsortedMobCount, witchCount, "witches");
            unsortedMobCountFilter(unsortedMobCount, witherSkeletonCount, "wither skeletons");
            unsortedMobCountFilter(unsortedMobCount, zombieCount, "zombie");
            unsortedMobCountFilter(unsortedMobCount, zombieVillagerCount, "zombie villagers");
            player.sendMessage(messageStringAppender(aggressiveCountMessage, unsortedMobCount));
        }
        if (passiveCount > 0) {
            String passiveCountMessage = "§b" + passiveCount + " §3Passive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, chickenCount, "chickens");
            unsortedMobCountFilter(unsortedMobCount, cowCount, "cows");
            unsortedMobCountFilter(unsortedMobCount, ironGolemCount, "iron golems");
            unsortedMobCountFilter(unsortedMobCount, mushroomCowCount, "mushroom cows");
            unsortedMobCountFilter(unsortedMobCount, pigCount, "pigs");
            unsortedMobCountFilter(unsortedMobCount, sheepCount, "sheep");
            player.sendMessage(messageStringAppender(passiveCountMessage, unsortedMobCount));
        }
        player.sendMessage("§5§m-----------------------------------------------------");
    } else if (commandSender instanceof ConsoleCommandSender) {
        getServer().getConsoleSender().sendMessage("§5§m-------------------------------------------------------------");
        getServer().getConsoleSender().sendMessage("§a§lEliteMobs stats:");
        getServer().getConsoleSender().sendMessage("There are currently §l§6" + totalMobCount + " §f§rEliteMobs replacing §l§e" + mobLevelSavingsCount + " §f§rregular mobs.");
        if (aggressiveCount > 0) {
            String aggressiveCountMessage = "§c" + aggressiveCount + " §4Aggressive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, blazeCount, "blazes");
            unsortedMobCountFilter(unsortedMobCount, caveSpiderCount, "cave spiders");
            unsortedMobCountFilter(unsortedMobCount, creeperCount, "creepers");
            unsortedMobCountFilter(unsortedMobCount, endermanCount, "endermen");
            unsortedMobCountFilter(unsortedMobCount, endermiteCount, "endermites");
            unsortedMobCountFilter(unsortedMobCount, huskCount, "husks");
            unsortedMobCountFilter(unsortedMobCount, ironGolemCount, "iron golems");
            unsortedMobCountFilter(unsortedMobCount, pigZombieCount, "zombiepigmen");
            unsortedMobCountFilter(unsortedMobCount, polarBearCount, "polar bears");
            unsortedMobCountFilter(unsortedMobCount, silverfishCount, "silverfish");
            unsortedMobCountFilter(unsortedMobCount, skeletonCount, "skeletons");
            unsortedMobCountFilter(unsortedMobCount, spiderCount, "spiders");
            unsortedMobCountFilter(unsortedMobCount, strayCount, "strays");
            unsortedMobCountFilter(unsortedMobCount, witchCount, "witches");
            unsortedMobCountFilter(unsortedMobCount, witherSkeletonCount, "wither skeletons");
            unsortedMobCountFilter(unsortedMobCount, zombieCount, "zombie");
            unsortedMobCountFilter(unsortedMobCount, zombieVillagerCount, "zombie villagers");
            getServer().getConsoleSender().sendMessage(messageStringAppender(aggressiveCountMessage, unsortedMobCount));
        }
        if (passiveCount > 0) {
            String passiveCountMessage = "§b" + passiveCount + " §3Passive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, chickenCount, "chickens");
            unsortedMobCountFilter(unsortedMobCount, cowCount, "cows");
            unsortedMobCountFilter(unsortedMobCount, mushroomCowCount, "mushroom cows");
            unsortedMobCountFilter(unsortedMobCount, pigCount, "pigs");
            unsortedMobCountFilter(unsortedMobCount, sheepCount, "sheep");
            getServer().getConsoleSender().sendMessage(messageStringAppender(passiveCountMessage, unsortedMobCount));
        }
        getServer().getConsoleSender().sendMessage("§5§m-------------------------------------------------------------");
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) World(org.bukkit.World) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 3 with ConsoleCommandSender

use of org.bukkit.command.ConsoleCommandSender in project EliteMobs by MagmaGuy.

the class CommandHandler method validCommands.

private void validCommands(CommandSender commandSender) {
    if (commandSender instanceof Player) {
        Player player = (Player) commandSender;
        player.sendMessage("Valid commands:");
        player.sendMessage("/elitemobs stats");
        player.sendMessage("/elitemobs reload configs");
        player.sendMessage("/elitemobs reload loot");
        player.sendMessage("/elitemobs getloot (alone to get GUI)");
        player.sendMessage("/elitemobs getloot [loot name]");
        player.sendMessage("/elitemobs giveloot [player name] random/[loot_name_underscore_for_spaces]");
        player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower2(keep adding as many as you'd like)]");
    } else if (commandSender instanceof ConsoleCommandSender) {
        getLogger().info("Command not recognized. Valid commands:");
        getLogger().info("elitemobs stats");
        getLogger().info("elitemobs reload configs");
        getLogger().info("elitemobs reload loot");
        getLogger().info("elitemobs giveloot [player name] random/[loot_name_underscore_for_spaces]");
        getLogger().info("elitemobs SpawnMob [worldName] [x] [y] [z] [mobType] [mobLevel] [mobPower] [mobPower2(keep adding as many as you'd like)]");
    }
}
Also used : Player(org.bukkit.entity.Player) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 4 with ConsoleCommandSender

use of org.bukkit.command.ConsoleCommandSender in project Bukkit by Bukkit.

the class HelpCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    String command;
    int pageNumber;
    int pageHeight;
    int pageWidth;
    if (args.length == 0) {
        command = "";
        pageNumber = 1;
    } else if (NumberUtils.isDigits(args[args.length - 1])) {
        command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " ");
        try {
            pageNumber = NumberUtils.createInteger(args[args.length - 1]);
        } catch (NumberFormatException exception) {
            pageNumber = 1;
        }
        if (pageNumber <= 0) {
            pageNumber = 1;
        }
    } else {
        command = StringUtils.join(args, " ");
        pageNumber = 1;
    }
    if (sender instanceof ConsoleCommandSender) {
        pageHeight = ChatPaginator.UNBOUNDED_PAGE_HEIGHT;
        pageWidth = ChatPaginator.UNBOUNDED_PAGE_WIDTH;
    } else {
        pageHeight = ChatPaginator.CLOSED_CHAT_PAGE_HEIGHT - 1;
        pageWidth = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH;
    }
    HelpMap helpMap = Bukkit.getServer().getHelpMap();
    HelpTopic topic = helpMap.getHelpTopic(command);
    if (topic == null) {
        topic = helpMap.getHelpTopic("/" + command);
    }
    if (topic == null) {
        topic = findPossibleMatches(command);
    }
    if (topic == null || !topic.canSee(sender)) {
        sender.sendMessage(ChatColor.RED + "No help for " + command);
        return true;
    }
    ChatPaginator.ChatPage page = ChatPaginator.paginate(topic.getFullText(sender), pageNumber, pageWidth, pageHeight);
    StringBuilder header = new StringBuilder();
    header.append(ChatColor.YELLOW);
    header.append("--------- ");
    header.append(ChatColor.WHITE);
    header.append("Help: ");
    header.append(topic.getName());
    header.append(" ");
    if (page.getTotalPages() > 1) {
        header.append("(");
        header.append(page.getPageNumber());
        header.append("/");
        header.append(page.getTotalPages());
        header.append(") ");
    }
    header.append(ChatColor.YELLOW);
    for (int i = header.length(); i < ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH; i++) {
        header.append("-");
    }
    sender.sendMessage(header.toString());
    sender.sendMessage(page.getLines());
    return true;
}
Also used : HelpTopic(org.bukkit.help.HelpTopic) IndexHelpTopic(org.bukkit.help.IndexHelpTopic) HelpMap(org.bukkit.help.HelpMap) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ChatPaginator(org.bukkit.util.ChatPaginator)

Example 5 with ConsoleCommandSender

use of org.bukkit.command.ConsoleCommandSender in project Denizen-For-Bukkit by DenizenScript.

the class CommandManager method executeMethod.

// Attempt to execute a command.
private void executeMethod(String[] args, CommandSender sender, Object[] methodArgs) throws CommandException {
    String cmdName = CoreUtilities.toLowerCase(args[0]);
    String modifier = args.length > 1 ? args[1] : "";
    boolean help = CoreUtilities.toLowerCase(modifier).equals("help");
    Method method = commands.get(cmdName + " " + CoreUtilities.toLowerCase(modifier));
    if (method == null && !help) {
        method = commands.get(cmdName + " *");
    }
    if (method == null && help) {
        executeHelp(args, sender);
        return;
    }
    if (method == null) {
        throw new UnhandledCommandException();
    }
    if (!serverCommands.contains(method) && sender instanceof ConsoleCommandSender) {
        throw new ServerCommandException();
    }
    if (!hasPermission(method, sender)) {
        throw new NoPermissionsException();
    }
    Command cmd = method.getAnnotation(Command.class);
    CommandContext context = new CommandContext(sender, args);
    if (context.argsLength() < cmd.min()) {
        throw new CommandUsageException("Too few arguments.", getUsage(args, cmd));
    }
    if (cmd.max() != -1 && context.argsLength() > cmd.max()) {
        throw new CommandUsageException("Too many arguments.", getUsage(args, cmd));
    }
    if (!cmd.flags().contains("*")) {
        for (char flag : context.getFlags()) {
            if (cmd.flags().indexOf(String.valueOf(flag)) == -1) {
                throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, cmd));
            }
        }
    }
    methodArgs[0] = context;
    for (Annotation annotation : registeredAnnotations.get(method)) {
        CommandAnnotationProcessor processor = annotationProcessors.get(annotation.annotationType());
        processor.process(sender, context, annotation, methodArgs);
    }
    Object instance = instances.get(method);
    try {
        method.invoke(instance, methodArgs);
    } catch (IllegalArgumentException e) {
        dB.echoError(e);
    } catch (IllegalAccessException e) {
        dB.echoError(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CommandException) {
            throw (CommandException) e.getCause();
        }
        throw new WrappedCommandException(e.getCause());
    }
}
Also used : Method(java.lang.reflect.Method) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)10 Player (org.bukkit.entity.Player)5 World (org.bukkit.World)3 ArrayList (java.util.ArrayList)2 Location (org.bukkit.Location)2 BlockCommandSender (org.bukkit.command.BlockCommandSender)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Test (org.junit.Test)2 com.cypherx.xauth.xAuthPlayer (com.cypherx.xauth.xAuthPlayer)1 MetadataHandler (com.magmaguy.elitemobs.MetadataHandler)1 LootCustomConfig (com.magmaguy.elitemobs.config.LootCustomConfig)1 EliteDropsHandler (com.magmaguy.elitemobs.elitedrops.EliteDropsHandler)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 GlowEntity (net.glowstone.entity.GlowEntity)1 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)1