From c0435a659e20d409f8dab044e7c442295b418308 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 20 Apr 2023 18:23:09 +0100 Subject: [PATCH] Cleaned up PR, updated preloading --- .../com/willfp/ecoenchants/enchants/EcoEnchant.kt | 12 +++++++----- .../willfp/ecoenchants/enchants/EcoEnchants.kt | 2 ++ .../com/willfp/ecoenchants/enchants/EnchantGUI.kt | 15 ++++++--------- .../ecoenchants/enchants/LibReforgeEcoEnchant.kt | 12 ++++-------- eco-core/core-plugin/src/main/resources/lang.yml | 2 +- gradle.properties | 2 +- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt index fa5eb6da..05acdbe2 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchant.kt @@ -18,6 +18,7 @@ import com.willfp.ecoenchants.target.EnchantLookup.getEnchantLevel import com.willfp.ecoenchants.target.EnchantmentTargets import com.willfp.ecoenchants.target.TargetSlot import com.willfp.ecoenchants.type.EnchantmentTypes +import com.willfp.libreforge.SilentViolationContext import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.conditions.ConditionList import com.willfp.libreforge.conditions.Conditions @@ -44,7 +45,7 @@ import java.util.Objects abstract class EcoEnchant( val id: String, configProvider: (EcoEnchant) -> Config, - protected val plugin: EcoPlugin + protected val plugin: EcoEnchantsPlugin ) : Enchantment(NamespacedKey.minecraft(id)), EcoEnchantLike { final override val config by lazy { configProvider(this) } override val enchant by lazy { this } @@ -85,19 +86,19 @@ abstract class EcoEnchant( constructor( config: Config, - plugin: EcoPlugin + plugin: EcoEnchantsPlugin ) : this(config.getString("id"), { config }, plugin) constructor( id: String, config: Config, - plugin: EcoPlugin + plugin: EcoEnchantsPlugin ) : this(id, { config }, plugin) @JvmOverloads constructor( id: String, - plugin: EcoPlugin, + plugin: EcoEnchantsPlugin, force: Boolean = true ) : this( id, @@ -130,7 +131,8 @@ abstract class EcoEnchant( conditions = Conditions.compile( config.getSubsections("conditions"), - ViolationContext(plugin, "Enchantment $id") + if (plugin.isLoaded) ViolationContext(plugin, "Enchantment $id") + else SilentViolationContext ) if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.$id") == null) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt index 59a6009d..c74e51b0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt @@ -27,6 +27,8 @@ object EcoEnchants : ConfigCategory("enchant", "enchants") { private val BY_KEY = HashBiMap.create() private val BY_NAME = HashBiMap.create() + override val shouldPreload = true + /** * Get all registered [EcoEnchant]s. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt index a7d3974d..9ff73c73 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt @@ -1,6 +1,7 @@ package com.willfp.ecoenchants.enchants import com.github.benmanes.caffeine.cache.Caffeine +import com.willfp.eco.core.config.base.LangYml import com.willfp.eco.core.config.updating.ConfigUpdater import com.willfp.eco.core.drops.DropQueue import com.willfp.eco.core.fast.fast @@ -262,12 +263,9 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot { }.ifEmpty { plugin.langYml.getFormattedString("no-conflicts").toWrappable() } } ) - .replace("%tradeable%", plugin.langYml - .getFormattedString(this.isTradeable.yesOrNo)) - .replace("%discoverable%", plugin.langYml - .getFormattedString(this.isDiscoverable.yesOrNo)) - .replace("%enchantable%", plugin.langYml - .getFormattedString(this.isEnchantable.yesOrNo)) + .replace("%tradeable%", this.isTradeable.parseYesOrNo(plugin.langYml)) + .replace("%discoverable%", this.isDiscoverable.parseYesOrNo(plugin.langYml)) + .replace("%enchantable%", this.isEnchantable.parseYesOrNo(plugin.langYml)) } .flatMap { WordUtils.wrap(it, 45, "\n", false) @@ -287,7 +285,6 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot { } } -val Boolean.yesOrNo: String - get() { - return if (this) "yes" else "no" +fun Boolean.parseYesOrNo(langYml: LangYml): String { + return if (this) langYml.getFormattedString("yes") else langYml.getFormattedString("no") } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt index febedc82..7c300d1d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/LibReforgeEcoEnchant.kt @@ -1,21 +1,16 @@ package com.willfp.ecoenchants.enchants -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config import com.willfp.ecoenchants.EcoEnchantsPlugin -import com.willfp.libreforge.Holder +import com.willfp.libreforge.SilentViolationContext import com.willfp.libreforge.ViolationContext -import com.willfp.libreforge.conditions.ConditionList -import com.willfp.libreforge.effects.EffectList import com.willfp.libreforge.effects.Effects import com.willfp.libreforge.effects.emptyEffectList -import com.willfp.libreforge.loader.LibreforgePlugin -import java.util.Objects class LibReforgeEcoEnchant( id: String, config: Config, - plugin: EcoPlugin + plugin: EcoEnchantsPlugin ) : EcoEnchant( id, config, @@ -23,7 +18,8 @@ class LibReforgeEcoEnchant( ) { private val effects = Effects.compile( config.getSubsections("effects"), - ViolationContext(plugin, "Enchantment $id") + if (plugin.isLoaded) ViolationContext(plugin, "Enchantment $id") + else SilentViolationContext ) override fun createLevel(level: Int): EcoEnchantLevel = diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index f3cb70ad..f1f1bccd 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -20,4 +20,4 @@ all: "All" yes: "&aYes" no: "&cNo" no-conflicts: "No Conflicts" -all-conflicts: "All Other Enchantments" \ No newline at end of file +all-conflicts: "All Other Enchantments" diff --git a/gradle.properties b/gradle.properties index 8cd54bcd..0038101b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ #libreforge-updater #Wed Apr 19 12:21:42 BST 2023 kotlin.code.style=official -libreforge-version=4.3.0 +libreforge-version=4.4.0 version=10.3.1