From 4baa32314c09e8621b9984e4097ec52681e9211a Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Sun, 14 Nov 2021 18:19:15 +0300 Subject: [PATCH 1/2] EcoSkillsPlayer#giveSkillExperience now updates exp amount if it has been change in PlayerSkillExpGainEvent --- .../src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt index 6bb2239..467c54d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt @@ -71,7 +71,7 @@ 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) Bukkit.getPluginManager().callEvent(gainEvent) @@ -80,6 +80,8 @@ fun Player.giveSkillExperience(skill: Skill, experience: Double, noMultiply: Boo return } + exp = gainEvent.amount + val level = this.getSkillLevel(skill) this.setSkillProgress(skill, this.getSkillProgress(skill) + exp) From 5fdab1a49aa49c1717bb03a2628c6bb821a93fdb Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Sun, 14 Nov 2021 19:11:19 +0300 Subject: [PATCH 2/2] Added PlayerSkillExpGainEvent#isMultiply --- .../ecoskills/api/PlayerSkillExpGainEvent.java | 18 +++++++++++++++++- .../com/willfp/ecoskills/EcoSkillsPlayer.kt | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/PlayerSkillExpGainEvent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/PlayerSkillExpGainEvent.java index 36caa6f..9f5eb34 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/PlayerSkillExpGainEvent.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/PlayerSkillExpGainEvent.java @@ -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. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt index 467c54d..d832ab4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt @@ -73,7 +73,7 @@ fun OfflinePlayer.getAverageSkillLevel(): Double { fun Player.giveSkillExperience(skill: Skill, experience: Double, noMultiply: Boolean = false) { 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) {