From bcf5ef3b0ff44ddd65cd9470a6464f8f947ffd0c Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Fri, 17 Feb 2023 03:54:57 +0300 Subject: [PATCH 1/4] Fixed inappropriate xp gain handling --- .../kotlin/com/willfp/ecojobs/jobs/JobTriggerXPGainListener.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobTriggerXPGainListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobTriggerXPGainListener.kt index 0af2c2a..6c4ea45 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobTriggerXPGainListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobTriggerXPGainListener.kt @@ -17,7 +17,7 @@ object JobTriggerXPGainListener : Listener { val amount = job.getXP(event) if (amount <= 0.0) { - return + continue } player.giveJobExperience(job, amount) From 2014a6dd5fc81c95de877f7dc74d0d5c31346bc8 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Fri, 17 Feb 2023 04:44:33 +0300 Subject: [PATCH 2/4] Updated eco --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 926eef0..3dc88fe 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.46.0' + compileOnly 'com.willfp:eco:6.51.1' implementation 'com.willfp:libreforge:3.129.2' implementation 'com.willfp:ecomponent:1.3.0' implementation 'org.joml:joml:1.10.4' From 4034f5098f167f1a7781568441c035eb324e4391 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Fri, 17 Feb 2023 04:45:45 +0300 Subject: [PATCH 3/4] Added %ecojobs_top___% placeholder --- .../com/willfp/ecojobs/EcoJobsPlugin.kt | 24 +++++++++++++++++++ .../kotlin/com/willfp/ecojobs/jobs/Job.kt | 15 ++++++++++++ .../core-plugin/src/main/resources/lang.yml | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt index bce3839..3e5eb1a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt @@ -1,7 +1,10 @@ package com.willfp.ecojobs import com.willfp.eco.core.command.impl.PluginCommand +import com.willfp.eco.core.placeholder.DynamicPlaceholder import com.willfp.eco.core.placeholder.PlayerPlaceholder +import com.willfp.eco.util.savedDisplayName +import com.willfp.eco.util.toNiceString import com.willfp.ecojobs.api.activeJobs import com.willfp.ecojobs.api.getJobLevel import com.willfp.ecojobs.api.jobLimit @@ -14,6 +17,7 @@ import com.willfp.ecojobs.jobs.PriceHandler import com.willfp.ecojobs.jobs.ResetOnQuitListener import com.willfp.libreforge.LibReforgePlugin import org.bukkit.event.Listener +import java.util.regex.Pattern class EcoJobsPlugin : LibReforgePlugin() { init { @@ -46,6 +50,26 @@ class EcoJobsPlugin : LibReforgePlugin() { } level.toString() }.register() + + DynamicPlaceholder( + this, + Pattern.compile("top_[a-z]+_[0-9]+_[a-z]+") + ) { + val split = it.split("_") + val jobId = split.getOrNull(1) ?: return@DynamicPlaceholder "You must specify the job id!" + val job = Jobs.getByID(jobId) ?: return@DynamicPlaceholder "Invalid job id!" + val placeString = split.getOrNull(2) ?: return@DynamicPlaceholder "You must specify the place!" + val place = placeString.toIntOrNull() ?: return@DynamicPlaceholder "Invalid place!" + val type = split.getOrNull(3) ?: return@DynamicPlaceholder "You must specify the top type!" + val topEntry = job.getTop(place) + return@DynamicPlaceholder when(type) { + "name" -> topEntry?.player?.savedDisplayName + ?: this.langYml.getFormattedString("top.name-empty") + "amount" -> topEntry?.amount?.toNiceString() + ?: this.langYml.getFormattedString("top.amount-empty") + else -> "Invalid type: $type! Available types: name/amount" + } + }.register() } override fun loadPluginCommands(): List { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt index 0411aeb..530c946 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt @@ -47,6 +47,8 @@ import kotlin.math.max class Job( val id: String, val config: Config, private val plugin: EcoJobsPlugin ) { + private val topCache = Caffeine.newBuilder().build() + val name = config.getFormattedString("name") val description = config.getFormattedString("description") val isUnlockedByDefault = config.getBool("unlocked-by-default") @@ -354,6 +356,14 @@ class Job( return jobXpGains.sumOf { it.getCount(event) } } + fun getTop(place: Int): LeaderboardCacheEntry? { + return topCache.get(place) { + val players = Bukkit.getOfflinePlayers().sortedByDescending { it.getJobLevel(this) } + val target = players.getOrNull(place-1) ?: return@get null + return@get LeaderboardCacheEntry(target, target.getJobLevel(this)) + } + } + override fun equals(other: Any?): Boolean { if (other !is Job) { return false @@ -373,6 +383,11 @@ private class LevelPlaceholder( operator fun invoke(level: Int) = function(level) } +data class LeaderboardCacheEntry( + val player: OfflinePlayer, + val amount: Int +) + private fun Collection.format(string: String, level: Int): String { var process = string for (placeholder in this) { diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 3844f7e..95ae2bf 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -42,3 +42,7 @@ menu: title: "Jobs" infinity: "∞" + +top: + name-empty: "&cEmpty" + amount-empty: "0" From 6bf9d371b9a2d60064fdd1c02d4256d97672613d Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Sat, 18 Feb 2023 02:20:16 +0300 Subject: [PATCH 4/4] Fixed leaderboard placeholders updating --- .../src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt | 5 ++++- eco-core/core-plugin/src/main/resources/config.yml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt index 530c946..19fca95 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt @@ -38,6 +38,7 @@ import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack +import java.time.Duration import java.util.DoubleSummaryStatistics import java.util.Objects import java.util.concurrent.TimeUnit @@ -47,7 +48,9 @@ import kotlin.math.max class Job( val id: String, val config: Config, private val plugin: EcoJobsPlugin ) { - private val topCache = Caffeine.newBuilder().build() + private val topCache = Caffeine.newBuilder() + .expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("leaderboard-cache-lifetime").toLong())) + .build() val name = config.getFormattedString("name") val description = config.getFormattedString("description") diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 6d507f3..ae6b936 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -312,6 +312,7 @@ point-names: # If you have point names that look ugly (eg g_souls) then you can use-faster-move-trigger: true # Disable if you want move trigger to detect sub-1-block movements raytrace-distance: 80 # The distance that alt_click should check for a location +leaderboard-cache-lifetime: 180 # How often will top placeholders update their cache (in seconds) potions: icon: