mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-01 21:36:34 +00:00
Fixes and improvements
This commit is contained in:
@@ -23,6 +23,7 @@ import com.willfp.ecoskills.libreforge.TriggerGainSkillXp
|
||||
import com.willfp.ecoskills.libreforge.TriggerLevelUpSkill
|
||||
import com.willfp.ecoskills.mana.MagicHandler
|
||||
import com.willfp.ecoskills.mana.MagicTypes
|
||||
import com.willfp.ecoskills.skills.EcoSkillsSkillTopPlaceholder
|
||||
import com.willfp.ecoskills.skills.EcoSkillsTopPlaceholder
|
||||
import com.willfp.ecoskills.skills.SkillCritListener
|
||||
import com.willfp.ecoskills.skills.Skills
|
||||
@@ -79,10 +80,14 @@ class EcoSkillsPlugin : LibreforgePlugin() {
|
||||
Filters.register(FilterSkillCrit)
|
||||
|
||||
EcoSkillsTopPlaceholder(this).register()
|
||||
EcoSkillsSkillTopPlaceholder(this).register()
|
||||
}
|
||||
|
||||
override fun handleReload() {
|
||||
ActionBarHandler(this).startTicking()
|
||||
if (this.configYml.getBool("persistent-action-bar.enabled")) {
|
||||
ActionBarHandler(this).startTicking()
|
||||
}
|
||||
|
||||
TemporaryBossBarHandler(this).startTicking()
|
||||
MagicHandler(this).startTicking()
|
||||
}
|
||||
|
||||
@@ -92,7 +92,8 @@ abstract class Levellable(
|
||||
|
||||
val uuid = leaderboardCache.get(true).getOrNull(position - 1) ?: return null
|
||||
|
||||
val player = Bukkit.getOfflinePlayer(uuid)
|
||||
val player = Bukkit.getOfflinePlayer(uuid).takeIf { it.hasPlayedBefore() } ?: return null
|
||||
|
||||
return LeaderboardEntry(
|
||||
player,
|
||||
getActualLevel(player)
|
||||
|
||||
@@ -16,6 +16,7 @@ class CommandSkills(plugin: EcoPlugin) : PluginCommand(
|
||||
) {
|
||||
init {
|
||||
this.addSubcommand(CommandToggleActionBar(plugin))
|
||||
.addSubcommand(CommandTop(plugin))
|
||||
}
|
||||
|
||||
override fun onExecute(player: Player, args: List<String>) {
|
||||
|
||||
@@ -14,7 +14,6 @@ class CommandToggleActionBar(plugin: EcoPlugin) : Subcommand(
|
||||
) {
|
||||
|
||||
override fun onExecute(player: Player, args: List<String>) {
|
||||
|
||||
when (player.isPersistentActionBarEnabled) {
|
||||
true -> {
|
||||
player.sendCompatibleActionBarMessage("")
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.willfp.ecoskills.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
import com.willfp.eco.core.placeholder.context.placeholderContext
|
||||
import com.willfp.eco.util.formatEco
|
||||
import com.willfp.eco.util.savedDisplayName
|
||||
import com.willfp.ecoskills.skills.Skills
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.util.StringUtil
|
||||
|
||||
|
||||
class CommandTop(plugin: EcoPlugin) :
|
||||
Subcommand(
|
||||
plugin,
|
||||
"top",
|
||||
"ecoskills.command.top",
|
||||
false
|
||||
) {
|
||||
|
||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||
val skill = Skills.getByID(args.getOrNull(0))
|
||||
|
||||
val pageIndex = if (skill == null) 0 else 1
|
||||
val page = args.getOrNull(pageIndex)?.toIntOrNull() ?: 1
|
||||
|
||||
if (skill == null && args.getOrNull(pageIndex)?.toIntOrNull() == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-skill"))
|
||||
return
|
||||
}
|
||||
|
||||
val positions = ((page)..(page + 9)).toList()
|
||||
|
||||
val top = if (skill == null) {
|
||||
positions.mapNotNull { Skills.getTop(it) }
|
||||
} else {
|
||||
positions.mapNotNull { skill.getTop(it) }
|
||||
}
|
||||
|
||||
val messages = plugin.langYml.getStrings("top.format")
|
||||
val lines = mutableListOf<String>()
|
||||
|
||||
for ((index, entry) in top.withIndex()) {
|
||||
val (player, level) = entry
|
||||
|
||||
val line = plugin.langYml.getString("top-line-format")
|
||||
.replace("%rank%", positions[index].toString())
|
||||
.replace("%level%", level.toString())
|
||||
.replace("%player%", player.savedDisplayName)
|
||||
|
||||
lines.add(line)
|
||||
}
|
||||
|
||||
val linesIndex = messages.indexOf("%lines%")
|
||||
|
||||
if (linesIndex != -1) {
|
||||
messages.removeAt(linesIndex)
|
||||
messages.addAll(linesIndex, lines)
|
||||
}
|
||||
|
||||
for (message in messages) {
|
||||
sender.sendMessage(
|
||||
message.formatEco(
|
||||
placeholderContext(
|
||||
player = sender as? Player
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
if (args.size == 1) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
listOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||
completions
|
||||
)
|
||||
return completions
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.willfp.eco.core.placeholder.context.PlaceholderContext
|
||||
import com.willfp.eco.util.savedDisplayName
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class EcoSkillsTopPlaceholder(
|
||||
class EcoSkillsSkillTopPlaceholder(
|
||||
private val plugin: EcoPlugin
|
||||
) : RegistrablePlaceholder {
|
||||
private val pattern = Pattern.compile("(top_)[a-z]+_[0-9]+_[a-z]+")
|
||||
@@ -31,7 +31,36 @@ class EcoSkillsTopPlaceholder(
|
||||
|
||||
return when (args.last()) {
|
||||
"name" -> skill.getTop(place)?.player?.savedDisplayName
|
||||
"amount" -> skill.getTop(place)?.level?.toString()
|
||||
"level", "amount" -> skill.getTop(place)?.level?.toString()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EcoSkillsTopPlaceholder(
|
||||
private val plugin: EcoPlugin
|
||||
) : RegistrablePlaceholder {
|
||||
private val pattern = Pattern.compile("(top_)[0-9]+_[a-z]+")
|
||||
|
||||
override fun getPattern(): Pattern = pattern
|
||||
override fun getPlugin(): EcoPlugin = plugin
|
||||
|
||||
override fun getValue(params: String, ctx: PlaceholderContext): String? {
|
||||
val args = params.split("_")
|
||||
|
||||
if (args.size < 2) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (args[0] != "top") {
|
||||
return null
|
||||
}
|
||||
|
||||
val place = args[1].toIntOrNull() ?: return null
|
||||
|
||||
return when (args.last()) {
|
||||
"name" -> Skills.getTop(place)?.player?.savedDisplayName
|
||||
"level", "amount" -> Skills.getTop(place)?.level?.toString()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,41 @@
|
||||
package com.willfp.ecoskills.skills
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.ecoskills.CategoryWithRegistry
|
||||
import com.willfp.ecoskills.EcoSkillsPlugin
|
||||
import com.willfp.ecoskills.api.totalSkillLevel
|
||||
import com.willfp.ecoskills.gui.menus.SkillsGUI
|
||||
import com.willfp.ecoskills.util.InvalidConfigurationException
|
||||
import com.willfp.ecoskills.util.LeaderboardEntry
|
||||
import com.willfp.libreforge.loader.LibreforgePlugin
|
||||
import org.bukkit.Bukkit
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object Skills : CategoryWithRegistry<Skill>("skill", "skills") {
|
||||
// Totally not copied over from Levellable
|
||||
private val leaderboardCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build<Boolean, List<UUID>> {
|
||||
Bukkit.getOfflinePlayers().sortedByDescending {
|
||||
it.totalSkillLevel
|
||||
}.map { it.uniqueId }
|
||||
}
|
||||
|
||||
fun getTop(position: Int): LeaderboardEntry? {
|
||||
require(position > 0) { "Position must be greater than 0" }
|
||||
|
||||
val uuid = leaderboardCache.get(true).getOrNull(position - 1) ?: return null
|
||||
|
||||
val player = Bukkit.getOfflinePlayer(uuid).takeIf { it.hasPlayedBefore() } ?: return null
|
||||
|
||||
return LeaderboardEntry(
|
||||
player,
|
||||
player.totalSkillLevel
|
||||
)
|
||||
}
|
||||
|
||||
override fun clear(plugin: LibreforgePlugin) {
|
||||
registry.clear()
|
||||
}
|
||||
|
||||
@@ -5,23 +5,16 @@ messages:
|
||||
invalid-command: "&cUnknown subcommand!"
|
||||
reloaded: "Reloaded!"
|
||||
|
||||
requires-player: "&cYou must specify a player!"
|
||||
invalid-player: "&cInvalid player!"
|
||||
requires-effect: "&cYou must specify an effect!"
|
||||
invalid-effect: "&cInvalid effect!"
|
||||
invalid-skill: "&cInvalid skill!"
|
||||
reset-player: "&fReset player!"
|
||||
recounted-player: "&fRecounted effect &6%effect% &ffor player &a%player%&f to level &6%level%&f!"
|
||||
invalid-skill-stat: "&cInvalid skill or stat!"
|
||||
requires-amount: "&cYou must specify the amount!"
|
||||
invalid-amount: "&cInvalid amount!"
|
||||
gave-skill-xp: "Gave %player% %amount% %obj% experience!"
|
||||
gave-stat: "Gave %player% %amount% %obj%&r!"
|
||||
enabled-actionbar: "&fYou have &aenabled &fthe action bar!"
|
||||
disabled-actionbar: "&fYou have &cdisabled &fthe action bar!"
|
||||
actionbar-disabled: "&cThe action bar is disabled on this server."
|
||||
enabled-xp-gain-sound: "&fYou have &aenabled &fskill XP gain sound!"
|
||||
disabled-xp-gain-sound: "&fYou have &cdisabled &fskill XP gain sound!"
|
||||
xp-gain-sound-disabled: "&cSkill XP gain sound is disabled on this server."
|
||||
resetting-all-players: "&fResetting all players... (this may take a while)"
|
||||
reset-all-players: "&fReset all players!"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user