mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2025-12-23 17:09:18 +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:
@@ -37,13 +37,22 @@ fun Player.toggleXPGainSound() {
|
|||||||
this.profile.write(xpGainSoundEnabledKey, !this.profile.read(xpGainSoundEnabledKey))
|
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
|
val Player.isXPGainSoundEnabled: Boolean
|
||||||
get() = this.profile.read(xpGainSoundEnabledKey)
|
get() = this.profile.read(xpGainSoundEnabledKey)
|
||||||
|
|
||||||
class GainXPDisplay(
|
class GainXPDisplay(
|
||||||
private val plugin: EcoPlugin
|
private val plugin: EcoPlugin
|
||||||
) : Listener {
|
) : 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()
|
.build()
|
||||||
|
|
||||||
private val sound = if (plugin.configYml.getBool("skills.gain-xp.sound.enabled")) {
|
private val sound = if (plugin.configYml.getBool("skills.gain-xp.sound.enabled")) {
|
||||||
@@ -55,8 +64,8 @@ class GainXPDisplay(
|
|||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
fun handle(event: PlayerSkillXPGainEvent) {
|
fun handle(event: PlayerSkillXPGainEvent) {
|
||||||
val player = event.player
|
val player = event.player
|
||||||
val current = gainCache.get(player.uniqueId to event.skill.id) { 0.0 }
|
val current = gainCache.get(playerSkill(player, event.skill)) { 0.0 }
|
||||||
gainCache.put(player.uniqueId to event.skill.id, current + event.gainedXP)
|
gainCache.put(playerSkill(player, event.skill), current + event.gainedXP)
|
||||||
|
|
||||||
// Run next tick because level up calls before xp is added
|
// Run next tick because level up calls before xp is added
|
||||||
plugin.scheduler.run {
|
plugin.scheduler.run {
|
||||||
@@ -112,7 +121,7 @@ class GainXPDisplay(
|
|||||||
)
|
)
|
||||||
.replace("%current_xp%", event.player.getSkillXP(event.skill).toNiceString())
|
.replace("%current_xp%", event.player.getSkillXP(event.skill).toNiceString())
|
||||||
.replace("%required_xp%", event.player.getFormattedRequiredXP(event.skill))
|
.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(
|
.formatEco(
|
||||||
placeholderContext(
|
placeholderContext(
|
||||||
event.player,
|
event.player,
|
||||||
|
|||||||
Reference in New Issue
Block a user