mirror of
https://github.com/Auxilor/EcoJobs.git
synced 2025-12-21 07:59:15 +00:00
Fixed xp-required and placeholders.
This commit is contained in:
@@ -39,7 +39,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.willfp:eco:6.55.0")
|
compileOnly("com.willfp:eco:6.56.0")
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:2.1.0")
|
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:2.1.0")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ fun OfflinePlayer.resetJob(job: Job) {
|
|||||||
/**
|
/**
|
||||||
* Get the experience required to advance to the next level.
|
* Get the experience required to advance to the next level.
|
||||||
*/
|
*/
|
||||||
fun OfflinePlayer.getJobXPRequired(job: Job) = job.getExpForLevel(this.getJobLevel(job) + 1)
|
fun OfflinePlayer.getJobXPRequired(job: Job) = job.getFormattedExpForLevel(this.getJobLevel(job) + 1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get progress to next level between 0 and 1, where 0 is none and 1 is complete.
|
* Get progress to next level between 0 and 1, where 0 is none and 1 is complete.
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import com.willfp.eco.core.data.keys.PersistentDataKey
|
|||||||
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
||||||
import com.willfp.eco.core.items.Items
|
import com.willfp.eco.core.items.Items
|
||||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
|
||||||
import com.willfp.eco.core.placeholder.PlayerPlaceholder
|
import com.willfp.eco.core.placeholder.PlayerPlaceholder
|
||||||
import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder
|
import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder
|
||||||
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
||||||
import com.willfp.eco.core.placeholder.StaticPlaceholder
|
import com.willfp.eco.core.placeholder.context.placeholderContext
|
||||||
import com.willfp.eco.core.price.ConfiguredPrice
|
import com.willfp.eco.core.price.ConfiguredPrice
|
||||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||||
import com.willfp.eco.core.registry.Registrable
|
import com.willfp.eco.core.registry.Registrable
|
||||||
@@ -27,6 +26,7 @@ import com.willfp.ecojobs.api.getJobXP
|
|||||||
import com.willfp.ecojobs.api.getJobXPRequired
|
import com.willfp.ecojobs.api.getJobXPRequired
|
||||||
import com.willfp.ecojobs.api.hasJobActive
|
import com.willfp.ecojobs.api.hasJobActive
|
||||||
import com.willfp.ecojobs.api.jobLimit
|
import com.willfp.ecojobs.api.jobLimit
|
||||||
|
import com.willfp.ecojobs.util.LevelInjectable
|
||||||
import com.willfp.libreforge.ViolationContext
|
import com.willfp.libreforge.ViolationContext
|
||||||
import com.willfp.libreforge.conditions.ConditionList
|
import com.willfp.libreforge.conditions.ConditionList
|
||||||
import com.willfp.libreforge.conditions.Conditions
|
import com.willfp.libreforge.conditions.Conditions
|
||||||
@@ -286,13 +286,8 @@ class Job(
|
|||||||
val withPlaceholders = lore.map {
|
val withPlaceholders = lore.map {
|
||||||
it.replace("%percentage_progress%", (player.getJobProgress(this) * 100).toNiceString())
|
it.replace("%percentage_progress%", (player.getJobProgress(this) * 100).toNiceString())
|
||||||
.replace("%current_xp%", player.getJobXP(this).toNiceString())
|
.replace("%current_xp%", player.getJobXP(this).toNiceString())
|
||||||
.replace("%required_xp%", this.getExpForLevel(player.getJobLevel(this) + 1).let { req ->
|
.replace("%required_xp%", this.getFormattedExpForLevel(player.getJobLevel(this) + 1))
|
||||||
if (req == Int.MAX_VALUE) {
|
.replace("%description%", this.description).replace("%job%", this.name)
|
||||||
plugin.langYml.getFormattedString("infinity")
|
|
||||||
} else {
|
|
||||||
req.toNiceString()
|
|
||||||
}
|
|
||||||
}).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("%level_numeral%", NumberUtils.toNumeral(forceLevel ?: player.getJobLevel(this)))
|
||||||
.replace("%join_price%", this.joinPrice.getDisplay(player))
|
.replace("%join_price%", this.joinPrice.getDisplay(player))
|
||||||
@@ -358,27 +353,34 @@ class Job(
|
|||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExpForLevel(level: Int): Int {
|
/**
|
||||||
if (level < 1 || level > maxLevel) {
|
* Get the XP required to reach the next level, if currently at [level].
|
||||||
return Int.MAX_VALUE
|
*/
|
||||||
}
|
fun getExpForLevel(level: Int): Double {
|
||||||
|
|
||||||
// Use levelXpRequirements if it exists and covers the level
|
|
||||||
if (levelXpRequirements != null && levelXpRequirements.size >= level) {
|
|
||||||
return levelXpRequirements[level - 1].toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to using the xpFormula if it exists
|
|
||||||
if (xpFormula != null) {
|
if (xpFormula != null) {
|
||||||
return evaluateExpression(
|
return evaluateExpression(
|
||||||
xpFormula.replace("%level%", level.toString())
|
xpFormula,
|
||||||
).toInt()
|
placeholderContext(
|
||||||
|
injectable = LevelInjectable(level)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback if neither configuration is usable
|
if (levelXpRequirements != null) {
|
||||||
return Int.MAX_VALUE
|
return levelXpRequirements.getOrNull(level) ?: Double.POSITIVE_INFINITY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Double.POSITIVE_INFINITY
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFormattedExpForLevel(level: Int): String {
|
||||||
|
val required = getExpForLevel(level)
|
||||||
|
return if (required.isInfinite()) {
|
||||||
|
plugin.langYml.getFormattedString("infinity")
|
||||||
|
} else {
|
||||||
|
required.toNiceString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun executeLevelCommands(player: Player, level: Int) {
|
fun executeLevelCommands(player: Player, level: Int) {
|
||||||
val commands = levelCommands[level] ?: emptyList()
|
val commands = levelCommands[level] ?: emptyList()
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.willfp.ecojobs.util
|
||||||
|
|
||||||
|
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
||||||
|
import com.willfp.eco.core.placeholder.PlaceholderInjectable
|
||||||
|
import com.willfp.eco.core.placeholder.StaticPlaceholder
|
||||||
|
|
||||||
|
class LevelInjectable(
|
||||||
|
level: Int
|
||||||
|
) : PlaceholderInjectable {
|
||||||
|
private val placeholders = listOf(
|
||||||
|
StaticPlaceholder(
|
||||||
|
"level"
|
||||||
|
) { level.toString() }
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
|
||||||
|
return placeholders
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addInjectablePlaceholder(p0: Iterable<InjectablePlaceholder>) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clearInjectedPlaceholders() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user