Search in sources :

Example 1 with AbstractHorse

use of org.bukkit.entity.AbstractHorse in project Prism-Bukkit by prism.

the class AbstractHorseSerializer method deserializer.

@Override
protected void deserializer(Entity entity) {
    final AbstractHorse h = (AbstractHorse) entity;
    if (entity.getType() == EntityType.HORSE) {
        Horse horse = (Horse) h;
        Horse.Color color = MiscUtils.getEnum(horseColor, Horse.Color.WHITE);
        Horse.Style vstyle = MiscUtils.getEnum(style, Horse.Style.NONE);
        horse.setColor(color);
        horse.setStyle(vstyle);
        horse.getInventory().setSaddle(ItemUtils.itemOf(saddle));
        horse.getInventory().setArmor(ItemUtils.itemOf(armor));
    } else if (entity.getType() == EntityType.LLAMA) {
        Llama llama = (Llama) h;
        Llama.Color color = MiscUtils.getEnum(horseColor, Llama.Color.CREAMY);
        llama.setColor(color);
        llama.getInventory().setDecor(ItemUtils.itemOf(saddle));
    } else if (entity.getType() == EntityType.DONKEY || entity.getType() == EntityType.MULE || entity.getType() == EntityType.ZOMBIE_HORSE || entity.getType() == EntityType.SKELETON_HORSE) {
        h.getInventory().setItem(0, ItemUtils.itemOf(saddle));
    }
    if (entity instanceof ChestedHorse) {
        ((ChestedHorse) h).setCarryingChest(Boolean.TRUE.equals(chest));
    }
    maxDom = Math.max(1, maxDom);
    dom = Math.min(Math.max(0, dom), maxDom);
    jump = Math.min(Math.max(0.0, jump), 2.0);
    h.setDomestication(dom);
    h.setMaxDomestication(maxDom);
    h.setJumpStrength(jump);
    h.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
    AttributeInstance attributeInstance = h.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
    if (attributeInstance != null) {
        attributeInstance.setBaseValue(movementSpeed);
    }
}
Also used : AbstractHorse(org.bukkit.entity.AbstractHorse) Llama(org.bukkit.entity.Llama) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) AbstractHorse(org.bukkit.entity.AbstractHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 2 with AbstractHorse

use of org.bukkit.entity.AbstractHorse in project Prism-Bukkit by prism.

the class AbstractHorseSerializer method serializer.

@Override
protected void serializer(Entity entity) {
    final AbstractHorse h = (AbstractHorse) entity;
    // TODO: Cleanup
    if (entity.getType() == EntityType.HORSE) {
        Horse horse = (Horse) h;
        horseColor = horse.getColor().name();
        style = horse.getStyle().name();
        saddle = ItemUtils.smallString(horse.getInventory().getSaddle());
        armor = ItemUtils.smallString(horse.getInventory().getArmor());
    } else if (entity.getType() == EntityType.LLAMA) {
        Llama llama = (Llama) h;
        horseColor = llama.getColor().name();
        saddle = ItemUtils.smallString(llama.getInventory().getDecor());
    } else if (entity.getType() == EntityType.MULE || entity.getType() == EntityType.DONKEY || entity.getType() == EntityType.ZOMBIE_HORSE || entity.getType() == EntityType.SKELETON_HORSE) {
        // Actually a saddle
        saddle = ItemUtils.smallString(h.getInventory().getItem(0));
    }
    if (entity instanceof ChestedHorse) {
        chest = ((ChestedHorse) entity).isCarryingChest();
    }
    dom = h.getDomestication();
    maxDom = h.getMaxDomestication();
    jump = h.getJumpStrength();
    maxHealth = h.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
    AttributeInstance attributeInstance = h.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
    if (attributeInstance != null) {
        movementSpeed = attributeInstance.getBaseValue();
    }
}
Also used : AbstractHorse(org.bukkit.entity.AbstractHorse) Llama(org.bukkit.entity.Llama) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) AbstractHorse(org.bukkit.entity.AbstractHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 3 with AbstractHorse

use of org.bukkit.entity.AbstractHorse in project Denizen-For-Bukkit by DenizenScript.

the class EquipCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    Map<String, ItemTag> equipment = (Map<String, ItemTag>) scriptEntry.getObject("equipment");
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("entities", entities), db("equipment", equipment));
    }
    for (EntityTag entity : entities) {
        if (entity.isGeneric()) {
            Debug.echoError(scriptEntry, "Cannot equip generic entity " + entity.identify() + "!");
        } else if (entity.isCitizensNPC()) {
            NPCTag npc = entity.getDenizenNPC();
            if (npc != null) {
                Equipment trait = npc.getEquipmentTrait();
                if (equipment.get("hand") != null) {
                    trait.set(0, equipment.get("hand").getItemStack());
                }
                if (equipment.get("head") != null) {
                    trait.set(1, equipment.get("head").getItemStack());
                }
                if (equipment.get("chest") != null) {
                    trait.set(2, equipment.get("chest").getItemStack());
                }
                if (equipment.get("legs") != null) {
                    trait.set(3, equipment.get("legs").getItemStack());
                }
                if (equipment.get("boots") != null) {
                    trait.set(4, equipment.get("boots").getItemStack());
                }
                if (equipment.get("offhand") != null) {
                    trait.set(5, equipment.get("offhand").getItemStack());
                }
                if (npc.isSpawned()) {
                    LivingEntity livingEntity = npc.getLivingEntity();
                    // TODO: Citizens API for this blob?
                    if (livingEntity instanceof AbstractHorse) {
                        if (equipment.get("saddle") != null) {
                            ((AbstractHorse) livingEntity).getInventory().setSaddle(equipment.get("saddle").getItemStack());
                        }
                        if (equipment.get("horse_armor") != null) {
                            if (((AbstractHorse) livingEntity).getInventory() instanceof HorseInventory) {
                                ((HorseInventory) ((AbstractHorse) livingEntity).getInventory()).setArmor(equipment.get("horse_armor").getItemStack());
                            }
                        }
                    } else if (livingEntity instanceof Steerable) {
                        if (equipment.get("saddle") != null) {
                            ItemTag saddle = equipment.get("saddle");
                            if (saddle.getBukkitMaterial() == Material.SADDLE) {
                                ((Steerable) livingEntity).setSaddle(true);
                            } else {
                                ((Steerable) livingEntity).setSaddle(false);
                            }
                        }
                    }
                }
            }
        } else {
            LivingEntity livingEntity = entity.getLivingEntity();
            if (livingEntity != null) {
                if (livingEntity instanceof AbstractHorse) {
                    if (equipment.get("saddle") != null) {
                        ((AbstractHorse) livingEntity).getInventory().setSaddle(equipment.get("saddle").getItemStack());
                    }
                    if (equipment.get("horse_armor") != null) {
                        if (((AbstractHorse) livingEntity).getInventory() instanceof HorseInventory) {
                            ((HorseInventory) ((AbstractHorse) livingEntity).getInventory()).setArmor(equipment.get("horse_armor").getItemStack());
                        }
                    }
                } else if (livingEntity instanceof Steerable) {
                    if (equipment.get("saddle") != null) {
                        ItemTag saddle = equipment.get("saddle");
                        if (saddle.getBukkitMaterial() == Material.SADDLE) {
                            ((Steerable) livingEntity).setSaddle(true);
                        } else {
                            ((Steerable) livingEntity).setSaddle(false);
                        }
                    }
                } else {
                    if (equipment.get("hand") != null) {
                        livingEntity.getEquipment().setItemInMainHand(equipment.get("hand").getItemStack());
                    }
                    if (equipment.get("head") != null) {
                        livingEntity.getEquipment().setHelmet(equipment.get("head").getItemStack());
                    }
                    if (equipment.get("chest") != null) {
                        livingEntity.getEquipment().setChestplate(equipment.get("chest").getItemStack());
                    }
                    if (equipment.get("legs") != null) {
                        livingEntity.getEquipment().setLeggings(equipment.get("legs").getItemStack());
                    }
                    if (equipment.get("boots") != null) {
                        livingEntity.getEquipment().setBoots(equipment.get("boots").getItemStack());
                    }
                    if (equipment.get("offhand") != null) {
                        livingEntity.getEquipment().setItemInOffHand(equipment.get("offhand").getItemStack());
                    }
                }
            }
        }
    }
}
Also used : AbstractHorse(org.bukkit.entity.AbstractHorse) LivingEntity(org.bukkit.entity.LivingEntity) Steerable(org.bukkit.entity.Steerable) Equipment(net.citizensnpcs.api.trait.trait.Equipment) NPCTag(com.denizenscript.denizen.objects.NPCTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) HorseInventory(org.bukkit.inventory.HorseInventory) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

AbstractHorse (org.bukkit.entity.AbstractHorse)3 AttributeInstance (org.bukkit.attribute.AttributeInstance)2 ChestedHorse (org.bukkit.entity.ChestedHorse)2 Horse (org.bukkit.entity.Horse)2 Llama (org.bukkit.entity.Llama)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 Equipment (net.citizensnpcs.api.trait.trait.Equipment)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Steerable (org.bukkit.entity.Steerable)1 HorseInventory (org.bukkit.inventory.HorseInventory)1