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] 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")) {