From 86b7ad2971b359154fdfedc68489f97409974090 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Tue, 4 Feb 2025 21:39:57 +0000 Subject: [PATCH 1/2] added level-up-effects added `level-up-effects` deprecated `level-commands` with message --- .../kotlin/com/willfp/ecojobs/jobs/Job.kt | 52 ++++++++++++------- .../willfp/ecojobs/jobs/JobLevelListener.kt | 2 + 2 files changed, 36 insertions(+), 18 deletions(-) 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 752f8b9..aebf888 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 @@ -33,6 +33,7 @@ import com.willfp.libreforge.conditions.Conditions import com.willfp.libreforge.counters.Counters import com.willfp.libreforge.effects.EffectList import com.willfp.libreforge.effects.Effects +import com.willfp.libreforge.effects.executors.impl.NormalExecutorFactory import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.configuration.InvalidConfigurationException @@ -133,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" @@ -201,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") + ) + override fun onRegister() { jobXpGains.forEach { it.bind(JobXPAccumulator(this)) } } @@ -382,6 +397,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")) { From 03e99e2e1e01b2ec4a6ad1e21afdb3d5eb8b9ad2 Mon Sep 17 00:00:00 2001 From: Exanthiax <107284021+Exanthiax@users.noreply.github.com> Date: Tue, 4 Feb 2025 23:05:41 +0000 Subject: [PATCH 2/2] updated ymls --- .../core-plugin/src/main/resources/jobs/_example.yml | 11 +++++++---- .../core-plugin/src/main/resources/jobs/beekeeper.yml | 2 +- .../core-plugin/src/main/resources/jobs/builder.yml | 2 +- .../core-plugin/src/main/resources/jobs/enchanter.yml | 2 +- .../core-plugin/src/main/resources/jobs/farmer.yml | 2 +- .../core-plugin/src/main/resources/jobs/fisherman.yml | 2 +- .../src/main/resources/jobs/lumberjack.yml | 2 +- .../core-plugin/src/main/resources/jobs/miner.yml | 2 +- .../core-plugin/src/main/resources/jobs/slayer.yml | 2 +- .../core-plugin/src/main/resources/jobs/smelter.yml | 2 +- .../core-plugin/src/main/resources/jobs/toolsmith.yml | 2 +- 11 files changed, 17 insertions(+), 14 deletions(-) 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 b37ec7e..6b39980 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/_example.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/_example.yml @@ -141,10 +141,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 cc96120..8881921 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/beekeeper.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/beekeeper.yml @@ -95,7 +95,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 ec52196..7ef0945 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/builder.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/builder.yml @@ -94,7 +94,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 eb7881b..9bef815 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/enchanter.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/enchanter.yml @@ -92,7 +92,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 9b9163c..ebd3092 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/farmer.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/farmer.yml @@ -107,7 +107,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 6a0046a..73bf173 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/fisherman.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/fisherman.yml @@ -92,7 +92,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 765f7dd..411f139 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/lumberjack.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/lumberjack.yml @@ -104,7 +104,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 9ee7a53..29e3291 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/miner.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/miner.yml @@ -104,7 +104,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 4fff9f7..972d9b1 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/slayer.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/slayer.yml @@ -95,7 +95,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 8fa00cd..ce3cc90 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/smelter.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/smelter.yml @@ -92,7 +92,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 10ba906..2a48506 100644 --- a/eco-core/core-plugin/src/main/resources/jobs/toolsmith.yml +++ b/eco-core/core-plugin/src/main/resources/jobs/toolsmith.yml @@ -133,7 +133,7 @@ level-up-messages: 1: - "&8» &8Earn &a$%money%&8 for each tool crafted" -level-commands: [ ] +level-up-effects: [ ] effects: - id: give_money