Skip to content

Commit

Permalink
libreforge-updater
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 21, 2023
1 parent 7763ea4 commit fe59c30
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import com.willfp.libreforge.filters.Filters
import com.willfp.libreforge.loader.LibreforgePlugin
import com.willfp.libreforge.loader.configs.ConfigCategory
import com.willfp.libreforge.registerHolderProvider
import com.willfp.libreforge.registerSpecificHolderProvider
import com.willfp.libreforge.triggers.Triggers
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import java.util.regex.Pattern

Expand All @@ -56,7 +58,7 @@ class EcoJobsPlugin : LibreforgePlugin() {
Triggers.register(TriggerLeaveJob)
Filters.register(FilterJob)

registerHolderProvider { player ->
registerSpecificHolderProvider<Player> { player ->
player.activeJobs.map { it.getLevel(player.getJobLevel(it)) }.map {
SimpleProvidedHolder(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ package com.willfp.ecojobs.libreforge

import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecojobs.api.activeJobs
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.get
import org.bukkit.entity.Player

object ConditionHasActiveJob : Condition<NoCompileData>("has_active_job") {
override val arguments = arguments {
require("job", "You must specify the job!")
}

override fun isMet(player: Player, config: Config, compileData: NoCompileData): Boolean {
override fun isMet(
dispatcher: Dispatcher<*>,
config: Config,
holder: ProvidedHolder,
compileData: NoCompileData
): Boolean {
val player = dispatcher.get<Player>() ?: return false

return player.activeJobs.any { it.id == config.getString("job").lowercase() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecojobs.api.event.PlayerJobLevelUpEvent
import com.willfp.ecojobs.api.getJobLevel
import com.willfp.ecojobs.jobs.Jobs
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.get
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.updateEffects
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
Expand All @@ -18,14 +22,21 @@ object ConditionHasJobLevel : Condition<NoCompileData>("has_job_level") {
require("level", "You must specify the level!")
}

override fun isMet(player: Player, config: Config, compileData: NoCompileData): Boolean {
override fun isMet(
dispatcher: Dispatcher<*>,
config: Config,
holder: ProvidedHolder,
compileData: NoCompileData
): Boolean {
val player = dispatcher.get<Player>() ?: return false

return player.getJobLevel(
Jobs.getByID(config.getString("job").lowercase()) ?: return false
) >= config.getIntFromExpression("level", player)
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun handle(event: PlayerJobLevelUpEvent) {
event.player.updateEffects()
event.player.toDispatcher().updateEffects()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.willfp.ecojobs.api.event.PlayerJobExpGainEvent
import com.willfp.ecojobs.jobs.Job
import com.willfp.ecojobs.jobs.Jobs
import com.willfp.libreforge.effects.templates.MultiMultiplierEffect
import com.willfp.libreforge.toDispatcher
import org.bukkit.event.EventHandler

object EffectJobXpMultiplier : MultiMultiplierEffect<Job>("job_xp_multiplier") {
Expand All @@ -19,6 +20,6 @@ object EffectJobXpMultiplier : MultiMultiplierEffect<Job>("job_xp_multiplier") {

@EventHandler(ignoreCancelled = true)
fun handle(event: PlayerJobExpGainEvent) {
event.amount *= getMultiplier(event.player, event.job)
event.amount *= getMultiplier(event.player.toDispatcher(), event.job)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.willfp.ecojobs.libreforge

import com.willfp.ecojobs.api.event.PlayerJobExpGainEvent
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -18,7 +19,7 @@ object TriggerGainJobXp : Trigger("gain_job_xp") {
val player = event.player

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.willfp.ecojobs.libreforge

import com.willfp.ecojobs.api.event.PlayerJobJoinEvent
import com.willfp.ecojobs.api.getJobLevel
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -20,7 +21,7 @@ object TriggerJoinJob : Trigger("join_job") {
val player = event.player as? Player ?: return

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.willfp.ecojobs.libreforge

import com.willfp.ecojobs.api.event.PlayerJobLeaveEvent
import com.willfp.ecojobs.api.getJobLevel
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -19,7 +20,7 @@ object TriggerLeaveJob : Trigger("leave_job") {
val player = event.player as? Player ?: return

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.willfp.ecojobs.libreforge

import com.willfp.ecojobs.api.event.PlayerJobLevelUpEvent
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -18,7 +19,7 @@ object TriggerLevelUpJob : Trigger("level_up_job") {
val player = event.player

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#libreforge-updater
#Sun Nov 19 14:13:20 GMT 2023
#Tue Nov 21 22:40:38 GMT 2023
kotlin.code.style=official
libreforge-version=4.43.1
version=3.42.1
libreforge-version=4.44.0
version=3.43.0

0 comments on commit fe59c30

Please sign in to comment.