9
0
mirror of https://github.com/Auxilor/EcoJobs.git synced 2025-12-20 15:39:26 +00:00

Compare commits

..

14 Commits
2.0.0 ... 2.1.4

Author SHA1 Message Date
Auxilor
edf978fa28 libreforge-updater 2023-03-13 13:38:53 +00:00
Auxilor
5504a89f1b libreforge-updater 2023-03-02 12:54:27 +00:00
Auxilor
ae3f3ac2d3 Updated to 2.1.2 2023-02-25 17:53:51 +00:00
Auxilor
704dfc65e5 Fixed dependencies 2023-02-25 17:38:56 +00:00
Auxilor
2169581466 libreforge-updater 2023-02-22 15:01:32 +00:00
Auxilor
034265a0e9 Updated to 2.1.0 2023-02-18 12:11:11 +00:00
Will FP
4eded008fe Merge pull request #20 from PQguanfang/master
Add %level_numeral% placeholder in Job Main and Job Level Gui
2023-02-18 12:09:01 +00:00
Will FP
7492f3e548 Merge pull request #21
Fixed inappropriate xp gain handling
2023-02-18 12:07:38 +00:00
_OfTeN_
6bf9d371b9 Fixed leaderboard placeholders updating 2023-02-18 02:20:16 +03:00
_OfTeN_
4034f5098f Added %ecojobs_top_<job>_<place>_<name/amount>% placeholder 2023-02-17 04:45:45 +03:00
_OfTeN_
2014a6dd5f Updated eco 2023-02-17 04:44:33 +03:00
_OfTeN_
bcf5ef3b0f Fixed inappropriate xp gain handling 2023-02-17 03:54:57 +03:00
PQguanfang
7e10899c72 Merge pull request #1 from PQguanfang/dev
Update Job.kt
2023-02-16 15:10:08 +08:00
PQguanfang
9bd24ed4e9 Update Job.kt 2023-02-16 15:07:56 +08:00
8 changed files with 55 additions and 9 deletions

View File

@@ -47,8 +47,8 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:6.46.0'
implementation 'com.willfp:libreforge:3.129.2'
compileOnly 'com.willfp:eco:6.51.1'
implementation 'com.willfp:libreforge:3.129.5'
implementation 'com.willfp:ecomponent:1.3.0'
implementation 'org.joml:joml:1.10.4'

View File

@@ -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<PluginCommand> {

View File

@@ -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,6 +48,10 @@ import kotlin.math.max
class Job(
val id: String, val config: Config, private val plugin: EcoJobsPlugin
) {
private val topCache = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("leaderboard-cache-lifetime").toLong()))
.build<Int, LeaderboardCacheEntry?>()
val name = config.getFormattedString("name")
val description = config.getFormattedString("description")
val isUnlockedByDefault = config.getBool("unlocked-by-default")
@@ -272,6 +277,7 @@ class Job(
}
}).replace("%description%", this.description).replace("%job%", this.name)
.replace("%level%", (forceLevel ?: player.getJobLevel(this)).toString())
.replace("%level_numeral%", NumberUtils.toNumeral(forceLevel ?: player.getJobLevel(this)))
.replace("%join_price%", this.joinPrice.getDisplay(player))
.replace("%leave_price%", this.leavePrice.getDisplay(player))
}.toMutableList()
@@ -308,7 +314,7 @@ class Job(
return ItemStackBuilder(base).setDisplayName(
plugin.configYml.getFormattedString("gui.job-icon.name").replace("%level%", level.toString())
.replace("%job%", this.name)
.replace("%level_numeral%", NumberUtils.toNumeral(level)).replace("%job%", this.name)
).addLoreLines {
injectPlaceholdersInto(
plugin.configYml.getStrings("gui.job-icon.lore"), player
@@ -328,7 +334,7 @@ class Job(
val base = baseItem.clone()
return ItemStackBuilder(base).setDisplayName(
plugin.configYml.getFormattedString("gui.job-info.active.name")
.replace("%level%", player.getJobLevel(this).toString()).replace("%job%", this.name)
.replace("%level%", player.getJobLevel(this).toString()).replace("%level_numeral%", NumberUtils.toNumeral(player.getJobLevel(this))).replace("%job%", this.name)
).addLoreLines {
injectPlaceholdersInto(plugin.configYml.getStrings("gui.job-info.active.lore"), player)
}.build()
@@ -354,6 +360,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 +387,11 @@ private class LevelPlaceholder(
operator fun invoke(level: Int) = function(level)
}
data class LeaderboardCacheEntry(
val player: OfflinePlayer,
val amount: Int
)
private fun Collection<LevelPlaceholder>.format(string: String, level: Int): String {
var process = string
for (placeholder in this) {

View File

@@ -17,7 +17,7 @@ object JobTriggerXPGainListener : Listener {
val amount = job.getXP(event)
if (amount <= 0.0) {
return
continue
}
player.giveJobExperience(job, amount)

View File

@@ -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:

View File

@@ -42,3 +42,7 @@ menu:
title: "Jobs"
infinity: "∞"
top:
name-empty: "&cEmpty"
amount-empty: "0"

View File

@@ -7,8 +7,6 @@ website: willfp.com
load: STARTUP
depend:
- eco
- ProtocolLib
- PlaceholderAPI
softdepend:
- AureliumSkills
- Vault

View File

@@ -1,4 +1,4 @@
#libreforge-updater
#Wed Feb 15 20:57:47 GMT 2023
version=2.0.0
#Mon Mar 13 13:38:53 GMT 2023
version=2.1.4
plugin-name=EcoJobs