Search in sources :

Example 1 with MetadataHandler

use of com.magmaguy.elitemobs.MetadataHandler in project EliteMobs by MagmaGuy.

the class MobPowersCustomConfig method initializeMobPowersConfig.

public void initializeMobPowersConfig() {
    MetadataHandler metadataHandler = new MetadataHandler();
    for (String string : metadataHandler.minorPowerList()) {
        this.getMobPowersConfig().addDefault("Powers.Minor Powers." + string, true);
    }
    for (String string : metadataHandler.majorPowerList()) {
        this.getMobPowersConfig().addDefault("Powers.Major Powers." + string, true);
    }
    getMobPowersConfig().options().copyDefaults(true);
    saveDefaultCustomConfig();
    saveCustomConfig();
}
Also used : MetadataHandler(com.magmaguy.elitemobs.MetadataHandler)

Example 2 with MetadataHandler

use of com.magmaguy.elitemobs.MetadataHandler in project EliteMobs by MagmaGuy.

the class ScoreboardHandler method aggressiveEliteMobScoreboard.

public void aggressiveEliteMobScoreboard(Entity entity, Player player) {
    processID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

        int iterator = 0;

        public void run() {
            if (!entity.isValid() || player.getWorld() != entity.getWorld() || player.getLocation().distance(entity.getLocation()) > 7) {
                player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
                playerHasScoreboard.put(player, false);
                Bukkit.getScheduler().cancelTask(processID);
                return;
            }
            MetadataHandler metadataHandler = new MetadataHandler();
            int powerCounter = 0;
            for (String string : MetadataHandler.allPowersList()) {
                if (entity.hasMetadata(string)) {
                    powerCounter++;
                }
            }
            ScoreboardManager scoreboardManager = Bukkit.getScoreboardManager();
            Scoreboard board = scoreboardManager.getNewScoreboard();
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(entity.getName());
            int currentHealth = (int) ((LivingEntity) entity).getHealth();
            int maxHealth = (int) ((LivingEntity) entity).getMaxHealth();
            int counter = 0;
            for (String string : MetadataHandler.allPowersList()) {
                if (entity.hasMetadata(string)) {
                    String finalString = metadataHandler.machineToHumanTranslator(string);
                    if (powerCounter > 13) {
                        Score score = null;
                        if (MetadataHandler.minorPowerList().contains(string)) {
                            score = objective.getScore(ChatColor.AQUA + finalString);
                        } else if (MetadataHandler.majorPowerList().contains(string)) {
                            score = objective.getScore(ChatColor.DARK_AQUA + finalString);
                        }
                        if (counter + iterator < powerCounter) {
                            score.setScore(counter + iterator);
                        } else {
                            int currentValue = (int) ((counter + iterator) - Math.floor(((counter + iterator) / powerCounter) * powerCounter));
                            score.setScore(currentValue);
                        }
                    } else {
                        Score score;
                        if (MetadataHandler.minorPowerList().contains(string)) {
                            score = objective.getScore(ChatColor.AQUA + finalString);
                        } else {
                            score = objective.getScore(ChatColor.DARK_AQUA + finalString);
                        }
                        score.setScore(counter);
                    }
                    counter++;
                }
            }
            player.setScoreboard(board);
            playerHasScoreboard.put(player, true);
            Score healthScore = objective.getScore(String.format("%s%s", ChatColor.DARK_RED, ChatColor.BOLD) + ConfigValues.translationConfig.getString("ScoreBoard.Health") + ChatColor.RED + currentHealth + ChatColor.DARK_RED + "/" + ChatColor.RED + maxHealth);
            healthScore.setScore(powerCounter);
            iterator++;
        }
    }, 4, 4);
}
Also used : MetadataHandler(com.magmaguy.elitemobs.MetadataHandler)

Example 3 with MetadataHandler

use of com.magmaguy.elitemobs.MetadataHandler in project EliteMobs by MagmaGuy.

the class SpawnMobCommandHandler method spawnMob.

