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

Added Join Price and Reset on Quit

This commit is contained in:
Auxilor
2022-09-14 13:23:22 +01:00
parent e33d3264d8
commit 7c06eb5c18
11 changed files with 78 additions and 6 deletions

View File

@@ -7,6 +7,8 @@ import com.willfp.ecojobs.commands.CommandEcojobs
import com.willfp.ecojobs.commands.CommandJobs
import com.willfp.ecojobs.jobs.JobLevelListener
import com.willfp.ecojobs.jobs.JobTriggerXPGainListener
import com.willfp.ecojobs.jobs.JoinPriceHandler
import com.willfp.ecojobs.jobs.ResetOnQuitListener
import com.willfp.ecojobs.jobs.activeJob
import com.willfp.ecojobs.jobs.activeJobLevel
import com.willfp.libreforge.LibReforgePlugin
@@ -42,7 +44,9 @@ class EcoJobsPlugin : LibReforgePlugin() {
override fun loadListeners(): List<Listener> {
return listOf(
JobLevelListener(this),
JobTriggerXPGainListener
JobTriggerXPGainListener,
ResetOnQuitListener,
JoinPriceHandler
)
}

View File

@@ -7,6 +7,7 @@ import com.willfp.eco.util.savedDisplayName
import com.willfp.ecojobs.jobs.Jobs
import com.willfp.ecojobs.jobs.activeJob
import com.willfp.ecojobs.jobs.hasJob
import com.willfp.ecojobs.jobs.resetJob
import com.willfp.ecojobs.jobs.setJobLevel
import com.willfp.ecojobs.jobs.setJobXP
import org.bukkit.Bukkit
@@ -48,8 +49,7 @@ class CommandReset(plugin: EcoPlugin) : Subcommand(plugin, "reset", "ecojobs.com
if (player.activeJob == job) {
player.activeJob = null
}
player.setJobXP(job, 0.0)
player.setJobLevel(job, 1)
player.resetJob(job)
sender.sendMessage(
plugin.langYml.getMessage("reset-xp", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)

View File

@@ -40,6 +40,8 @@ class Job(
val name = config.getFormattedString("name")
val description = config.getFormattedString("description")
val isUnlockedByDefault = config.getBool("unlocked-by-default")
val resetsOnQuit = config.getBool("reset-on-quit")
val joinPrice = config.getDouble("join-price")
val levelKey: PersistentDataKey<Int> = PersistentDataKey(
EcoJobsPlugin.instance.namespacedKeyFactory.create("${id}_level"),
@@ -253,6 +255,7 @@ class Job(
.replace("%description%", this.description)
.replace("%job%", this.name)
.replace("%level%", (forceLevel ?: player.getJobLevel(this)).toString())
.replace("%cost%", NumberUtils.format(this.joinPrice))
}
.toMutableList()
@@ -407,6 +410,11 @@ fun OfflinePlayer.getJobLevel(job: Job): Int =
fun OfflinePlayer.setJobLevel(job: Job, level: Int) =
this.profile.write(job.levelKey, level)
fun OfflinePlayer.resetJob(job: Job) {
this.setJobLevel(job, 1)
this.setJobXP(job, 0.0)
}
fun OfflinePlayer.getJobProgress(job: Job): Double {
val currentXP = this.getJobXP(job)
val requiredXP = job.getExpForLevel(this.getJobLevel(job) + 1)

View File

@@ -0,0 +1,25 @@
package com.willfp.ecojobs.jobs
import com.willfp.eco.core.integrations.economy.balance
import com.willfp.ecojobs.api.event.PlayerJobJoinEvent
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
object JoinPriceHandler : Listener {
@EventHandler
fun onJoin(event: PlayerJobJoinEvent) {
val player = event.player
val job = event.job
val price = job.joinPrice
if (price > 0) {
val hasMoney = player.balance >= price
if (!hasMoney) {
event.isCancelled = true
}
player.balance -= price
}
}
}

View File

@@ -0,0 +1,17 @@
package com.willfp.ecojobs.jobs
import com.willfp.ecojobs.api.event.PlayerJobLeaveEvent
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
object ResetOnQuitListener: Listener {
@EventHandler
fun onQuit(event: PlayerJobLeaveEvent) {
val player = event.player
val job = event.job
if (job.resetsOnQuit) {
player.resetJob(job)
}
}
}

View File

@@ -53,7 +53,7 @@ gui:
lore:
- "%description%"
- "&f"
- "&fEffects:"
- "&fJob Rewards:"
- "%effects%"
- ""
- "&fProgress:"
@@ -67,7 +67,7 @@ gui:
lore:
- "%description%"
- "&f"
- "&fEffects:"
- "&fJob Rewards:"
- "%effects%"
- ""
- "&fProgress:"
@@ -78,7 +78,7 @@ gui:
- ""
- "&cThis job is already active!"
not-active-lore:
not-active-lore: # If using join cost, you can use %cost% as a placeholder.
- ""
- "&eClick to activate this job!"

View File

@@ -13,6 +13,12 @@ description: "&8&oLevel up by mining blocks"
# If the job should be unlocked by default
unlocked-by-default: true
# If job progress should be reset when quitting
reset-on-quit: false
# The price to join this job (set to 0 to disable)
join-price: 0
# The xp requirements for each job level - add new levels by adding more to this list
level-xp-requirements:
- 100

View File

@@ -3,6 +3,9 @@ description: "&8&oLevel up by placing blocks"
unlocked-by-default: true
reset-on-quit: false
join-price: 0
level-xp-requirements:
- 100
- 120

View File

@@ -3,6 +3,9 @@ description: "&8&oLevel up by farming crops"
unlocked-by-default: true
reset-on-quit: false
join-price: 0
level-xp-requirements:
- 100
- 120

View File

@@ -3,6 +3,9 @@ description: "&8&oLevel up by mining blocks"
unlocked-by-default: true
reset-on-quit: false
join-price: 0
level-xp-requirements:
- 100
- 120

View File

@@ -3,6 +3,9 @@ description: "&8&oLevel up by killing mobs"
unlocked-by-default: true
reset-on-quit: false
join-price: 0
level-xp-requirements:
- 100
- 120