Search in sources :

Example 1 with MyPetLevelUpEvent

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

the class MyPetExperience method reset.

public void reset() {
    levelCapExp = getExpByLevel(Configuration.LevelSystem.Experience.LEVEL_CAP);
    exp = 0;
    Bukkit.getServer().getPluginManager().callEvent(new MyPetLevelUpEvent(myPet, getLevel(), 0, true));
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent)

Example 2 with MyPetLevelUpEvent

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

the class MyPetExperience method setExp.

public void setExp(double exp) {
    exp = Math.max(0, exp);
    exp = Math.min(levelCapExp, exp);
    MyPetExpEvent expEvent = new MyPetExpEvent(myPet, this.exp, exp);
    Bukkit.getServer().getPluginManager().callEvent(expEvent);
    if (expEvent.isCancelled()) {
        return;
    }
    int tmplvl = getLevel();
    this.exp = expEvent.getExp();
    if (tmplvl != getLevel()) {
        Bukkit.getServer().getPluginManager().callEvent(new MyPetLevelUpEvent(myPet, getLevel(), tmplvl, true));
    }
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent) MyPetExpEvent(de.Keyle.MyPet.api.event.MyPetExpEvent)

Example 3 with MyPetLevelUpEvent

use of de.Keyle.MyPet.api.event.MyPetLevelUpEvent 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 4 with MyPetLevelUpEvent

use of de.Keyle.MyPet.api.event.MyPetLevelUpEvent 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 5 with MyPetLevelUpEvent

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

the class MyPet method setSkilltree.

public boolean setSkilltree(SkillTree skillTree) {
    if (skillTree == null || this.skillTree == skillTree) {
        return false;
    }
    if (skillTree.getRequiredLevel() > 1 && getExperience().getLevel() < skillTree.getRequiredLevel()) {
        return false;
    }
    skills.reset();
    this.skillTree = skillTree;
    getServer().getPluginManager().callEvent(new MyPetLevelUpEvent(this, experience.getLevel(), 0, true));
    return true;
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent)

Aggregations

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