diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt index ee3c981..253dc30 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt @@ -134,24 +134,7 @@ class Job( ViolationContext(plugin, "Job $id") ) - for (string in config.getStrings("level-commands")) { - val split = string.split(":") - - if (split.size == 1) { - for (level in 1..maxLevel) { - val commands = levelCommands[level] ?: mutableListOf() - commands.add(string) - levelCommands[level] = commands - } - } else { - val level = split[0].toInt() - - val command = string.removePrefix("$level:") - val commands = levelCommands[level] ?: mutableListOf() - commands.add(command) - levelCommands[level] = commands - } - } + manageLevelCommands(config) PlayerPlaceholder( plugin, "${id}_percentage_progress" @@ -202,6 +185,37 @@ class Job( }.register() } + @Deprecated("Use level-up-effects instead") + private fun manageLevelCommands(config: Config) { + if (config.getStrings("level-commands").isNotEmpty()) { + plugin.logger.warning("$id job: The `level-commands` key is deprecated and will be removed in future versions. Switch to `level-up-effects` instead. Refer to the wiki for more info.") + } + for (string in config.getStrings("level-commands")) { + val split = string.split(":") + + if (split.size == 1) { + for (level in 1..maxLevel) { + val commands = levelCommands[level] ?: mutableListOf() + commands.add(string) + levelCommands[level] = commands + } + } else { + val level = split[0].toInt() + + val command = string.removePrefix("$level:") + val commands = levelCommands[level] ?: mutableListOf() + commands.add(command) + levelCommands[level] = commands + } + } + } + + val levelUpEffects = Effects.compileChain( + config.getSubsections("level-up-effects"), + NormalExecutorFactory.create(), + ViolationContext(plugin, "Job $id level-up-effects") + ) + val joinEffects = Effects.compileChain( config.getSubsections("join-effects"), NormalExecutorFactory.create(), @@ -395,6 +409,7 @@ class Job( } } + @Deprecated("Use level-up-effects instead") fun executeLevelCommands(player: Player, level: Int) { val commands = levelCommands[level] ?: emptyList() diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobLevelListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobLevelListener.kt index 6050fc6..eb97478 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobLevelListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/JobLevelListener.kt @@ -2,6 +2,7 @@ package com.willfp.ecojobs.jobs import com.willfp.ecojobs.EcoJobsPlugin import com.willfp.ecojobs.api.event.PlayerJobLevelUpEvent +import com.willfp.libreforge.toDispatcher import org.bukkit.Sound import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority @@ -16,6 +17,7 @@ class JobLevelListener( val player = event.player val level = event.level + job.levelUpEffects?.trigger(player.toDispatcher()) job.executeLevelCommands(player, level) if (this.plugin.configYml.getBool("level-up.sound.enabled")) { diff --git a/eco-core/core-plugin/src/main/resources/jobs/_example.yml b/eco-core/core-plugin/src/main/resources/jobs/_example.yml index 73200dc..ba27ce7 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/_example.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/_example.yml @@ -155,10 +155,13 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each &a%blocks%&8 blocks mined" -# Commands to be sent on levelup, can be formatted two ways: -# level:command (e.g. 10:eco give %player% 1000), which would execute that command for level 10 -# command (e.g. eco give %player% 5000), which would execute that command for all levels -level-commands: [ ] +# Effects to run when the skill levels up +# %level% is the level the skill leveled up to. +# If you want to restrict this to certain levels, you can use +# require: %level% = 20, or require: %level% < 50, etc. +# If you want a reward to run every x levels, you can use +# every: 1, or every: 12, etc +level-up-effects: [ ] # The effects for the job, has %level% as a placeholder effects: diff --git a/eco-core/core-plugin/src/main/resources/jobs/beekeeper.yml b/eco-core/core-plugin/src/main/resources/jobs/beekeeper.yml index 9ad6287..262265f 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/beekeeper.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/beekeeper.yml @@ -99,7 +99,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each bee you breed" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/builder.yml b/eco-core/core-plugin/src/main/resources/jobs/builder.yml index 64cd1ba..0b33817 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/builder.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/builder.yml @@ -98,7 +98,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each &a%blocks%&8 blocks placed" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/enchanter.yml b/eco-core/core-plugin/src/main/resources/jobs/enchanter.yml index 4f30762..b1a1d8a 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/enchanter.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/enchanter.yml @@ -96,7 +96,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each enchanted item" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/farmer.yml b/eco-core/core-plugin/src/main/resources/jobs/farmer.yml index be74559..11cabae 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/farmer.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/farmer.yml @@ -111,7 +111,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each crop farmed" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/fisherman.yml b/eco-core/core-plugin/src/main/resources/jobs/fisherman.yml index ebe15fc..cf33948 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/fisherman.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/fisherman.yml @@ -96,7 +96,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each fish caught" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/lumberjack.yml b/eco-core/core-plugin/src/main/resources/jobs/lumberjack.yml index 8bae52a..29f03b1 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/lumberjack.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/lumberjack.yml @@ -108,7 +108,7 @@ level-up-messages: 1: - "&8» &7Earn &a$%money%&7 for each log chopped." -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/miner.yml b/eco-core/core-plugin/src/main/resources/jobs/miner.yml index 3169dba..9d0d994 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/miner.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/miner.yml @@ -108,7 +108,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each &a%blocks%&8 blocks mined" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/slayer.yml b/eco-core/core-plugin/src/main/resources/jobs/slayer.yml index a451c74..4ec4e74 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/slayer.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/slayer.yml @@ -99,7 +99,7 @@ level-up-messages: - "&8» &8Earn &a$%money%&8 per heart of health that" - " &8mobs you kill have" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/smelter.yml b/eco-core/core-plugin/src/main/resources/jobs/smelter.yml index b384f97..8f583ad 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/smelter.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/smelter.yml @@ -96,7 +96,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each smelted item" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money diff --git a/eco-core/core-plugin/src/main/resources/jobs/toolsmith.yml b/eco-core/core-plugin/src/main/resources/jobs/toolsmith.yml index 9328452..480c5d4 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/toolsmith.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/toolsmith.yml @@ -137,7 +137,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each tool crafted" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money