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

- fix print top command

- gainCache should be per player
This commit is contained in:
Kapitowa
2024-07-06 03:24:40 +03:00
parent 2f1ae21b9e
commit 00ca55a629
2 changed files with 8 additions and 8 deletions

View File

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

View File

@@ -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<Skill, Double> = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(3))
private val gainCache: Cache<UUID, Pair<String, Double>> = 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,