From 74a5b645129d9f8ccc3cb919cf3d8934a05ded36 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 24 Feb 2023 12:59:00 +0000 Subject: [PATCH] Fixed NaN experience bug --- .../com/willfp/ecoskills/EcoSkillsPlayer.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 5177bd6..b1fda66 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 @@ -125,11 +125,20 @@ fun OfflinePlayer.getSkillProgressRequired(skill: Skill): Int { } fun OfflinePlayer.getSkillProgress(skill: Skill): Double { - return this.profile.read(skill.dataXPKey) + val xp = this.profile.read(skill.dataXPKey) + + if (xp.isNaN()) { + this.profile.write(skill.dataXPKey, 0.0) + return 0.0 + } + + return xp } -fun OfflinePlayer.setSkillProgress(skill: Skill, level: Double) { - this.profile.write(skill.dataXPKey, level) +fun OfflinePlayer.setSkillProgress(skill: Skill, xp: Double) { + require(!xp.isNaN()) { "NaN Experience!" } + + this.profile.write(skill.dataXPKey, xp) } fun OfflinePlayer.getEffectLevel(effect: Effect): Int {