Search in sources :

Example 1 with Spellcaster

use of org.bukkit.entity.Spellcaster in project CoreProtect by PlayPro.

the class EntityUtil method spawnEntity.

public static void spawnEntity(final BlockState block, final EntityType type, final List<Object> list) {
    if (type == null) {
        return;
    }
    Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
        try {
            Location location = block.getLocation();
            location.setX(location.getX() + 0.50);
            location.setZ(location.getZ() + 0.50);
            Entity entity = block.getLocation().getWorld().spawnEntity(location, type);
            if (list.isEmpty()) {
                return;
            }
            @SuppressWarnings("unchecked") List<Object> age = (List<Object>) list.get(0);
            @SuppressWarnings("unchecked") List<Object> tame = (List<Object>) list.get(1);
            @SuppressWarnings("unchecked") List<Object> data = (List<Object>) list.get(2);
            if (list.size() >= 5) {
                entity.setCustomNameVisible((Boolean) list.get(3));
                entity.setCustomName((String) list.get(4));
            }
            int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
            int wid = Util.getWorldId(block.getWorld().getName());
            String token = "" + block.getX() + "." + block.getY() + "." + block.getZ() + "." + wid + "." + type.name() + "";
            CacheHandler.entityCache.put(token, new Object[] { unixtimestamp, entity.getEntityId() });
            if (entity instanceof Ageable) {
                int count = 0;
                Ageable ageable = (Ageable) entity;
                for (Object value : age) {
                    if (count == 0) {
                        int set = (Integer) value;
                        ageable.setAge(set);
                    } else if (count == 1) {
                        boolean set = (Boolean) value;
                        ageable.setAgeLock(set);
                    } else if (count == 2) {
                        boolean set = (Boolean) value;
                        if (set) {
                            ageable.setAdult();
                        } else {
                            ageable.setBaby();
                        }
                    } else if (count == 3) {
                        boolean set = (Boolean) value;
                        ageable.setBreed(set);
                    } else if (count == 4 && value != null) {
                        // deprecated
                        double set = (Double) value;
                        ageable.setMaxHealth(set);
                    }
                    count++;
                }
            }
            if (entity instanceof Tameable) {
                int count = 0;
                Tameable tameable = (Tameable) entity;
                for (Object value : tame) {
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        tameable.setTamed(set);
                    } else if (count == 1) {
                        String set = (String) value;
                        if (set.length() > 0) {
                            Player owner = Bukkit.getServer().getPlayer(set);
                            if (owner == null) {
                                OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(set);
                                if (offlinePlayer != null) {
                                    tameable.setOwner(offlinePlayer);
                                }
                            } else {
                                tameable.setOwner(owner);
                            }
                        }
                    }
                    count++;
                }
            }
            if (entity instanceof Attributable && list.size() >= 6) {
                Attributable attributable = (Attributable) entity;
                @SuppressWarnings("unchecked") List<Object> attributes = (List<Object>) list.get(5);
                for (Object value : attributes) {
                    @SuppressWarnings("unchecked") List<Object> attributeData = (List<Object>) value;
                    Attribute attribute = (Attribute) attributeData.get(0);
                    Double baseValue = (Double) attributeData.get(1);
                    @SuppressWarnings("unchecked") List<Object> attributeModifiers = (List<Object>) attributeData.get(2);
                    AttributeInstance entityAttribute = attributable.getAttribute(attribute);
                    if (entityAttribute != null) {
                        entityAttribute.setBaseValue(baseValue);
                        for (AttributeModifier modifier : entityAttribute.getModifiers()) {
                            entityAttribute.removeModifier(modifier);
                        }
                        for (Object modifier : attributeModifiers) {
                            @SuppressWarnings("unchecked") Map<String, Object> serializedModifier = (Map<String, Object>) modifier;
                            entityAttribute.addModifier(AttributeModifier.deserialize(serializedModifier));
                        }
                    }
                }
            }
            if (entity instanceof LivingEntity && list.size() >= 7) {
                LivingEntity livingEntity = (LivingEntity) entity;
                @SuppressWarnings("unchecked") List<Object> details = (List<Object>) list.get(6);
                int count = 0;
                for (Object value : details) {
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        livingEntity.setRemoveWhenFarAway(set);
                    } else if (count == 1) {
                        boolean set = (Boolean) value;
                        livingEntity.setCanPickupItems(set);
                    }
                    count++;
                }
            }
            int count = 0;
            for (Object value : data) {
                if (entity instanceof Creeper) {
                    Creeper creeper = (Creeper) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        creeper.setPowered(set);
                    }
                } else if (entity instanceof Enderman) {
                    Enderman enderman = (Enderman) entity;
                    if (count == 1) {
                        String blockDataString = (String) value;
                        BlockData blockData = Bukkit.getServer().createBlockData(blockDataString);
                        enderman.setCarriedBlock(blockData);
                    }
                } else if (entity instanceof IronGolem) {
                    IronGolem irongolem = (IronGolem) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        irongolem.setPlayerCreated(set);
                    }
                } else if (entity instanceof Cat) {
                    Cat cat = (Cat) entity;
                    if (count == 0) {
                        Cat.Type set = (Cat.Type) value;
                        cat.setCatType(set);
                    } else if (count == 1) {
                        DyeColor set = (DyeColor) value;
                        cat.setCollarColor(set);
                    }
                } else if (entity instanceof Fox) {
                    Fox fox = (Fox) entity;
                    if (count == 0) {
                        Fox.Type set = (Fox.Type) value;
                        fox.setFoxType(set);
                    } else if (count == 1) {
                        boolean set = (Boolean) value;
                        fox.setSitting(set);
                    }
                } else if (entity instanceof Panda) {
                    Panda panda = (Panda) entity;
                    if (count == 0) {
                        Gene set = (Gene) value;
                        panda.setMainGene(set);
                    } else if (count == 1) {
                        Gene set = (Gene) value;
                        panda.setHiddenGene(set);
                    }
                } else if (entity instanceof Pig) {
                    Pig pig = (Pig) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        pig.setSaddle(set);
                    }
                } else if (entity instanceof Sheep) {
                    Sheep sheep = (Sheep) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        sheep.setSheared(set);
                    } else if (count == 1) {
                        DyeColor set = (DyeColor) value;
                        sheep.setColor(set);
                    }
                } else if (entity instanceof MushroomCow) {
                    MushroomCow mushroomCow = (MushroomCow) entity;
                    if (count == 0) {
                        MushroomCow.Variant set = (MushroomCow.Variant) value;
                        mushroomCow.setVariant(set);
                    }
                } else if (entity instanceof Slime) {
                    Slime slime = (Slime) entity;
                    if (count == 0) {
                        int set = (Integer) value;
                        slime.setSize(set);
                    }
                } else if (entity instanceof Parrot) {
                    Parrot parrot = (Parrot) entity;
                    if (count == 0) {
                        Variant set = (Variant) value;
                        parrot.setVariant(set);
                    }
                } else if (entity instanceof TropicalFish) {
                    TropicalFish tropicalFish = (TropicalFish) entity;
                    if (count == 0) {
                        DyeColor set = (DyeColor) value;
                        tropicalFish.setBodyColor(set);
                    } else if (count == 1) {
                        TropicalFish.Pattern set = (TropicalFish.Pattern) value;
                        tropicalFish.setPattern(set);
                    } else if (count == 2) {
                        DyeColor set = (DyeColor) value;
                        tropicalFish.setPatternColor(set);
                    }
                } else if (entity instanceof Phantom) {
                    Phantom phantom = (Phantom) entity;
                    if (count == 0) {
                        int set = (Integer) value;
                        phantom.setSize(set);
                    }
                } else if (entity instanceof AbstractVillager) {
                    AbstractVillager abstractVillager = (AbstractVillager) entity;
                    if (count == 0) {
                        if (abstractVillager instanceof Villager) {
                            Villager villager = (Villager) abstractVillager;
                            Profession set = (Profession) value;
                            villager.setProfession(set);
                        }
                    } else if (count == 1) {
                        if (abstractVillager instanceof Villager && value instanceof Villager.Type) {
                            Villager villager = (Villager) abstractVillager;
                            Villager.Type set = (Villager.Type) value;
                            villager.setVillagerType(set);
                        }
                    } else if (count == 2) {
                        List<MerchantRecipe> merchantRecipes = new ArrayList<>();
                        @SuppressWarnings("unchecked") List<Object> set = (List<Object>) value;
                        for (Object recipes : set) {
                            @SuppressWarnings("unchecked") List<Object> recipe = (List<Object>) recipes;
                            @SuppressWarnings("unchecked") List<Object> itemMap = (List<Object>) recipe.get(0);
                            @SuppressWarnings("unchecked") ItemStack result = ItemStack.deserialize((Map<String, Object>) itemMap.get(0));
                            @SuppressWarnings("unchecked") List<List<Map<String, Object>>> metadata = (List<List<Map<String, Object>>>) itemMap.get(1);
                            Object[] populatedStack = Rollback.populateItemStack(result, metadata);
                            result = (ItemStack) populatedStack[2];
                            int uses = (int) recipe.get(1);
                            int maxUses = (int) recipe.get(2);
                            boolean experienceReward = (boolean) recipe.get(3);
                            List<ItemStack> merchantIngredients = new ArrayList<>();
                            @SuppressWarnings("unchecked") List<Object> ingredients = (List<Object>) recipe.get(4);
                            for (Object ingredient : ingredients) {
                                @SuppressWarnings("unchecked") List<Object> ingredientMap = (List<Object>) ingredient;
                                @SuppressWarnings("unchecked") ItemStack item = ItemStack.deserialize((Map<String, Object>) ingredientMap.get(0));
                                @SuppressWarnings("unchecked") List<List<Map<String, Object>>> itemMetaData = (List<List<Map<String, Object>>>) ingredientMap.get(1);
                                populatedStack = Rollback.populateItemStack(item, itemMetaData);
                                item = (ItemStack) populatedStack[2];
                                merchantIngredients.add(item);
                            }
                            MerchantRecipe merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward);
                            if (recipe.size() > 6) {
                                int villagerExperience = (int) recipe.get(5);
                                float priceMultiplier = (float) recipe.get(6);
                                merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier);
                            }
                            merchantRecipe.setIngredients(merchantIngredients);
                            merchantRecipes.add(merchantRecipe);
                        }
                        if (!merchantRecipes.isEmpty()) {
                            abstractVillager.setRecipes(merchantRecipes);
                        }
                    } else {
                        Villager villager = (Villager) abstractVillager;
                        if (count == 3) {
                            int set = (int) value;
                            villager.setVillagerLevel(set);
                        } else if (count == 4) {
                            int set = (int) value;
                            villager.setVillagerExperience(set);
                        }
                    }
                } else if (entity instanceof Raider) {
                    Raider raider = (Raider) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        raider.setPatrolLeader(set);
                    }
                    if (entity instanceof Spellcaster && count == 1) {
                        Spellcaster spellcaster = (Spellcaster) entity;
                        Spell set = (Spell) value;
                        spellcaster.setSpell(set);
                    }
                } else if (entity instanceof Wolf) {
                    Wolf wolf = (Wolf) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        wolf.setSitting(set);
                    } else if (count == 1) {
                        DyeColor set = (DyeColor) value;
                        wolf.setCollarColor(set);
                    }
                } else if (entity instanceof ZombieVillager) {
                    ZombieVillager zombieVillager = (ZombieVillager) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        zombieVillager.setBaby(set);
                    } else if (count == 1) {
                        Profession set = (Profession) value;
                        zombieVillager.setVillagerProfession(set);
                    }
                } else if (entity instanceof Zombie) {
                    Zombie zombie = (Zombie) entity;
                    if (count == 0) {
                        boolean set = (Boolean) value;
                        zombie.setBaby(set);
                    }
                } else if (entity instanceof AbstractHorse) {
                    AbstractHorse abstractHorse = (AbstractHorse) entity;
                    if (count == 0 && value != null) {
                        // deprecated
                        boolean set = (Boolean) value;
                        if (entity instanceof ChestedHorse) {
                            ChestedHorse chestedHorse = (ChestedHorse) entity;
                            chestedHorse.setCarryingChest(set);
                        }
                    } else if (count == 1 && value != null) {
                        // deprecated
                        org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
                        if (entity instanceof Horse) {
                            Horse horse = (Horse) entity;
                            horse.setColor(set);
                        }
                    } else if (count == 2) {
                        int set = (Integer) value;
                        abstractHorse.setDomestication(set);
                    } else if (count == 3) {
                        double set = (Double) value;
                        abstractHorse.setJumpStrength(set);
                    } else if (count == 4) {
                        int set = (Integer) value;
                        abstractHorse.setMaxDomestication(set);
                    } else if (count == 5 && value != null) {
                        // deprecated
                        Style set = (Style) value;
                        Horse horse = (Horse) entity;
                        horse.setStyle(set);
                    }
                    if (entity instanceof Horse) {
                        Horse horse = (Horse) entity;
                        if (count == 8) {
                            if (value != null) {
                                @SuppressWarnings("unchecked") ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
                                horse.getInventory().setSaddle(set);
                            }
                        } else if (count == 9) {
                            org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
                            horse.setColor(set);
                        } else if (count == 10) {
                            Style set = (Style) value;
                            horse.setStyle(set);
                        } else if (count == 11) {
                            if (value != null) {
                                @SuppressWarnings("unchecked") ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
                                horse.getInventory().setArmor(set);
                            }
                        } else if (count == 12 && value != null) {
                            @SuppressWarnings("unchecked") org.bukkit.Color set = org.bukkit.Color.deserialize((Map<String, Object>) value);
                            ItemStack armor = horse.getInventory().getArmor();
                            if (armor != null) {
                                ItemMeta itemMeta = armor.getItemMeta();
                                if (itemMeta instanceof LeatherArmorMeta) {
                                    LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
                                    leatherArmorMeta.setColor(set);
                                    armor.setItemMeta(leatherArmorMeta);
                                }
                            }
                        }
                    } else if (entity instanceof ChestedHorse) {
                        if (count == 7) {
                            ChestedHorse chestedHorse = (ChestedHorse) entity;
                            boolean set = (Boolean) value;
                            chestedHorse.setCarryingChest(set);
                        }
                        if (entity instanceof Llama) {
                            Llama llama = (Llama) entity;
                            if (count == 8) {
                                if (value != null) {
                                    @SuppressWarnings("unchecked") ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
                                    llama.getInventory().setDecor(set);
                                }
                            } else if (count == 9) {
                                Llama.Color set = (Llama.Color) value;
                                llama.setColor(set);
                            }
                        }
                    }
                } else {
                    BukkitAdapter.ADAPTER.setEntityMeta(entity, value, count);
                }
                count++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) AbstractHorse(org.bukkit.entity.AbstractHorse) Gene(org.bukkit.entity.Panda.Gene) AbstractHorse(org.bukkit.entity.AbstractHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) Phantom(org.bukkit.entity.Phantom) ZombieVillager(org.bukkit.entity.ZombieVillager) Villager(org.bukkit.entity.Villager) AbstractVillager(org.bukkit.entity.AbstractVillager) OfflinePlayer(org.bukkit.OfflinePlayer) List(java.util.List) ArrayList(java.util.ArrayList) AbstractVillager(org.bukkit.entity.AbstractVillager) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) MushroomCow(org.bukkit.entity.MushroomCow) Raider(org.bukkit.entity.Raider) Zombie(org.bukkit.entity.Zombie) Parrot(org.bukkit.entity.Parrot) DyeColor(org.bukkit.DyeColor) DyeColor(org.bukkit.DyeColor) Fox(org.bukkit.entity.Fox) Panda(org.bukkit.entity.Panda) Variant(org.bukkit.entity.Parrot.Variant) Profession(org.bukkit.entity.Villager.Profession) Enderman(org.bukkit.entity.Enderman) ChestedHorse(org.bukkit.entity.ChestedHorse) Cat(org.bukkit.entity.Cat) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ZombieVillager(org.bukkit.entity.ZombieVillager) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) Attribute(org.bukkit.attribute.Attribute) Creeper(org.bukkit.entity.Creeper) IronGolem(org.bukkit.entity.IronGolem) Ageable(org.bukkit.entity.Ageable) Spell(org.bukkit.entity.Spellcaster.Spell) LivingEntity(org.bukkit.entity.LivingEntity) Attributable(org.bukkit.attribute.Attributable) TropicalFish(org.bukkit.entity.TropicalFish) AttributeInstance(org.bukkit.attribute.AttributeInstance) Spellcaster(org.bukkit.entity.Spellcaster) Style(org.bukkit.entity.Horse.Style) Wolf(org.bukkit.entity.Wolf) BlockData(org.bukkit.block.data.BlockData) ItemMeta(org.bukkit.inventory.meta.ItemMeta) MerchantRecipe(org.bukkit.inventory.MerchantRecipe) Tameable(org.bukkit.entity.Tameable) AttributeModifier(org.bukkit.attribute.AttributeModifier) Slime(org.bukkit.entity.Slime) Pig(org.bukkit.entity.Pig) EntityType(org.bukkit.entity.EntityType) Llama(org.bukkit.entity.Llama) Sheep(org.bukkit.entity.Sheep) Location(org.bukkit.Location)

