Search in sources :

Example 1 with SkillName

use of de.Keyle.MyPet.api.skill.SkillName in project MyPet by xXKeyleXx.

the class LevelListener method on.

@EventHandler
public void on(MyPetLevelEvent event) {
    if (event instanceof MyPetLevelUpEvent || event instanceof MyPetLevelDownEvent) {
        return;
    }
    MyPet myPet = event.getPet();
    int lvl = event.getLevel();
    myPet.getSkills().all().forEach(Skill::reset);
    Skilltree skilltree = myPet.getSkilltree();
    if (skilltree != null) {
        for (int i = 1; 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.apply(skill);
                    }
                }
            }
        }
    }
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent) Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) SkillName(de.Keyle.MyPet.api.skill.SkillName) MyPetLevelDownEvent(de.Keyle.MyPet.api.event.MyPetLevelDownEvent) MyPet(de.Keyle.MyPet.api.entity.MyPet) Upgrade(de.Keyle.MyPet.api.skill.Upgrade) EventHandler(org.bukkit.event.EventHandler)

Example 2 with SkillName

use of de.Keyle.MyPet.api.skill.SkillName 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)

Example 3 with SkillName

use of de.Keyle.MyPet.api.skill.SkillName in project MyPet by xXKeyleXx.

the class LevelListener method on.

@EventHandler
public void on(MyPetLevelUpEvent event) {
    MyPet myPet = event.getPet();
    int lvl = event.getLevel();
    int fromLvl = event.fromLevel();
    if (!event.isQuiet()) {
        int maxlevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : 0;
        if (maxlevel != 0 && lvl >= maxlevel) {
            myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.ReachedMaxLevel", event.getOwner()), myPet.getPetName(), maxlevel));
        } else {
            myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.LevelUp", event.getOwner()), myPet.getPetName(), event.getLevel()));
        }
    }
    Skilltree skilltree = myPet.getSkilltree();
    if (skilltree != null) {
        for (int i = fromLvl + 1; i <= lvl; i++) {
            if (!event.isQuiet()) {
                List<String> notifications = skilltree.getNotifications(i);
                for (String notification : notifications) {
                    notification = notification.replace("{{owner}}", myPet.getOwner().getName()).replace("{{level}}", "" + lvl).replace("{{pet}}", myPet.getPetName());
                    notification = Colorizer.setColors(notification);
                    String[] lines = notification.split("(<br>|\\\\n|\n|<br\\s?/>)");
                    for (String line : lines) {
                        myPet.getOwner().sendMessage(line);
                    }
                }
            }
            Set<Skill> affectedSkills = new HashSet<>();
            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.apply(skill);
                        affectedSkills.add(skill);
                    }
                }
            }
            if (!event.isQuiet()) {
                for (Skill skill : affectedSkills) {
                    String[] messages = skill.getUpgradeMessage();
                    if (messages != null && messages.length > 0) {
                        for (String message : messages) {
                            myPet.getOwner().sendMessage("  " + message);
                        }
                    }
                }
            }
        }
    }
    if (myPet.getStatus() == MyPet.PetState.Here) {
        myPet.getEntity().ifPresent(entity -> {
            entity.getHandle().updateNameTag();
            if (!event.isQuiet()) {
                myPet.setHealth(myPet.getMaxHealth());
                myPet.setSaturation(100);
                new SpiralAnimation(1, entity.getEyeHeight() + 0.5, new EntityLocationHolder(entity)) {

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

Aggregations

MyPet (de.Keyle.MyPet.api.entity.MyPet)3 SkillName (de.Keyle.MyPet.api.skill.SkillName)3 Upgrade (de.Keyle.MyPet.api.skill.Upgrade)3 Skill (de.Keyle.MyPet.api.skill.skilltree.Skill)3 Skilltree (de.Keyle.MyPet.api.skill.skilltree.Skilltree)3 EventHandler (org.bukkit.event.EventHandler)3 EntityLocationHolder (de.Keyle.MyPet.api.util.location.EntityLocationHolder)2 Location (org.bukkit.Location)2 MyPetLevelDownEvent (de.Keyle.MyPet.api.event.MyPetLevelDownEvent)1 MyPetLevelUpEvent (de.Keyle.MyPet.api.event.MyPetLevelUpEvent)1 FixedCircleAnimation (de.Keyle.MyPet.api.util.animation.particle.FixedCircleAnimation)1 SpiralAnimation (de.Keyle.MyPet.api.util.animation.particle.SpiralAnimation)1 HashSet (java.util.HashSet)1