public void spawnMob(CommandSender commandSender, String[] args) {
    World world = null;
    Location location = null;
    String entityInput = null;
    int mobLevel = 0;
    List<String> mobPower = new ArrayList<>();
    if (commandSender instanceof Player) {
        Player player = (Player) commandSender;
        if (args.length == 1) {
            player.sendMessage("Valid command syntax:");
            player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these mobPowers as many as you'd like)]");
        }
        world = player.getWorld();
        location = player.getTargetBlock((HashSet<Byte>) null, 30).getLocation().add(0, 1, 0);
        entityInput = args[1].toLowerCase();
        if (args.length > 2) {
            try {
                mobLevel = Integer.valueOf(args[2]);
            } catch (NumberFormatException ex) {
                player.sendMessage("Not a valid level.");
                player.sendMessage("Valid command syntax:");
                player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these mobPowers as many as you'd like)]");
            }
        }
        if (args.length > 3) {
            int index = 0;
            for (String arg : args) {
                //mob powers start after arg 2
                if (index > 2) {
                    mobPower.add(arg);
                }
                index++;
            }
        }
    } else if (commandSender instanceof ConsoleCommandSender || commandSender instanceof BlockCommandSender) {
        for (World worldIterator : worldList) {
            //find world
            if (worldIterator.getName().equals(args[1])) {
                world = worldIterator;
                //find x coord
                try {
                    double xCoord = Double.parseDouble(args[2]);
                    double yCoord = Double.parseDouble(args[3]);
                    double zCoord = Double.parseDouble(args[4]);
                    location = new Location(worldIterator, xCoord, yCoord, zCoord);
                    entityInput = args[5].toLowerCase();
                    break;
                } catch (NumberFormatException ex) {
                    getConsoleSender().sendMessage("At least one of the coordinates (x:" + args[2] + ", y:" + args[3] + ", z:" + args[4] + ") is not valid");
                    getConsoleSender().sendMessage("Valid command syntax: /elitemobs SpawnMob worldName xCoord yCoord " + "zCoord mobType mobLevel mobPower mobPower(you can keep adding these mobPowers as many as you'd like)");
                }
                if (args.length > 6) {
                    int index = 0;
                    for (String arg : args) {
                        //mob powers start after arg 2
                        if (index > 2) {
                            mobPower.add(arg);
                        }
                        index++;
                    }
                }
            }
        }
        if (world == null) {
            getConsoleSender().sendMessage("World " + args[1] + "not found. Valid command syntax: /elitemobs SpawnMob" + " [worldName] [xCoord] [yCoord] [zCoord] [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these " + "mobPowers as many as you'd like)]");
        }
    }
    EntityType entityType = null;
    switch(entityInput) {
        case "blaze":
            entityType = EntityType.BLAZE;
            break;
        case "cavespider":
            entityType = EntityType.CAVE_SPIDER;
            break;
        case "creeper":
            entityType = EntityType.CREEPER;
            break;
        case "enderman":
            entityType = EntityType.ENDERMAN;
            break;
        case "endermite":
            entityType = EntityType.ENDERMITE;
            break;
        case "husk":
            entityType = EntityType.HUSK;
            break;
        case "irongolem":
            entityType = EntityType.IRON_GOLEM;
            break;
        case "pigzombie":
            entityType = EntityType.PIG_ZOMBIE;
            break;
        case "polarbear":
            entityType = EntityType.POLAR_BEAR;
            break;
        case "silverfish":
            entityType = EntityType.SILVERFISH;
            break;
        case "skeleton":
            entityType = EntityType.SKELETON;
            break;
        case "spider":
            entityType = EntityType.SPIDER;
            break;
        case "stray":
            entityType = EntityType.STRAY;
            break;
        case "witch":
            entityType = EntityType.WITCH;
            break;
        case "witherskeleton":
            entityType = EntityType.WITHER_SKELETON;
            break;
        case "zombie":
            entityType = EntityType.ZOMBIE;
            break;
        case "chicken":
            entityType = EntityType.CHICKEN;
            break;
        case "cow":
            entityType = EntityType.COW;
            break;
        case "mushroomcow":
            entityType = EntityType.MUSHROOM_COW;
            break;
        case "pig":
            entityType = EntityType.PIG;
            break;
        case "sheep":
            entityType = EntityType.SHEEP;
            break;
        default:
            if (commandSender instanceof Player) {
                ((Player) commandSender).getPlayer().sendTitle("Could not spawn mob type " + entityInput, "If this is incorrect, please contact the dev.");
            } else if (commandSender instanceof ConsoleCommandSender) {
                getConsoleSender().sendMessage("Could not spawn mob type " + entityInput + ". If this is incorrect, " + "please contact the dev.");
            }
            break;
    }
    Entity entity = null;
    if (entityType != null) {
        entity = world.spawnEntity(location, entityType);
    }
    if (entityType == EntityType.CHICKEN || entityType == EntityType.COW || entityType == EntityType.MUSHROOM_COW || entityType == EntityType.PIG || entityType == EntityType.SHEEP) {
        HealthHandler.passiveHealthHandler(entity, ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount"));
        NameHandler.customPassiveName(entity, plugin);
        return;
    }
    if (mobLevel > 0) {
        entity.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, mobLevel));
    }
    if (mobPower.size() > 0) {
        boolean inputError = false;
        int powerCount = 0;
        MetadataHandler metadataHandler = new MetadataHandler();
        for (String string : mobPower) {
            switch(string) {
                //major powers
                case MetadataHandler.ZOMBIE_FRIENDS_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_FRIENDS_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                case MetadataHandler.ZOMBIE_NECRONOMICON_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_NECRONOMICON_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                case MetadataHandler.ZOMBIE_TEAM_ROCKET_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_TEAM_ROCKET_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                case MetadataHandler.ZOMBIE_PARENTS_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_PARENTS_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                //minor powers
                case MetadataHandler.ATTACK_ARROW_H:
                    entity.setMetadata(MetadataHandler.ATTACK_ARROW_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_BLINDING_H:
                    entity.setMetadata(MetadataHandler.ATTACK_BLINDING_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_CONFUSING_H:
                    entity.setMetadata(MetadataHandler.ATTACK_CONFUSING_MD, new FixedMetadataValue(plugin, true));
                    //                        minorPowerPowerStance.attackConfusing(entity);
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_FIRE_H:
                    entity.setMetadata(MetadataHandler.ATTACK_FIRE_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_FIREBALL_H:
                    entity.setMetadata(MetadataHandler.ATTACK_FIREBALL_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_FREEZE_H:
                    entity.setMetadata(MetadataHandler.ATTACK_FREEZE_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_GRAVITY_H:
                    entity.setMetadata(MetadataHandler.ATTACK_GRAVITY_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_POISON_H:
                    entity.setMetadata(MetadataHandler.ATTACK_POISON_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_PUSH_H:
                    entity.setMetadata(MetadataHandler.ATTACK_PUSH_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_WEAKNESS_H:
                    entity.setMetadata(MetadataHandler.ATTACK_WEAKNESS_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_WEB_H:
                    entity.setMetadata(MetadataHandler.ATTACK_WEB_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_WITHER_H:
                    entity.setMetadata(MetadataHandler.ATTACK_WITHER_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.BONUS_LOOT_H:
                    entity.setMetadata(MetadataHandler.BONUS_LOOT_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.DOUBLE_DAMAGE_H:
                    if (!(entity instanceof IronGolem)) {
                        entity.setMetadata(MetadataHandler.DOUBLE_DAMAGE_MD, new FixedMetadataValue(plugin, true));
                    }
                    powerCount++;
                    break;
                case MetadataHandler.DOUBLE_HEALTH_H:
                    if (!(entity instanceof IronGolem)) {
                        entity.setMetadata(MetadataHandler.DOUBLE_HEALTH_MD, new FixedMetadataValue(plugin, true));
                    }
                    powerCount++;
                    break;
                case MetadataHandler.INVISIBILITY_H:
                    entity.setMetadata(MetadataHandler.INVISIBILITY_MD, new FixedMetadataValue(plugin, true));
                    ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_ARROW_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_ARROW_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_FALL_DAMAGE_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_FALL_DAMAGE_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_FIRE_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_FIRE_MD, new FixedMetadataValue(plugin, true));
                    //                        minorPowerPowerStance.invulnerabilityFireEffect(entity);
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_KNOCKBACK_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_KNOCKBACK_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.MOVEMENT_SPEED_H:
                    entity.setMetadata(MetadataHandler.MOVEMENT_SPEED_MD, new FixedMetadataValue(plugin, true));
                    ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
                    powerCount++;
                    break;
                case MetadataHandler.TAUNT_H:
                    entity.setMetadata(MetadataHandler.TAUNT_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case "custom":
                    entity.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                default:
                    if (commandSender instanceof Player) {
                        Player player = (Player) commandSender;
                        player.sendMessage(string + " is not a valid power.");
                    } else if (commandSender instanceof ConsoleCommandSender) {
                        getConsoleSender().sendMessage(string + " is not a valid power.");
                    }
                    inputError = true;
            }
        }
        entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, powerCount));
        minorPowerPowerStance.itemEffect(entity);
        majorPowerPowerStance.itemEffect(entity);
        if (inputError) {
            if (commandSender instanceof Player) {
                Player player = (Player) commandSender;
                player.sendMessage("Valid powers: " + MetadataHandler.powerListHumanFormat() + " custom");
            } else if (commandSender instanceof ConsoleCommandSender) {
                getConsoleSender().sendMessage("Valid powers: " + MetadataHandler.powerListHumanFormat() + MetadataHandler.majorPowerList() + " custom");
            }
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MetadataHandler(com.magmaguy.elitemobs.MetadataHandler) World(org.bukkit.World) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Location(org.bukkit.Location) HashSet(java.util.HashSet) BlockCommandSender(org.bukkit.command.BlockCommandSender)

Aggregations

MetadataHandler (com.magmaguy.elitemobs.MetadataHandler)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 BlockCommandSender (org.bukkit.command.BlockCommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1 PotionEffect (org.bukkit.potion.PotionEffect)1