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

Fixed bugs with stat modifiers

This commit is contained in:
Auxilor
2021-10-05 19:36:14 +01:00
parent 4a1336a4ed
commit 07e6ed206c
5 changed files with 24 additions and 6 deletions

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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)
}
}
}