mirror of
https://github.com/Auxilor/EcoJobs.git
synced 2025-12-23 08:59:22 +00:00
Added leave price
This commit is contained in:
@@ -7,7 +7,7 @@ import com.willfp.ecojobs.commands.CommandEcojobs
|
|||||||
import com.willfp.ecojobs.commands.CommandJobs
|
import com.willfp.ecojobs.commands.CommandJobs
|
||||||
import com.willfp.ecojobs.jobs.JobLevelListener
|
import com.willfp.ecojobs.jobs.JobLevelListener
|
||||||
import com.willfp.ecojobs.jobs.JobTriggerXPGainListener
|
import com.willfp.ecojobs.jobs.JobTriggerXPGainListener
|
||||||
import com.willfp.ecojobs.jobs.JoinPriceHandler
|
import com.willfp.ecojobs.jobs.PriceHandler
|
||||||
import com.willfp.ecojobs.jobs.ResetOnQuitListener
|
import com.willfp.ecojobs.jobs.ResetOnQuitListener
|
||||||
import com.willfp.ecojobs.jobs.activeJob
|
import com.willfp.ecojobs.jobs.activeJob
|
||||||
import com.willfp.ecojobs.jobs.activeJobLevel
|
import com.willfp.ecojobs.jobs.activeJobLevel
|
||||||
@@ -46,7 +46,7 @@ class EcoJobsPlugin : LibReforgePlugin() {
|
|||||||
JobLevelListener(this),
|
JobLevelListener(this),
|
||||||
JobTriggerXPGainListener,
|
JobTriggerXPGainListener,
|
||||||
ResetOnQuitListener,
|
ResetOnQuitListener,
|
||||||
JoinPriceHandler
|
PriceHandler
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class Job(
|
|||||||
val isUnlockedByDefault = config.getBool("unlocked-by-default")
|
val isUnlockedByDefault = config.getBool("unlocked-by-default")
|
||||||
val resetsOnQuit = config.getBool("reset-on-quit")
|
val resetsOnQuit = config.getBool("reset-on-quit")
|
||||||
val joinPrice = config.getDouble("join-price")
|
val joinPrice = config.getDouble("join-price")
|
||||||
|
val leavePrice = config.getDouble("leave-price")
|
||||||
|
|
||||||
val levelKey: PersistentDataKey<Int> = PersistentDataKey(
|
val levelKey: PersistentDataKey<Int> = PersistentDataKey(
|
||||||
EcoJobsPlugin.instance.namespacedKeyFactory.create("${id}_level"),
|
EcoJobsPlugin.instance.namespacedKeyFactory.create("${id}_level"),
|
||||||
@@ -255,7 +256,8 @@ class Job(
|
|||||||
.replace("%description%", this.description)
|
.replace("%description%", this.description)
|
||||||
.replace("%job%", this.name)
|
.replace("%job%", this.name)
|
||||||
.replace("%level%", (forceLevel ?: player.getJobLevel(this)).toString())
|
.replace("%level%", (forceLevel ?: player.getJobLevel(this)).toString())
|
||||||
.replace("%cost%", NumberUtils.format(this.joinPrice))
|
.replace("%join_price%", NumberUtils.format(this.joinPrice))
|
||||||
|
.replace("%leave_price%", NumberUtils.format(this.leavePrice))
|
||||||
}
|
}
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.willfp.ecojobs.jobs
|
||||||
|
|
||||||
|
import com.willfp.eco.core.integrations.economy.balance
|
||||||
|
import com.willfp.ecojobs.api.event.PlayerJobJoinEvent
|
||||||
|
import com.willfp.ecojobs.api.event.PlayerJobLeaveEvent
|
||||||
|
import org.bukkit.event.EventHandler
|
||||||
|
import org.bukkit.event.EventPriority
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
|
||||||
|
object PriceHandler : Listener {
|
||||||
|
@EventHandler(
|
||||||
|
priority = EventPriority.LOW,
|
||||||
|
ignoreCancelled = true
|
||||||
|
)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(
|
||||||
|
priority = EventPriority.LOW,
|
||||||
|
ignoreCancelled = true
|
||||||
|
)
|
||||||
|
fun onLeave(event: PlayerJobLeaveEvent) {
|
||||||
|
val player = event.player
|
||||||
|
val job = event.job
|
||||||
|
val price = job.leavePrice
|
||||||
|
|
||||||
|
if (price > 0) {
|
||||||
|
val hasMoney = player.balance >= price
|
||||||
|
|
||||||
|
if (!hasMoney) {
|
||||||
|
event.isCancelled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
player.balance -= price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,10 @@ import com.willfp.ecojobs.api.event.PlayerJobLeaveEvent
|
|||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
|
|
||||||
object ResetOnQuitListener: Listener {
|
object ResetOnQuitListener : Listener {
|
||||||
@EventHandler
|
@EventHandler(
|
||||||
|
ignoreCancelled = true
|
||||||
|
)
|
||||||
fun onQuit(event: PlayerJobLeaveEvent) {
|
fun onQuit(event: PlayerJobLeaveEvent) {
|
||||||
val player = event.player
|
val player = event.player
|
||||||
val job = event.job
|
val job = event.job
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ gui:
|
|||||||
- ""
|
- ""
|
||||||
item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmFkYzA0OGE3Y2U3OGY3ZGFkNzJhMDdkYTI3ZDg1YzA5MTY4ODFlNTUyMmVlZWQxZTNkYWYyMTdhMzhjMWEifX19
|
item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmFkYzA0OGE3Y2U3OGY3ZGFkNzJhMDdkYTI3ZDg1YzA5MTY4ODFlNTUyMmVlZWQxZTNkYWYyMTdhMzhjMWEifX19
|
||||||
|
|
||||||
|
# %join_price% and %leave_price% are also available as placeholders
|
||||||
|
|
||||||
active:
|
active:
|
||||||
name: "%job% &fLvl. &a%level%"
|
name: "%job% &fLvl. &a%level%"
|
||||||
lore:
|
lore:
|
||||||
@@ -78,7 +80,7 @@ gui:
|
|||||||
- ""
|
- ""
|
||||||
- "&cThis job is already active!"
|
- "&cThis job is already active!"
|
||||||
|
|
||||||
not-active-lore: # If using join cost, you can use %cost% as a placeholder.
|
not-active-lore:
|
||||||
- ""
|
- ""
|
||||||
- "&eClick to activate this job!"
|
- "&eClick to activate this job!"
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ unlocked-by-default: true
|
|||||||
# If job progress should be reset when quitting
|
# If job progress should be reset when quitting
|
||||||
reset-on-quit: false
|
reset-on-quit: false
|
||||||
|
|
||||||
# The price to join this job (set to 0 to disable)
|
# The price to join or leave this job (set to 0 to disable)
|
||||||
join-price: 0
|
join-price: 0
|
||||||
|
leave-price: 0
|
||||||
|
|
||||||
# The xp requirements for each job level - add new levels by adding more to this list
|
# The xp requirements for each job level - add new levels by adding more to this list
|
||||||
level-xp-requirements:
|
level-xp-requirements:
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ description: "&8&oLevel up by placing blocks"
|
|||||||
unlocked-by-default: true
|
unlocked-by-default: true
|
||||||
|
|
||||||
reset-on-quit: false
|
reset-on-quit: false
|
||||||
|
|
||||||
join-price: 0
|
join-price: 0
|
||||||
|
leave-price: 0
|
||||||
|
|
||||||
level-xp-requirements:
|
level-xp-requirements:
|
||||||
- 100
|
- 100
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ description: "&8&oLevel up by farming crops"
|
|||||||
unlocked-by-default: true
|
unlocked-by-default: true
|
||||||
|
|
||||||
reset-on-quit: false
|
reset-on-quit: false
|
||||||
|
|
||||||
join-price: 0
|
join-price: 0
|
||||||
|
leave-price: 0
|
||||||
|
|
||||||
level-xp-requirements:
|
level-xp-requirements:
|
||||||
- 100
|
- 100
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ description: "&8&oLevel up by mining blocks"
|
|||||||
unlocked-by-default: true
|
unlocked-by-default: true
|
||||||
|
|
||||||
reset-on-quit: false
|
reset-on-quit: false
|
||||||
|
|
||||||
join-price: 0
|
join-price: 0
|
||||||
|
leave-price: 0
|
||||||
|
|
||||||
level-xp-requirements:
|
level-xp-requirements:
|
||||||
- 100
|
- 100
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ description: "&8&oLevel up by killing mobs"
|
|||||||
unlocked-by-default: true
|
unlocked-by-default: true
|
||||||
|
|
||||||
reset-on-quit: false
|
reset-on-quit: false
|
||||||
|
|
||||||
join-price: 0
|
join-price: 0
|
||||||
|
leave-price: 0
|
||||||
|
|
||||||
level-xp-requirements:
|
level-xp-requirements:
|
||||||
- 100
|
- 100
|
||||||
|
|||||||
Reference in New Issue
Block a user