Example 2 with Spellcaster

use of org.bukkit.entity.Spellcaster in project CoreProtect by PlayPro.

the class EntityDeathListener method logEntityDeath.

protected static void logEntityDeath(LivingEntity entity, String e) {
    if (!Config.getConfig(entity.getWorld()).ENTITY_KILLS) {
        return;
    }
    EntityDamageEvent damage = entity.getLastDamageCause();
    if (damage == null) {
        return;
    }
    boolean isCommand = (damage.getCause() == DamageCause.VOID && entity.getLocation().getBlockY() >= BukkitAdapter.ADAPTER.getMinHeight(entity.getWorld()));
    if (e == null) {
        e = isCommand ? "#command" : "";
    }
    boolean skip = true;
    if (!Config.getConfig(entity.getWorld()).SKIP_GENERIC_DATA || (!(entity instanceof Zombie) && !(entity instanceof Skeleton))) {
        skip = false;
    }
    if (damage instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent attack = (EntityDamageByEntityEvent) damage;
        Entity attacker = attack.getDamager();
        if (attacker instanceof Player) {
            Player player = (Player) attacker;
            e = player.getName();
        } else if (attacker instanceof AbstractArrow) {
            AbstractArrow arrow = (AbstractArrow) attacker;
            ProjectileSource shooter = arrow.getShooter();
            if (shooter instanceof Player) {
                Player player = (Player) shooter;
                e = player.getName();
            } else if (shooter instanceof LivingEntity) {
                EntityType entityType = ((LivingEntity) shooter).getType();
                if (entityType != null) {
                    // Check for MyPet plugin
                    String name = entityType.name().toLowerCase(Locale.ROOT);
                    e = "#" + name;
                }
            }
        } else if (attacker instanceof ThrownPotion) {
            ThrownPotion potion = (ThrownPotion) attacker;
            ProjectileSource shooter = potion.getShooter();
            if (shooter instanceof Player) {
                Player player = (Player) shooter;
                e = player.getName();
            } else if (shooter instanceof LivingEntity) {
                EntityType entityType = ((LivingEntity) shooter).getType();
                if (entityType != null) {
                    // Check for MyPet plugin
                    String name = entityType.name().toLowerCase(Locale.ROOT);
                    e = "#" + name;
                }
            }
        } else if (attacker.getType().name() != null) {
            e = "#" + attacker.getType().name().toLowerCase(Locale.ROOT);
        }
    } else {
        EntityDamageEvent.DamageCause cause = damage.getCause();
        if (cause.equals(EntityDamageEvent.DamageCause.FIRE)) {
            e = "#fire";
        } else if (cause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)) {
            if (!skip) {
                e = "#fire";
            }
        } else if (cause.equals(EntityDamageEvent.DamageCause.LAVA)) {
            e = "#lava";
        } else if (cause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)) {
            e = "#explosion";
        } else if (cause.equals(EntityDamageEvent.DamageCause.MAGIC)) {
            e = "#magic";
        }
    }
    if (entity instanceof ArmorStand) {
        Location entityLocation = entity.getLocation();
        if (!Config.getConfig(entityLocation.getWorld()).ITEM_TRANSACTIONS) {
            entityLocation.setY(entityLocation.getY() + 0.99);
            Block block = entityLocation.getBlock();
            Queue.queueBlockBreak(e, block.getState(), Material.ARMOR_STAND, null, (int) entityLocation.getYaw());
        }
        /*
            else if (isCommand) {
                entityLocation.setY(entityLocation.getY() + 0.99);
                Block block = entityLocation.getBlock();
                Database.containerBreakCheck(e, Material.ARMOR_STAND, entity, null, block.getLocation());
                Queue.queueBlockBreak(e, block.getState(), Material.ARMOR_STAND, null, (int) entityLocation.getYaw());
            }
            */
        return;
    }
    EntityType entity_type = entity.getType();
    if (e.length() == 0) {
        // assume killed self
        if (!skip) {
            if (!(entity instanceof Player) && entity_type.name() != null) {
                // Player player = (Player)entity;
                // e = player.getName();
                e = "#" + entity_type.name().toLowerCase(Locale.ROOT);
            } else if (entity instanceof Player) {
                e = entity.getName();
            }
        }
    }
    if (e.startsWith("#wither")) {
        e = "#wither";
    }
    if (e.startsWith("#enderdragon")) {
        e = "#enderdragon";
    }
    if (e.startsWith("#primedtnt") || e.startsWith("#tnt")) {
        e = "#tnt";
    }
    if (e.startsWith("#lightning")) {
        e = "#lightning";
    }
    if (e.length() > 0) {
        List<Object> data = new ArrayList<>();
        List<Object> age = new ArrayList<>();
        List<Object> tame = new ArrayList<>();
        List<Object> attributes = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        List<Object> info = new ArrayList<>();
        EntityType type = entity_type;
        // Basic LivingEntity attributes
        details.add(entity.getRemoveWhenFarAway());
        details.add(entity.getCanPickupItems());
        if (entity instanceof Ageable) {
            Ageable ageable = (Ageable) entity;
            age.add(ageable.getAge());
            age.add(ageable.getAgeLock());
            age.add(ageable.isAdult());
            age.add(ageable.canBreed());
            age.add(null);
        }
        if (entity instanceof Tameable) {
            Tameable tameable = (Tameable) entity;
            tame.add(tameable.isTamed());
            if (tameable.isTamed()) {
                if (tameable.getOwner() != null) {
                    tame.add(tameable.getOwner().getName());
                }
            }
        }
        if (entity instanceof Attributable) {
            Attributable attributable = entity;
            for (Attribute attribute : Attribute.values()) {
                AttributeInstance attributeInstance = attributable.getAttribute(attribute);
                if (attributeInstance != null) {
                    List<Object> attributeData = new ArrayList<>();
                    List<Object> attributeModifiers = new ArrayList<>();
                    attributeData.add(attributeInstance.getAttribute());
                    attributeData.add(attributeInstance.getBaseValue());
                    for (AttributeModifier modifier : attributeInstance.getModifiers()) {
                        attributeModifiers.add(modifier.serialize());
                    }
                    attributeData.add(attributeModifiers);
                    attributes.add(attributeData);
                }
            }
        }
        if (entity instanceof Creeper) {
            Creeper creeper = (Creeper) entity;
            info.add(creeper.isPowered());
        } else if (entity instanceof Enderman) {
            Enderman enderman = (Enderman) entity;
            info.add(null);
            try {
                info.add(enderman.getCarriedBlock().getAsString());
            } catch (Exception endermanException) {
            }
        } else if (entity instanceof IronGolem) {
            IronGolem irongolem = (IronGolem) entity;
            info.add(irongolem.isPlayerCreated());
        } else if (entity instanceof Cat) {
            Cat cat = (Cat) entity;
            info.add(cat.getCatType());
            info.add(cat.getCollarColor());
        } else if (entity instanceof Fox) {
            Fox fox = (Fox) entity;
            info.add(fox.getFoxType());
            info.add(fox.isSitting());
        } else if (entity instanceof Panda) {
            Panda panda = (Panda) entity;
            info.add(panda.getMainGene());
            info.add(panda.getHiddenGene());
        } else if (entity instanceof Pig) {
            Pig pig = (Pig) entity;
            info.add(pig.hasSaddle());
        } else if (entity instanceof Sheep) {
            Sheep sheep = (Sheep) entity;
            info.add(sheep.isSheared());
            info.add(sheep.getColor());
        } else if (entity instanceof MushroomCow) {
            MushroomCow mushroomCow = (MushroomCow) entity;
            info.add(mushroomCow.getVariant());
        } else if (entity instanceof Skeleton) {
            info.add(null);
        } else if (entity instanceof Slime) {
            Slime slime = (Slime) entity;
            info.add(slime.getSize());
        } else if (entity instanceof Parrot) {
            Parrot parrot = (Parrot) entity;
            info.add(parrot.getVariant());
        } else if (entity instanceof TropicalFish) {
            TropicalFish tropicalFish = (TropicalFish) entity;
            info.add(tropicalFish.getBodyColor());
            info.add(tropicalFish.getPattern());
            info.add(tropicalFish.getPatternColor());
        } else if (entity instanceof Phantom) {
            Phantom phantom = (Phantom) entity;
            info.add(phantom.getSize());
        } else if (entity instanceof AbstractVillager) {
            AbstractVillager abstractVillager = (AbstractVillager) entity;
            List<Object> recipes = new ArrayList<>();
            for (MerchantRecipe merchantRecipe : abstractVillager.getRecipes()) {
                List<Object> recipe = new ArrayList<>();
                List<Object> ingredients = new ArrayList<>();
                List<Object> itemMap = new ArrayList<>();
                ItemStack item = merchantRecipe.getResult().clone();
                List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, item.getType(), null, 0);
                item.setItemMeta(null);
                itemMap.add(item.serialize());
                itemMap.add(metadata);
                recipe.add(itemMap);
                recipe.add(merchantRecipe.getUses());
                recipe.add(merchantRecipe.getMaxUses());
                recipe.add(merchantRecipe.hasExperienceReward());
                for (ItemStack ingredient : merchantRecipe.getIngredients()) {
                    itemMap = new ArrayList<>();
                    item = ingredient.clone();
                    metadata = ItemMetaHandler.seralize(item, item.getType(), null, 0);
                    item.setItemMeta(null);
                    itemMap.add(item.serialize());
                    itemMap.add(metadata);
                    ingredients.add(itemMap);
                }
                recipe.add(ingredients);
                recipe.add(merchantRecipe.getVillagerExperience());
                recipe.add(merchantRecipe.getPriceMultiplier());
                recipes.add(recipe);
            }
            if (abstractVillager instanceof Villager) {
                Villager villager = (Villager) abstractVillager;
                info.add(villager.getProfession());
                info.add(villager.getVillagerType());
                info.add(recipes);
                info.add(villager.getVillagerLevel());
                info.add(villager.getVillagerExperience());
            } else {
                info.add(null);
                info.add(null);
                info.add(recipes);
            }
        } else if (entity instanceof Raider) {
            Raider raider = (Raider) entity;
            info.add(raider.isPatrolLeader());
            if (entity instanceof Spellcaster) {
                Spellcaster spellcaster = (Spellcaster) entity;
                info.add(spellcaster.getSpell());
            }
        } else if (entity instanceof Wolf) {
            Wolf wolf = (Wolf) entity;
            info.add(wolf.isSitting());
            info.add(wolf.getCollarColor());
        } else if (entity instanceof ZombieVillager) {
            ZombieVillager zombieVillager = (ZombieVillager) entity;
            info.add(zombieVillager.isBaby());
            info.add(zombieVillager.getVillagerProfession());
        } else if (entity instanceof Zombie) {
            Zombie zombie = (Zombie) entity;
            info.add(zombie.isBaby());
            info.add(null);
            info.add(null);
        } else if (entity instanceof AbstractHorse) {
            AbstractHorse abstractHorse = (AbstractHorse) entity;
            info.add(null);
            info.add(null);
            info.add(abstractHorse.getDomestication());
            info.add(abstractHorse.getJumpStrength());
            info.add(abstractHorse.getMaxDomestication());
            info.add(null);
            info.add(null);
            if (entity instanceof Horse) {
                Horse horse = (Horse) entity;
                info.add(null);
                ItemStack saddle = horse.getInventory().getSaddle();
                if (saddle != null) {
                    info.add(saddle.serialize());
                } else {
                    info.add(null);
                }
                info.add(horse.getColor());
                info.add(horse.getStyle());
                ItemStack horseArmor = horse.getInventory().getArmor();
                if (horseArmor != null) {
                    ItemStack armor = horseArmor.clone();
                    ItemMeta itemMeta = armor.getItemMeta();
                    Color color = null;
                    if (itemMeta instanceof LeatherArmorMeta) {
                        LeatherArmorMeta meta = (LeatherArmorMeta) itemMeta;
                        color = meta.getColor();
                        meta.setColor(null);
                        armor.setItemMeta(meta);
                    }
                    info.add(armor.serialize());
                    if (color != null) {
                        info.add(color.serialize());
                    } else {
                        info.add(null);
                    }
                } else {
                    info.add(null);
                    info.add(null);
                }
            } else if (entity instanceof ChestedHorse) {
                ChestedHorse chestedHorse = (ChestedHorse) entity;
                info.add(chestedHorse.isCarryingChest());
                if (entity instanceof Llama) {
                    Llama llama = (Llama) entity;
                    ItemStack decor = llama.getInventory().getDecor();
                    if (decor != null) {
                        info.add(decor.serialize());
                    } else {
                        info.add(null);
                    }
                    info.add(llama.getColor());
                }
            }
        } else {
            BukkitAdapter.ADAPTER.getEntityMeta(entity, info);
        }
        data.add(age);
        data.add(tame);
        data.add(info);
        data.add(entity.isCustomNameVisible());
        data.add(entity.getCustomName());
        data.add(attributes);
        data.add(details);
        if (!(entity instanceof Player)) {
            Queue.queueEntityKill(e, entity.getLocation(), data, type);
        } else {
            Queue.queuePlayerKill(e, entity.getLocation(), entity.getName());
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) AbstractHorse(org.bukkit.entity.AbstractHorse) ArrayList(java.util.ArrayList) AbstractHorse(org.bukkit.entity.AbstractHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) Phantom(org.bukkit.entity.Phantom) ZombieVillager(org.bukkit.entity.ZombieVillager) Villager(org.bukkit.entity.Villager) AbstractVillager(org.bukkit.entity.AbstractVillager) ThrownPotion(org.bukkit.entity.ThrownPotion) List(java.util.List) ArrayList(java.util.ArrayList) AbstractVillager(org.bukkit.entity.AbstractVillager) Player(org.bukkit.entity.Player) MushroomCow(org.bukkit.entity.MushroomCow) Raider(org.bukkit.entity.Raider) Zombie(org.bukkit.entity.Zombie) Parrot(org.bukkit.entity.Parrot) Color(org.bukkit.Color) Fox(org.bukkit.entity.Fox) Panda(org.bukkit.entity.Panda) EntityType(org.bukkit.entity.EntityType) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Enderman(org.bukkit.entity.Enderman) ChestedHorse(org.bukkit.entity.ChestedHorse) Cat(org.bukkit.entity.Cat) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) Block(org.bukkit.block.Block) ZombieVillager(org.bukkit.entity.ZombieVillager) ItemStack(org.bukkit.inventory.ItemStack) AbstractArrow(org.bukkit.entity.AbstractArrow) Attribute(org.bukkit.attribute.Attribute) Creeper(org.bukkit.entity.Creeper) IronGolem(org.bukkit.entity.IronGolem) Ageable(org.bukkit.entity.Ageable) LivingEntity(org.bukkit.entity.LivingEntity) Attributable(org.bukkit.attribute.Attributable) ArmorStand(org.bukkit.entity.ArmorStand) TropicalFish(org.bukkit.entity.TropicalFish) AttributeInstance(org.bukkit.attribute.AttributeInstance) Spellcaster(org.bukkit.entity.Spellcaster) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) Skeleton(org.bukkit.entity.Skeleton) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Wolf(org.bukkit.entity.Wolf) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) MerchantRecipe(org.bukkit.inventory.MerchantRecipe) Tameable(org.bukkit.entity.Tameable) AttributeModifier(org.bukkit.attribute.AttributeModifier) Slime(org.bukkit.entity.Slime) Pig(org.bukkit.entity.Pig) Llama(org.bukkit.entity.Llama) Sheep(org.bukkit.entity.Sheep) Location(org.bukkit.Location)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Location (org.bukkit.Location)2 Attributable (org.bukkit.attribute.Attributable)2 Attribute (org.bukkit.attribute.Attribute)2 AttributeInstance (org.bukkit.attribute.AttributeInstance)2 AttributeModifier (org.bukkit.attribute.AttributeModifier)2 AbstractHorse (org.bukkit.entity.AbstractHorse)2 AbstractVillager (org.bukkit.entity.AbstractVillager)2 Ageable (org.bukkit.entity.Ageable)2 Cat (org.bukkit.entity.Cat)2 ChestedHorse (org.bukkit.entity.ChestedHorse)2 Creeper (org.bukkit.entity.Creeper)2 Enderman (org.bukkit.entity.Enderman)2 Entity (org.bukkit.entity.Entity)2 EntityType (org.bukkit.entity.EntityType)2 Fox (org.bukkit.entity.Fox)2 Horse (org.bukkit.entity.Horse)2 IronGolem (org.bukkit.entity.IronGolem)2 LivingEntity (org.bukkit.entity.LivingEntity)2