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;
}
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);
}
}
}
}
}
}
Aggregations