mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-02 22:02:19 +00:00
Added %ecoskillstop_<place>_name% and %ecoskillstop_<place>_amount% placeholders
This commit is contained in:
@@ -34,6 +34,7 @@ allprojects {
|
||||
maven { url 'https://repo.codemc.io/repository/maven-public/' }
|
||||
maven { url 'https://repo.dmulloy2.net/repository/public/' }
|
||||
maven { url 'https://repo.essentialsx.net/releases/' }
|
||||
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
|
||||
}
|
||||
|
||||
jar {
|
||||
@@ -49,6 +50,7 @@ allprojects {
|
||||
compileOnly 'com.willfp:eco:6.44.0'
|
||||
implementation 'com.willfp:libreforge:3.128.0'
|
||||
implementation 'org.joml:joml:1.10.4'
|
||||
compileOnly 'me.clip:placeholderapi:2.11.2'
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
compileOnly 'com.github.LegameMc:EnchantGui-API:1.0'
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.willfp.ecoskills.effects.Effect;
|
||||
import com.willfp.ecoskills.effects.Effects;
|
||||
import com.willfp.ecoskills.integrations.EcoEnchantsEnchantingLeveller;
|
||||
import com.willfp.ecoskills.integrations.enchantgui.EnchantGuiHandler;
|
||||
import com.willfp.ecoskills.placeholders.EcoSkillsTopExpansion;
|
||||
import com.willfp.ecoskills.skills.CustomSkillTriggerXPGainListener;
|
||||
import com.willfp.ecoskills.skills.Skill;
|
||||
import com.willfp.ecoskills.skills.SkillDisplayListener;
|
||||
@@ -149,7 +150,8 @@ public class EcoSkillsPlugin extends LibReforgePlugin {
|
||||
public List<IntegrationLoader> loadAdditionalIntegrations() {
|
||||
return List.of(
|
||||
new IntegrationLoader("EcoEnchants", () -> this.getEventManager().registerListener(new EcoEnchantsEnchantingLeveller(this))),
|
||||
new IntegrationLoader("EnchantGui", () -> this.getEventManager().registerListener(new EnchantGuiHandler()))
|
||||
new IntegrationLoader("EnchantGui", () -> this.getEventManager().registerListener(new EnchantGuiHandler())),
|
||||
new IntegrationLoader("PlaceholderAPI", () -> new EcoSkillsTopExpansion(this).register())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class CommandTop(plugin: EcoPlugin) :
|
||||
val page = args.firstOrNull()?.toIntOrNull() ?: 1
|
||||
val top = LeaderboardHandler.getPage(page)
|
||||
|
||||
val messages = plugin.langYml.getStrings("top")
|
||||
val messages = plugin.langYml.getStrings("top.format")
|
||||
val lines = mutableListOf<String>()
|
||||
|
||||
val useDisplayName = plugin.configYml.getBool("commands.top.use-display-name")
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoskills.placeholders
|
||||
|
||||
import com.willfp.eco.util.savedDisplayName
|
||||
import com.willfp.ecoskills.EcoSkillsPlugin
|
||||
import com.willfp.ecoskills.skills.Skills
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion
|
||||
import org.bukkit.OfflinePlayer
|
||||
|
||||
class EcoSkillsTopExpansion(val plugin: EcoSkillsPlugin): PlaceholderExpansion() {
|
||||
/**
|
||||
* The placeholder identifier of this expansion. May not contain %,
|
||||
* {} or _
|
||||
*
|
||||
* @return placeholder identifier that is associated with this expansion
|
||||
*/
|
||||
override fun getIdentifier(): String {
|
||||
return "ecoskillstop"
|
||||
}
|
||||
|
||||
/**
|
||||
* The author of this expansion
|
||||
*
|
||||
* @return name of the author for this expansion
|
||||
*/
|
||||
override fun getAuthor(): String {
|
||||
return "_OfTeN_"
|
||||
}
|
||||
|
||||
/**
|
||||
* The version of this expansion
|
||||
*
|
||||
* @return current version of this expansion
|
||||
*/
|
||||
override fun getVersion(): String {
|
||||
return "1.0.0"
|
||||
}
|
||||
|
||||
override fun onRequest(player: OfflinePlayer?, params: String): String? {
|
||||
val args = params.split("_")
|
||||
val skill = Skills.getByID(args.firstOrNull()?.lowercase() ?: return "Invalid skill")
|
||||
val place = args.getOrNull(1)?.toIntOrNull() ?: return "Invalid place (must be an integer)"
|
||||
|
||||
return when (args.lastOrNull() ?: return "Invalid type: ${args.lastOrNull()}. Must be name/amount") {
|
||||
"name" -> skill?.getTop(place)?.player?.savedDisplayName ?: plugin.langYml.getFormattedString(
|
||||
"top.name-empty"
|
||||
)
|
||||
"amount" -> skill?.getTop(place)?.amount?.toString() ?: plugin.langYml.getFormattedString(
|
||||
"top.amount-empty"
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoskills.skills
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
@@ -24,14 +25,19 @@ import com.willfp.ecoskills.stats.Stats
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.Listener
|
||||
import java.time.Duration
|
||||
|
||||
abstract class Skill @JvmOverloads constructor(
|
||||
val id: String,
|
||||
forceConfig: Config? = null
|
||||
) : Listener {
|
||||
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
|
||||
val leaderBoardCache: Cache<Int, LeaderboardCacheEntry?> = Caffeine.newBuilder()
|
||||
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
|
||||
.build()
|
||||
|
||||
val key: NamespacedKey = plugin.namespacedKeyFactory.create(id)
|
||||
|
||||
@@ -240,6 +246,17 @@ abstract class Skill @JvmOverloads constructor(
|
||||
return levels
|
||||
}
|
||||
|
||||
fun getTop(place: Int): LeaderboardCacheEntry? {
|
||||
return leaderBoardCache.get(place) {
|
||||
val top = Bukkit.getOfflinePlayers()
|
||||
.sortedByDescending { it.getSkillLevel(this) }.getOrNull(place - 1)
|
||||
|
||||
if (top == null) {
|
||||
null
|
||||
} else LeaderboardCacheEntry(top, top.getSkillLevel(this))
|
||||
}
|
||||
}
|
||||
|
||||
fun getRewardsMessages(player: Player?, level: Int): List<String> {
|
||||
val raw = messagesCache.get(level) {
|
||||
val parentSection = this.config.getSubsection("rewards.chat-messages")
|
||||
@@ -351,3 +368,5 @@ abstract class Skill @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class LeaderboardCacheEntry(val player: OfflinePlayer, val amount: Int)
|
||||
|
||||
@@ -549,6 +549,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
|
||||
cache-expire-after: 180 # The amount of seconds to cache a player's leaderboard stats for
|
||||
|
||||
potions:
|
||||
icon:
|
||||
|
||||
@@ -42,8 +42,11 @@ line-wrap-color: "&8"
|
||||
|
||||
top-line-format: "%rank%. %playername% - %level%"
|
||||
top:
|
||||
- "---- Skills Leaderboard ----"
|
||||
- "%lines%"
|
||||
format:
|
||||
- "---- Skills Leaderboard ----"
|
||||
- "%lines%"
|
||||
name-empty: "&cEmpty"
|
||||
amount-empty: "&0"
|
||||
|
||||
menu:
|
||||
title: "Your Skills"
|
||||
|
||||
Reference in New Issue
Block a user