diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/EcoSkillsAPI.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/EcoSkillsAPI.java index 8f2cfa9..7fd120b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/EcoSkillsAPI.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/api/EcoSkillsAPI.java @@ -115,6 +115,16 @@ public interface EcoSkillsAPI { int getStatLevel(@NotNull OfflinePlayer player, @NotNull Stat stat); + /** + * Get the stat level for a player before any modifiers are applied. + * + * @param player The player. + * @param stat The stat. + * @return The stat level. + */ + int getBaseStatLevel(@NotNull OfflinePlayer player, + @NotNull Stat stat); + /** * Add a stat modifier to an item. * @@ -203,7 +213,7 @@ public interface EcoSkillsAPI { */ @Nullable PlayerStatModifier getStatModifier(@NotNull Player player, - @NotNull NamespacedKey key); + @NotNull NamespacedKey key); /** * Get the instance of the API. 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 f384bd1..08cdfa3 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 @@ -127,7 +127,7 @@ fun OfflinePlayer.setEffectLevel(effect: Effect, level: Int) { } fun OfflinePlayer.getStatLevel(stat: Stat): Int { - var base = profile.readInt(stat.id) + var base = this.getBaseStatLevel(stat) if (this is Player) { for (modifier in this.getStatModifiers()) { if (modifier.stat == stat) { @@ -138,6 +138,10 @@ fun OfflinePlayer.getStatLevel(stat: Stat): Int { return base } +fun OfflinePlayer.getBaseStatLevel(stat: Stat): Int { + return profile.readInt(stat.id) +} + fun Player.setStatLevel(stat: Stat, level: Int) { profile.write(stat.id, level) stat.updateStatLevel(this) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/api/EcoSkillsAPIImpl.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/api/EcoSkillsAPIImpl.kt index 5db6dcf..bc13cf3 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/api/EcoSkillsAPIImpl.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/api/EcoSkillsAPIImpl.kt @@ -44,6 +44,10 @@ object EcoSkillsAPIImpl: EcoSkillsAPI { return player.getStatLevel(stat) } + override fun getBaseStatLevel(player: OfflinePlayer, stat: Stat): Int { + return player.getBaseStatLevel(stat) + } + override fun addStatModifier(itemStack: ItemStack, modifier: ItemStatModifier) { itemStack.addStatModifier(modifier) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt index 6573708..d4a75f5 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt @@ -4,7 +4,7 @@ import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.CommandHandler import com.willfp.eco.core.command.TabCompleteHandler import com.willfp.eco.core.command.impl.Subcommand -import com.willfp.ecoskills.getStatLevel +import com.willfp.ecoskills.getBaseStatLevel import com.willfp.ecoskills.giveSkillExperience import com.willfp.ecoskills.setStatLevel import com.willfp.ecoskills.skills.Skill @@ -73,7 +73,7 @@ class CommandGive(plugin: EcoPlugin) : } if (obj is Stat) { - player.setStatLevel(obj, player.getStatLevel(obj) + amount) + player.setStatLevel(obj, player.getBaseStatLevel(obj) + amount) sender.sendMessage( this.plugin.langYml.getMessage("gave-stat") .replace("%player%", player.name) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt index 3f53ebd..8cbb77e 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt @@ -2,8 +2,8 @@ package com.willfp.ecoskills.skills import com.willfp.ecoskills.api.PlayerSkillLevelUpEvent import com.willfp.ecoskills.effects.Effect +import com.willfp.ecoskills.getBaseStatLevel import com.willfp.ecoskills.getEffectLevel -import com.willfp.ecoskills.getStatLevel import com.willfp.ecoskills.setEffectLevel import com.willfp.ecoskills.setStatLevel import com.willfp.ecoskills.stats.Stat @@ -27,7 +27,7 @@ class SkillLevellingListener : Listener { player.setEffectLevel(obj, player.getEffectLevel(obj) + toGive) } is Stat -> { - player.setStatLevel(obj, player.getStatLevel(obj) + toGive) + player.setStatLevel(obj, player.getBaseStatLevel(obj) + toGive) } } }