From 00ca55a629c12b219c02a9c3648a686d4f0ab1a8 Mon Sep 17 00:00:00 2001 From: Kapitowa Date: Sat, 6 Jul 2024 03:24:40 +0300 Subject: [PATCH 1/3] - fix print top command - gainCache should be per player --- .../kotlin/com/willfp/ecoskills/commands/CommandTop.kt | 6 +++--- .../willfp/ecoskills/skills/display/GainXPDisplay.kt | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt index 84f801d..13cd128 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt @@ -35,9 +35,9 @@ class CommandTop(plugin: EcoPlugin) : return@runAsync } - val offset = (page - 1) * 10 - - val positions = ((offset + page)..(offset + page + 9)).toList() + val start = (page - 1) * 10 + 1 + val end = start + 9 + (page - 1) + val positions = (start..end).toList() val top = if (skill == null) { positions.mapNotNull { Skills.getTop(it) } 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 dc9621a..5a2f1fc 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 @@ -18,13 +18,13 @@ import com.willfp.ecoskills.api.getFormattedRequiredXP import com.willfp.ecoskills.api.getSkillLevel import com.willfp.ecoskills.api.getSkillProgress import com.willfp.ecoskills.api.getSkillXP -import com.willfp.ecoskills.skills.Skill import org.bukkit.boss.BarColor import org.bukkit.boss.BarStyle import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import java.time.Duration +import java.util.UUID private val xpGainSoundEnabledKey = PersistentDataKey( namespacedKeyOf("ecoskills", "gain_sound_enabled"), @@ -42,7 +42,7 @@ val Player.isXPGainSoundEnabled: Boolean class GainXPDisplay( private val plugin: EcoPlugin ) : Listener { - private val gainCache: Cache = 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")) { @@ -54,8 +54,8 @@ class GainXPDisplay( @EventHandler fun handle(event: PlayerSkillXPGainEvent) { val player = event.player - val current = gainCache.get(event.skill) { 0.0 } - gainCache.put(event.skill, current + event.gainedXP) + val current = gainCache.get(player.uniqueId) { event.skill.id to 0.0 } + gainCache.put(player.uniqueId, event.skill.id to (current.second + event.gainedXP)) // Run next tick because level up calls before xp is added plugin.scheduler.run { @@ -111,7 +111,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.skill) { 0.0 }.toNiceString()) + .replace("%gained_xp%", gainCache.get(event.player.uniqueId) { event.skill.id to 0.0 }.toNiceString()) .formatEco( placeholderContext( event.player, From 94bfa39b65fa81cf95b80c3adb047d792024de40 Mon Sep 17 00:00:00 2001 From: Kapitowa Date: Sat, 6 Jul 2024 13:50:19 +0300 Subject: [PATCH 2/3] - fix mistakes --- .../src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt | 2 +- .../kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt index 13cd128..2cfd647 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt @@ -36,7 +36,7 @@ class CommandTop(plugin: EcoPlugin) : } val start = (page - 1) * 10 + 1 - val end = start + 9 + (page - 1) + val end = start + 9 val positions = (start..end).toList() val top = if (skill == null) { 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 5a2f1fc..6cbd7f6 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 @@ -111,7 +111,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) { event.skill.id to 0.0 }.toNiceString()) + .replace("%gained_xp%", gainCache.get(event.player.uniqueId) { event.skill.id to 0.0 }.second.toNiceString()) .formatEco( placeholderContext( event.player, From 792965fc18383a9b5806f4d41fd76dceb62c8abc Mon Sep 17 00:00:00 2001 From: Kapitowa Date: Sat, 13 Jul 2024 16:11:47 +0300 Subject: [PATCH 3/3] - fix display for each skill and do priority monitor to accept multipliers --- .../willfp/ecoskills/skills/display/GainXPDisplay.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 6cbd7f6..19b8c60 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 @@ -22,6 +22,7 @@ import org.bukkit.boss.BarColor import org.bukkit.boss.BarStyle import org.bukkit.entity.Player import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority import org.bukkit.event.Listener import java.time.Duration import java.util.UUID @@ -42,7 +43,7 @@ val Player.isXPGainSoundEnabled: Boolean class GainXPDisplay( private val plugin: EcoPlugin ) : Listener { - private val gainCache: Cache> = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(3)) + private val gainCache: Cache, Double> = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(3)) .build() private val sound = if (plugin.configYml.getBool("skills.gain-xp.sound.enabled")) { @@ -51,11 +52,11 @@ class GainXPDisplay( ) } else null - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) fun handle(event: PlayerSkillXPGainEvent) { val player = event.player - val current = gainCache.get(player.uniqueId) { event.skill.id to 0.0 } - gainCache.put(player.uniqueId, event.skill.id to (current.second + event.gainedXP)) + val current = gainCache.get(player.uniqueId to event.skill.id) { 0.0 } + gainCache.put(player.uniqueId to event.skill.id, current + event.gainedXP) // Run next tick because level up calls before xp is added plugin.scheduler.run { @@ -111,7 +112,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) { event.skill.id to 0.0 }.second.toNiceString()) + .replace("%gained_xp%", gainCache.get(event.player.uniqueId to event.skill.id) { 0.0 }.toNiceString()) .formatEco( placeholderContext( event.player,