Search in sources :

Example 1 with FixedCircleAnimation

use of de.Keyle.MyPet.api.util.animation.particle.FixedCircleAnimation in project MyPet by xXKeyleXx.

the class LevelListener method on.

@EventHandler
public void on(MyPetLevelDownEvent event) {
    MyPet myPet = event.getPet();
    int lvl = event.getLevel();
    int fromLvl = event.fromLevel();
    if (!event.isQuiet()) {
        myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.LevelDown", event.getOwner()), myPet.getPetName(), event.getLevel()));
    }
    Skilltree skilltree = myPet.getSkilltree();
    if (skilltree != null) {
        for (int i = fromLvl; i > lvl; i--) {
            List<Upgrade> upgrades = skilltree.getUpgrades(i);
            for (Upgrade upgrade : upgrades) {
                SkillName sn = Util.getClassAnnotation(upgrade.getClass(), SkillName.class);
                if (sn != null) {
                    Skill skill = myPet.getSkills().get(sn.value());
                    if (skill != null) {
                        upgrade.invert(skill);
                    }
                }
            }
        }
    }
    if (myPet.getStatus() == MyPet.PetState.Here) {
        myPet.getEntity().ifPresent(entity -> {
            entity.getHandle().updateNameTag();
            if (!event.isQuiet()) {
                myPet.setHealth(myPet.getMaxHealth());
                myPet.setSaturation(100);
                new FixedCircleAnimation(1, entity.getEyeHeight() + 0.5, 10, new EntityLocationHolder(entity)) {

                    @Override
                    protected void playParticleEffect(Location location) {
                        MyPetApi.getPlatformHelper().playParticleEffect(location, ParticleCompat.BLOCK_CRACK.get(), 0, 0, 0, 0, 1, 32, ParticleCompat.REDSTONE_BLOCK_DATA);
                    }
                }.once();
                entity.getWorld().playSound(entity.getLocation(), Sound.valueOf(SoundCompat.LEVEL_DOWN.get()), 1F, 0.7F);
            }
        });
    }
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) SkillName(de.Keyle.MyPet.api.skill.SkillName) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) MyPet(de.Keyle.MyPet.api.entity.MyPet) FixedCircleAnimation(de.Keyle.MyPet.api.util.animation.particle.FixedCircleAnimation) EntityLocationHolder(de.Keyle.MyPet.api.util.location.EntityLocationHolder) Upgrade(de.Keyle.MyPet.api.skill.Upgrade) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MyPet (de.Keyle.MyPet.api.entity.MyPet)1 SkillName (de.Keyle.MyPet.api.skill.SkillName)1 Upgrade (de.Keyle.MyPet.api.skill.Upgrade)1 Skill (de.Keyle.MyPet.api.skill.skilltree.Skill)1 Skilltree (de.Keyle.MyPet.api.skill.skilltree.Skilltree)1 FixedCircleAnimation (de.Keyle.MyPet.api.util.animation.particle.FixedCircleAnimation)1 EntityLocationHolder (de.Keyle.MyPet.api.util.location.EntityLocationHolder)1 Location (org.bukkit.Location)1 EventHandler (org.bukkit.event.EventHandler)1