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

Merge pull request #160 from Kapitowa/master

Fix 2 issues
This commit is contained in:
Will FP
2025-01-31 11:43:43 +00:00
committed by GitHub
2 changed files with 10 additions and 9 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
val positions = (start..end).toList()
val top = if (skill == null) {
positions.mapNotNull { Skills.getTop(it) }

View File

@@ -18,13 +18,14 @@ 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.EventPriority
import org.bukkit.event.Listener
import java.time.Duration
import java.util.UUID
private val xpGainSoundEnabledKey = PersistentDataKey(
namespacedKeyOf("ecoskills", "gain_sound_enabled"),
@@ -42,7 +43,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<Pair<UUID, String>, 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(event.skill) { 0.0 }
gainCache.put(event.skill, current + 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.skill) { 0.0 }.toNiceString())
.replace("%gained_xp%", gainCache.get(event.player.uniqueId to event.skill.id) { 0.0 }.toNiceString())
.formatEco(
placeholderContext(
event.player,