mirror of
https://github.com/Auxilor/EcoJobs.git
synced 2025-12-20 07:29:20 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edf978fa28 | ||
|
|
5504a89f1b | ||
|
|
ae3f3ac2d3 | ||
|
|
704dfc65e5 | ||
|
|
2169581466 | ||
|
|
034265a0e9 | ||
|
|
4eded008fe | ||
|
|
7492f3e548 | ||
|
|
6bf9d371b9 | ||
|
|
4034f5098f | ||
|
|
2014a6dd5f | ||
|
|
bcf5ef3b0f | ||
|
|
7e10899c72 | ||
|
|
9bd24ed4e9 |
@@ -47,8 +47,8 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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:libreforge:3.129.5'
|
||||||
implementation 'com.willfp:ecomponent:1.3.0'
|
implementation 'com.willfp:ecomponent:1.3.0'
|
||||||
implementation 'org.joml:joml:1.10.4'
|
implementation 'org.joml:joml:1.10.4'
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.willfp.ecojobs
|
package com.willfp.ecojobs
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
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.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.activeJobs
|
||||||
import com.willfp.ecojobs.api.getJobLevel
|
import com.willfp.ecojobs.api.getJobLevel
|
||||||
import com.willfp.ecojobs.api.jobLimit
|
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.ecojobs.jobs.ResetOnQuitListener
|
||||||
import com.willfp.libreforge.LibReforgePlugin
|
import com.willfp.libreforge.LibReforgePlugin
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
class EcoJobsPlugin : LibReforgePlugin() {
|
class EcoJobsPlugin : LibReforgePlugin() {
|
||||||
init {
|
init {
|
||||||
@@ -46,6 +50,26 @@ class EcoJobsPlugin : LibReforgePlugin() {
|
|||||||
}
|
}
|
||||||
level.toString()
|
level.toString()
|
||||||
}.register()
|
}.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> {
|
override fun loadPluginCommands(): List<PluginCommand> {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.bukkit.Bukkit
|
|||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import java.time.Duration
|
||||||
import java.util.DoubleSummaryStatistics
|
import java.util.DoubleSummaryStatistics
|
||||||
import java.util.Objects
|
import java.util.Objects
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@@ -47,6 +48,10 @@ import kotlin.math.max
|
|||||||
class Job(
|
class Job(
|
||||||
val id: String, val config: Config, private val plugin: EcoJobsPlugin
|
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 name = config.getFormattedString("name")
|
||||||
val description = config.getFormattedString("description")
|
val description = config.getFormattedString("description")
|
||||||
val isUnlockedByDefault = config.getBool("unlocked-by-default")
|
val isUnlockedByDefault = config.getBool("unlocked-by-default")
|
||||||
@@ -272,6 +277,7 @@ class Job(
|
|||||||
}
|
}
|
||||||
}).replace("%description%", this.description).replace("%job%", this.name)
|
}).replace("%description%", this.description).replace("%job%", this.name)
|
||||||
.replace("%level%", (forceLevel ?: player.getJobLevel(this)).toString())
|
.replace("%level%", (forceLevel ?: player.getJobLevel(this)).toString())
|
||||||
|
.replace("%level_numeral%", NumberUtils.toNumeral(forceLevel ?: player.getJobLevel(this)))
|
||||||
.replace("%join_price%", this.joinPrice.getDisplay(player))
|
.replace("%join_price%", this.joinPrice.getDisplay(player))
|
||||||
.replace("%leave_price%", this.leavePrice.getDisplay(player))
|
.replace("%leave_price%", this.leavePrice.getDisplay(player))
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
@@ -308,7 +314,7 @@ class Job(
|
|||||||
|
|
||||||
return ItemStackBuilder(base).setDisplayName(
|
return ItemStackBuilder(base).setDisplayName(
|
||||||
plugin.configYml.getFormattedString("gui.job-icon.name").replace("%level%", level.toString())
|
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 {
|
).addLoreLines {
|
||||||
injectPlaceholdersInto(
|
injectPlaceholdersInto(
|
||||||
plugin.configYml.getStrings("gui.job-icon.lore"), player
|
plugin.configYml.getStrings("gui.job-icon.lore"), player
|
||||||
@@ -328,7 +334,7 @@ class Job(
|
|||||||
val base = baseItem.clone()
|
val base = baseItem.clone()
|
||||||
return ItemStackBuilder(base).setDisplayName(
|
return ItemStackBuilder(base).setDisplayName(
|
||||||
plugin.configYml.getFormattedString("gui.job-info.active.name")
|
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 {
|
).addLoreLines {
|
||||||
injectPlaceholdersInto(plugin.configYml.getStrings("gui.job-info.active.lore"), player)
|
injectPlaceholdersInto(plugin.configYml.getStrings("gui.job-info.active.lore"), player)
|
||||||
}.build()
|
}.build()
|
||||||
@@ -354,6 +360,14 @@ class Job(
|
|||||||
return jobXpGains.sumOf { it.getCount(event) }
|
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 {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other !is Job) {
|
if (other !is Job) {
|
||||||
return false
|
return false
|
||||||
@@ -373,6 +387,11 @@ private class LevelPlaceholder(
|
|||||||
operator fun invoke(level: Int) = function(level)
|
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 {
|
private fun Collection<LevelPlaceholder>.format(string: String, level: Int): String {
|
||||||
var process = string
|
var process = string
|
||||||
for (placeholder in this) {
|
for (placeholder in this) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ object JobTriggerXPGainListener : Listener {
|
|||||||
val amount = job.getXP(event)
|
val amount = job.getXP(event)
|
||||||
|
|
||||||
if (amount <= 0.0) {
|
if (amount <= 0.0) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
player.giveJobExperience(job, amount)
|
player.giveJobExperience(job, amount)
|
||||||
|
|||||||
@@ -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
|
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
|
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:
|
potions:
|
||||||
icon:
|
icon:
|
||||||
|
|||||||
@@ -42,3 +42,7 @@ menu:
|
|||||||
title: "Jobs"
|
title: "Jobs"
|
||||||
|
|
||||||
infinity: "∞"
|
infinity: "∞"
|
||||||
|
|
||||||
|
top:
|
||||||
|
name-empty: "&cEmpty"
|
||||||
|
amount-empty: "0"
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ website: willfp.com
|
|||||||
load: STARTUP
|
load: STARTUP
|
||||||
depend:
|
depend:
|
||||||
- eco
|
- eco
|
||||||
- ProtocolLib
|
|
||||||
- PlaceholderAPI
|
|
||||||
softdepend:
|
softdepend:
|
||||||
- AureliumSkills
|
- AureliumSkills
|
||||||
- Vault
|
- Vault
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#libreforge-updater
|
#libreforge-updater
|
||||||
#Wed Feb 15 20:57:47 GMT 2023
|
#Mon Mar 13 13:38:53 GMT 2023
|
||||||
version=2.0.0
|
version=2.1.4
|
||||||
plugin-name=EcoJobs
|
plugin-name=EcoJobs
|
||||||
|
|||||||
Reference in New Issue
Block a user