Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2 issues #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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")) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down