9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2025-12-19 15:09:23 +00:00

Merge pull request #164 from Auxilor/develop

Fixed %gained_xp% placeholder returning per-skill, not per-player values
This commit is contained in:
Will FP
2025-01-31 11:45:07 +00:00
committed by GitHub

View File

@@ -37,13 +37,22 @@ fun Player.toggleXPGainSound() {
this.profile.write(xpGainSoundEnabledKey, !this.profile.read(xpGainSoundEnabledKey))
}
data class PlayerSkill(
val player: UUID,
val skill: String
)
private fun playerSkill(player: Player, skill: Skill): PlayerSkill {
return PlayerSkill(player.uniqueId, skill.id)
}
val Player.isXPGainSoundEnabled: Boolean
get() = this.profile.read(xpGainSoundEnabledKey)
class GainXPDisplay(
private val plugin: EcoPlugin
) : Listener {
private val gainCache: Cache<Pair<UUID, String>, Double> = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(3))
private val gainCache: Cache<PlayerSkill, Double> = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(3))
.build()
private val sound = if (plugin.configYml.getBool("skills.gain-xp.sound.enabled")) {
@@ -55,8 +64,8 @@ class GainXPDisplay(
@EventHandler(priority = EventPriority.MONITOR)
fun handle(event: PlayerSkillXPGainEvent) {
val player = event.player
val current = gainCache.get(player.uniqueId to event.skill.id) { 0.0 }
gainCache.put(player.uniqueId to event.skill.id, current + event.gainedXP)
val current = gainCache.get(playerSkill(player, event.skill)) { 0.0 }
gainCache.put(playerSkill(player, event.skill), current + event.gainedXP)
// Run next tick because level up calls before xp is added
plugin.scheduler.run {
@@ -112,7 +121,7 @@ class GainXPDisplay(
)
.replace("%current_xp%", event.player.getSkillXP(event.skill).toNiceString())
.replace("%required_xp%", event.player.getFormattedRequiredXP(event.skill))
.replace("%gained_xp%", gainCache.get(event.player.uniqueId to event.skill.id) { 0.0 }.toNiceString())
.replace("%gained_xp%", gainCache.get(playerSkill(event.player, event.skill)) { 0.0 }.toNiceString())
.formatEco(
placeholderContext(
event.player,