Search in sources :

Example 1 with MyPetExpEvent

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

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

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

the class MyPetExperience method addExp.

public double addExp(EntityType type, int percent) {
    MonsterExperience monsterExperience = MonsterExperience.getMonsterExperience(type);
    if (monsterExperience.getEntityType() != EntityType.UNKNOWN) {
        double exp = monsterExperience.getRandomExp() / 100. * percent;
        MyPetExpEvent expEvent = new MyPetExpEvent(myPet, this.exp, Math.min(levelCapExp, this.exp + exp));
        Bukkit.getServer().getPluginManager().callEvent(expEvent);
        if (expEvent.isCancelled()) {
            return 0;
        }
        int tmpLvl = getLevel();
        this.exp = expEvent.getExp();
        if (tmpLvl < getLevel()) {
            Bukkit.getServer().getPluginManager().callEvent(new MyPetLevelUpEvent(myPet, getLevel(), tmpLvl));
        }
        return expEvent.getNewExp() - expEvent.getOldExp();
    }
    return 0;
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent) MonsterExperience(de.Keyle.MyPet.api.skill.experience.MonsterExperience) MyPetExpEvent(de.Keyle.MyPet.api.event.MyPetExpEvent)

Example 4 with MyPetExpEvent

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

the class MyPetExperience method removeCurrentExp.

public void removeCurrentExp(double exp) {
    if (exp > getCurrentExp()) {
        exp = getCurrentExp();
    }
    MyPetExpEvent expEvent = new MyPetExpEvent(myPet, this.exp, this.exp - exp);
    Bukkit.getServer().getPluginManager().callEvent(expEvent);
    if (expEvent.isCancelled()) {
        return;
    }
    this.exp = expEvent.getExp();
}
Also used : MyPetExpEvent(de.Keyle.MyPet.api.event.MyPetExpEvent)

Example 5 with MyPetExpEvent

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

the class MyPetExperience method addExp.

public double addExp(double exp) {
    MyPetExpEvent event = new MyPetExpEvent(myPet, this.exp, Math.min(levelCapExp, this.exp + exp));
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return 0;
    }
    int tmpLvl = getLevel();
    this.exp = event.getExp();
    if (tmpLvl < getLevel()) {
        Bukkit.getServer().getPluginManager().callEvent(new MyPetLevelUpEvent(myPet, getLevel(), tmpLvl));
    }
    return event.getNewExp() - event.getOldExp();
}
Also used : MyPetLevelUpEvent(de.Keyle.MyPet.api.event.MyPetLevelUpEvent) MyPetExpEvent(de.Keyle.MyPet.api.event.MyPetExpEvent)

Aggregations

MyPetExpEvent (de.Keyle.MyPet.api.event.MyPetExpEvent)7 MyPetLevelUpEvent (de.Keyle.MyPet.api.event.MyPetLevelUpEvent)5 MonsterExperience (de.Keyle.MyPet.api.skill.experience.MonsterExperience)2 MyPetLevelDownEvent (de.Keyle.MyPet.api.event.MyPetLevelDownEvent)1