diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt index 19b8c60..295160f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt @@ -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, Double> = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(3)) + private val gainCache: Cache = 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,