Search in sources :

Example 1 with MyPetLevelDownEvent

use of de.Keyle.MyPet.api.event.MyPetLevelDownEvent in project MyPet by xXKeyleXx.

the class MyPetExperience method uppdateExp.

protected double uppdateExp(double exp, boolean quiet) {
    MyPetExpEvent expEvent = new MyPetExpEvent(myPet, exp);
    Bukkit.getServer().getPluginManager().callEvent(expEvent);
    if (expEvent.isCancelled()) {
        return 0;
    }
    int oldLvl = this.level;
    double oldExp = this.exp;
    this.exp += expEvent.getExp();
    this.exp = Math.max(0, Math.min(maxExp, this.exp));
    int lvl = cache.getLevel(myPet.getWorldGroup(), myPet.getPetType(), this.exp);
    if (lvl != 0) {
        this.level = lvl;
    } else {
        this.level = calculateLevel();
    }
    if (oldLvl != this.level) {
        if (oldLvl < this.level) {
            Bukkit.getServer().getPluginManager().callEvent(new MyPetLevelUpEvent(myPet, this.level, oldLvl, quiet));
        } else {
            Bukkit.getServer().getPluginManager().callEvent(new MyPetLevelDownEvent(myPet, this.level, oldLvl, quiet));
        }
    }
    return this.exp - oldExp;
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent) MyPetExpEvent(de.Keyle.MyPet.api.event.MyPetExpEvent) MyPetLevelDownEvent(de.Keyle.MyPet.api.event.MyPetLevelDownEvent)

Example 2 with MyPetLevelDownEvent

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

Aggregations

MyPetLevelDownEvent (de.Keyle.MyPet.api.event.MyPetLevelDownEvent)2 MyPetLevelUpEvent (de.Keyle.MyPet.api.event.MyPetLevelUpEvent)2 MyPet (de.Keyle.MyPet.api.entity.MyPet)1 MyPetExpEvent (de.Keyle.MyPet.api.event.MyPetExpEvent)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 EventHandler (org.bukkit.event.EventHandler)1