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