9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-03 14:22:17 +00:00

Merge pull request #23

EcoSkillsPlayer#giveSkillExperience now updates exp amount if it has been changed in PlayerSkillExpGainEvent
This commit is contained in:
Will FP
2021-11-15 09:40:44 +00:00
committed by GitHub
2 changed files with 21 additions and 3 deletions

View File

@@ -13,6 +13,11 @@ public class PlayerSkillExpGainEvent extends PlayerEvent implements Cancellable
*/
private static final HandlerList HANDLERS = new HandlerList();
/**
* If multiplier is used in this event
*/
private final boolean multiply;
/**
* The skill.
*/
@@ -37,10 +42,12 @@ public class PlayerSkillExpGainEvent extends PlayerEvent implements Cancellable
*/
public PlayerSkillExpGainEvent(@NotNull final Player who,
@NotNull final Skill skill,
final double amount) {
final double amount,
final boolean multiply) {
super(who);
this.skill = skill;
this.amount = amount;
this.multiply = multiply;
}
/**
@@ -61,6 +68,15 @@ public class PlayerSkillExpGainEvent extends PlayerEvent implements Cancellable
return amount;
}
/**
* Get if EcoSkills multipliers are used in this event.
*
* @return The experience.
*/
public boolean isMultiply() {
return multiply;
}
/**
* Set the amount of experience.
*

View File

@@ -71,15 +71,17 @@ fun OfflinePlayer.getAverageSkillLevel(): Double {
}
fun Player.giveSkillExperience(skill: Skill, experience: Double, noMultiply: Boolean = false) {
val exp = abs(if (noMultiply) experience else experience * this.getSkillExperienceMultiplier())
var exp = abs(if (noMultiply) experience else experience * this.getSkillExperienceMultiplier())
val gainEvent = PlayerSkillExpGainEvent(this, skill, exp)
val gainEvent = PlayerSkillExpGainEvent(this, skill, exp, !noMultiply)
Bukkit.getPluginManager().callEvent(gainEvent)
if (gainEvent.isCancelled) {
return
}
exp = gainEvent.amount
val level = this.getSkillLevel(skill)
this.setSkillProgress(skill, this.getSkillProgress(skill) + exp)