diff --git a/build.gradle b/build.gradle index 2c47494..6b5ac78 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { compileOnly 'org.jetbrains:annotations:23.0.0' - compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10' + compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.20' } tasks.withType(JavaCompile) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt index 2733906..adf46b0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt @@ -5,24 +5,15 @@ import com.willfp.boosters.boosters.activeBoosters import com.willfp.boosters.boosters.expireBooster import com.willfp.boosters.boosters.scanForBoosters import com.willfp.boosters.commands.CommandBoosters -import com.willfp.boosters.config.BoostersYml import com.willfp.eco.core.command.impl.PluginCommand -import com.willfp.eco.core.data.ServerProfile -import com.willfp.eco.core.data.profile -import com.willfp.eco.core.integrations.placeholder.PlaceholderManager -import com.willfp.eco.core.placeholder.PlayerlessPlaceholder -import com.willfp.eco.util.formatEco -import com.willfp.eco.util.savedDisplayName import com.willfp.libreforge.LibReforgePlugin import org.bukkit.Bukkit - import org.bukkit.event.Listener -import kotlin.math.floor class BoostersPlugin : LibReforgePlugin(supportsLrcdb = false) { - val boostersYml = BoostersYml(this) - override fun handleEnableAdditional() { + this.copyConfigs("boosters") + this.registerHolderProvider { Bukkit.getServer().activeBoosters.map { it.booster } } } @@ -62,7 +53,7 @@ class BoostersPlugin : LibReforgePlugin(supportsLrcdb = false) { ) } - override fun loadPluginCommands(): List { + override fun loadPluginCommands(): List { return listOf( CommandBoosters(this) ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt index 3fb12ce..157bf82 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt @@ -24,10 +24,9 @@ import kotlin.math.floor class Booster( private val plugin: BoostersPlugin, - val config: Config, + override val id: String, + val config: Config ) : Holder { - override val id = config.getString("id") - val ownedDataKey: PersistentDataKey = PersistentDataKey( plugin.namespacedKeyFactory.create(id), PersistentDataKeyType.INT, @@ -206,11 +205,12 @@ class Booster( ) { var activeList = mutableListOf() - for(active in Bukkit.getServer().activeBoosters){ + for (active in Bukkit.getServer().activeBoosters) { activeList.add(active.booster.name) } - var outputString = plugin.langYml.getString("no-currently-active-list").formatEco(formatPlaceholders = false) + var outputString = + plugin.langYml.getString("no-currently-active-list").formatEco(formatPlaceholders = false) if (activeList.size > 0) { outputString = activeList.joinToString(", ") } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Boosters.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Boosters.kt index a75d1c9..0638976 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Boosters.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Boosters.kt @@ -4,13 +4,14 @@ import com.google.common.collect.BiMap import com.google.common.collect.HashBiMap import com.google.common.collect.ImmutableList import com.willfp.boosters.BoostersPlugin +import com.willfp.eco.core.config.ConfigType +import com.willfp.eco.core.config.readConfig import com.willfp.eco.core.config.updating.ConfigUpdater import com.willfp.libreforge.chains.EffectChains +import java.io.File object Boosters { - /** - * Registered boosters. - */ + /** Registered boosters. */ private val BY_ID: BiMap = HashBiMap.create() /** @@ -42,14 +43,22 @@ object Boosters { @ConfigUpdater @JvmStatic fun update(plugin: BoostersPlugin) { - plugin.boostersYml.getSubsections("chains").mapNotNull { - EffectChains.compile(it, "Effect Chains") - } for (booster in values()) { removeBooster(booster) } - for (config in plugin.boostersYml.getSubsections("boosters")) { - Booster(plugin, config) + + for ((id, config) in plugin.fetchConfigs("boosters")) { + Booster(plugin, id, config) + } + + // Legacy + val boostersYml = File(plugin.dataFolder, "boosters.yml").readConfig(ConfigType.YAML) + + for (config in boostersYml.getSubsections("boosters")) { + Booster(plugin, config.getString("id"), config) + } + boostersYml.getSubsections("chains").mapNotNull { + EffectChains.compile(it, "Effect Chains") } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/config/BoostersYml.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/config/BoostersYml.kt deleted file mode 100644 index 4197305..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/config/BoostersYml.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.willfp.boosters.config - -import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.config.BaseConfig -import com.willfp.eco.core.config.ConfigType - -class BoostersYml(plugin: EcoPlugin) : BaseConfig( - "boosters", - plugin, - false, - ConfigType.YAML -) diff --git a/eco-core/core-plugin/src/main/resources/boosters.yml b/eco-core/core-plugin/src/main/resources/boosters.yml deleted file mode 100644 index 03466c7..0000000 --- a/eco-core/core-plugin/src/main/resources/boosters.yml +++ /dev/null @@ -1,124 +0,0 @@ -boosters: - - id: 1_5sell_multiplier - name: "1.5x Sell Multiplier" - duration: 72000 - effects: - - id: sell_multiplier - args: - multiplier: 1.5 - conditions: [] - commands: - activation: [] - expiry: [] - messages: - activation: - - "" - - " %player%&f has activated a &a1.5x Sell Multiplier Booster&f!" - - " &fThis booster will last an hour, be sure to thank them!" - - "" - expiry: - - "" - - " &fThe &a1.5x Sell Multiplier Booster&f has ended" - - " &fGet another one here: &ahttps://store.ecomc.net/package/756887" - - "" - gui: - item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM0YjI3YmZjYzhmOWI5NjQ1OTRiNjE4YjExNDZhZjY5ZGUyNzhjZTVlMmUzMDEyY2I0NzFhOWEzY2YzODcxIn19fQ== - name: "&d1.5x Sell Multiplier" - lore: - - "" - - "&fGives everyone online a" - - "&a1.5x Sell Multiplier" - - "&fto make money faster!" - - "" - - "&fDuration: &a1 Hour" - - "" - - "&fYou have: &a%amount%" - - "&fGet more at &astore.ecomc.net" - - "" - - "&e&oClick to activate!" - - "" - position: - row: 2 - column: 2 - - id: 2sell_multiplier - name: "2x Sell Multiplier" - duration: 72000 - effects: - - id: sell_multiplier - args: - multiplier: 2 - conditions: [] - commands: - activation: [] - expiry: [] - messages: - activation: - - "" - - " %player%&f has activated a &a2x Sell Multiplier Booster&f!" - - " &fThis booster will last an hour, be sure to thank them!" - - "" - expiry: - - "" - - " &fThe &a2x Sell Multiplier Booster&f has ended" - - " &fGet another one here: &ahttps://store.ecomc.net/package/756888" - - "" - gui: - item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjBhN2I5NGM0ZTU4MWI2OTkxNTlkNDg4NDZlYzA5MTM5MjUwNjIzN2M4OWE5N2M5MzI0OGEwZDhhYmM5MTZkNSJ9fX0= - name: "&d2x Sell Multiplier" - lore: - - "" - - "&fGives everyone online a" - - "&a2x Sell Multiplier" - - "&fto make money faster!" - - "" - - "&fDuration: &a1 Hour" - - "" - - "&fYou have: &a%amount%" - - "&fGet more at &astore.ecomc.net" - - "" - - "&e&oClick to activate!" - - "" - position: - row: 2 - column: 5 - - id: skill_xp - name: "2x Skill XP Multiplier" - duration: 72000 - effects: - - id: skill_xp_multiplier - args: - multiplier: 2 - conditions: [] - commands: - activation: [] - expiry: [] - messages: - activation: - - "" - - " %player%&f has activated a &a2x Skill XP Booster&f!" - - " &fThis booster will last an hour, be sure to thank them!" - - "" - expiry: - - "" - - " &fThe &a2x Skill XP Booster&f has ended" - - " &fGet another one here: &ahttps://store.ecomc.net/package/756893" - - "" - gui: - item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODkyNmMxZjJjM2MxNGQwODZjNDBjZmMyMzVmZTkzODY5NGY0YTUxMDY3YWRhNDcyNmI0ODZlYTFjODdiMDNlMiJ9fX0= - name: "&d2x Skill XP Multiplier" - lore: - - "" - - "&fGives everyone online a" - - "&a2x Skill XP Multiplier" - - "&fto level up faster!" - - "" - - "&fDuration: &a1 Hour" - - "" - - "&fYou have: &a%amount%" - - "&fGet more at &astore.ecomc.net" - - "" - - "&e&oClick to activate!" - - "" - position: - row: 2 - column: 8 diff --git a/eco-core/core-plugin/src/main/resources/boosters/1_5sell_multiplier.yml b/eco-core/core-plugin/src/main/resources/boosters/1_5sell_multiplier.yml new file mode 100644 index 0000000..b81b5e0 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/boosters/1_5sell_multiplier.yml @@ -0,0 +1,40 @@ +name: "1.5x Sell Multiplier" +duration: 72000 +effects: + - id: sell_multiplier + args: + multiplier: 1.5 +conditions: [ ] +commands: + activation: [ ] + expiry: [ ] +messages: + activation: + - "" + - " %player%&f has activated a &a1.5x Sell Multiplier Booster&f!" + - " &fThis booster will last an hour, be sure to thank them!" + - "" + expiry: + - "" + - " &fThe &a1.5x Sell Multiplier Booster&f has ended" + - " &fGet another one here: &ahttps://store.ecomc.net/package/756887" + - "" +gui: + item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM0YjI3YmZjYzhmOWI5NjQ1OTRiNjE4YjExNDZhZjY5ZGUyNzhjZTVlMmUzMDEyY2I0NzFhOWEzY2YzODcxIn19fQ== + name: "&d1.5x Sell Multiplier" + lore: + - "" + - "&fGives everyone online a" + - "&a1.5x Sell Multiplier" + - "&fto make money faster!" + - "" + - "&fDuration: &a1 Hour" + - "" + - "&fYou have: &a%amount%" + - "&fGet more at &astore.ecomc.net" + - "" + - "&e&oClick to activate!" + - "" + position: + row: 2 + column: 2 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/boosters/2sell_multiplier.yml b/eco-core/core-plugin/src/main/resources/boosters/2sell_multiplier.yml new file mode 100644 index 0000000..6e103c6 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/boosters/2sell_multiplier.yml @@ -0,0 +1,40 @@ +name: "2x Sell Multiplier" +duration: 72000 +effects: + - id: sell_multiplier + args: + multiplier: 2 +conditions: [ ] +commands: + activation: [ ] + expiry: [ ] +messages: + activation: + - "" + - " %player%&f has activated a &a2x Sell Multiplier Booster&f!" + - " &fThis booster will last an hour, be sure to thank them!" + - "" + expiry: + - "" + - " &fThe &a2x Sell Multiplier Booster&f has ended" + - " &fGet another one here: &ahttps://store.ecomc.net/package/756888" + - "" +gui: + item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjBhN2I5NGM0ZTU4MWI2OTkxNTlkNDg4NDZlYzA5MTM5MjUwNjIzN2M4OWE5N2M5MzI0OGEwZDhhYmM5MTZkNSJ9fX0= + name: "&d2x Sell Multiplier" + lore: + - "" + - "&fGives everyone online a" + - "&a2x Sell Multiplier" + - "&fto make money faster!" + - "" + - "&fDuration: &a1 Hour" + - "" + - "&fYou have: &a%amount%" + - "&fGet more at &astore.ecomc.net" + - "" + - "&e&oClick to activate!" + - "" + position: + row: 2 + column: 5 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/boosters/_example.yml b/eco-core/core-plugin/src/main/resources/boosters/_example.yml new file mode 100644 index 0000000..83d3637 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/boosters/_example.yml @@ -0,0 +1,55 @@ +# The ID of the booster is the name of the .yml file, +# for example skill_xp_multiplier.yml has the ID of skill_xp_multiplier +# You can place boosters anywhere in this folder, +# including in subfolders if you want to organize your booster configs +# _example.yml is not loaded. + +name: "1.5x Sell Multiplier" # The name of the booster, shown to players +duration: 72000 # The duration, in ticks + +# The effects of the booster (i.e. the functionality) +# See here: https://plugins.auxilor.io/effects/configuring-an-effect +effects: + - id: sell_multiplier + args: + multiplier: 1.5 + +# The conditions required for the effects to activate +conditions: [] + +# Commands ran by console on booster activation and expiry +commands: + activation: [] + expiry: [] + +messages: + activation: + - "" + - " %player%&f has activated a &a1.5x Sell Multiplier Booster&f!" + - " &fThis booster will last an hour, be sure to thank them!" + - "" + expiry: + - "" + - " &fThe &a1.5x Sell Multiplier Booster&f has ended" + - " &fGet another one here: &ahttps://store.ecomc.net/package/756887" + - "" + +gui: + item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM0YjI3YmZjYzhmOWI5NjQ1OTRiNjE4YjExNDZhZjY5ZGUyNzhjZTVlMmUzMDEyY2I0NzFhOWEzY2YzODcxIn19fQ== + name: "&d1.5x Sell Multiplier" + lore: + - "" + - "&fGives everyone online a" + - "&a1.5x Sell Multiplier" + - "&fto make money faster!" + - "" + - "&fDuration: &a1 Hour" + - "" + - "&fYou have: &a%amount%" + - "&fGet more at &astore.ecomc.net" + - "" + - "&e&oClick to activate!" + - "" + position: + row: 2 + column: 2 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/boosters/skill_xp.yml b/eco-core/core-plugin/src/main/resources/boosters/skill_xp.yml new file mode 100644 index 0000000..5024538 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/boosters/skill_xp.yml @@ -0,0 +1,40 @@ +name: "2x Skill XP Multiplier" +duration: 72000 +effects: + - id: skill_xp_multiplier + args: + multiplier: 2 +conditions: [ ] +commands: + activation: [ ] + expiry: [ ] +messages: + activation: + - "" + - " %player%&f has activated a &a2x Skill XP Booster&f!" + - " &fThis booster will last an hour, be sure to thank them!" + - "" + expiry: + - "" + - " &fThe &a2x Skill XP Booster&f has ended" + - " &fGet another one here: &ahttps://store.ecomc.net/package/756893" + - "" +gui: + item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODkyNmMxZjJjM2MxNGQwODZjNDBjZmMyMzVmZTkzODY5NGY0YTUxMDY3YWRhNDcyNmI0ODZlYTFjODdiMDNlMiJ9fX0= + name: "&d2x Skill XP Multiplier" + lore: + - "" + - "&fGives everyone online a" + - "&a2x Skill XP Multiplier" + - "&fto level up faster!" + - "" + - "&fDuration: &a1 Hour" + - "" + - "&fYou have: &a%amount%" + - "&fGet more at &astore.ecomc.net" + - "" + - "&e&oClick to activate!" + - "" + position: + row: 2 + column: 8 \ No newline at end of file