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