Fixed init bugs

This commit is contained in:
Will FP 2023-12-07 16:17:14 +00:00
parent 7cc4f8d00c
commit c7a1bb21b7
6 changed files with 17 additions and 15 deletions

View File

@ -42,11 +42,11 @@ fun EcoEnchantLike.getFormattedName(
val typeFormat = this.type.format
val name = this.rawDisplayName
val number = if (numerals) NumberUtils.toNumeral(level) else level.toString()
val dontShowNumber = (level == 1 && this.enchantment.maxLevel == 1) || level < 1
val dontShowNumber = (level == 1 && this.maximumLevel == 1) || level < 1
val notMetFormat = if (showNotMet) plugin.configYml.getString("display.not-met.format") else ""
if (plugin.configYml.getBool("display.above-max-level.enabled") && level > this.enchantment.maxLevel) {
if (plugin.configYml.getBool("display.above-max-level.enabled") && level > this.maximumLevel) {
val format = plugin.configYml.getString("display.above-max-level.format")
val levelOnly = plugin.configYml.getBool("display.above-max-level.level-only")

View File

@ -19,11 +19,6 @@ interface EcoEnchant : KRegistrable, EcoEnchantLike {
override val enchantment: Enchantment
get() = this as Enchantment
/**
* The max enchantment level.
*/
val maximumLevel: Int
/**
* If this enchantment conflicts with all other enchantments.
*/

View File

@ -23,6 +23,11 @@ interface EcoEnchantLike {
*/
val config: Config
/**
* The max enchantment level.
*/
val maximumLevel: Int
/**
* The plugin.
*/

View File

@ -18,10 +18,11 @@ import org.bukkit.enchantments.Enchantment
abstract class EcoEnchantBase(
final override val id: String,
final override val plugin: EcoEnchantsPlugin,
_config: Config? = null
) : EcoEnchant {
protected val context = ViolationContext(plugin, "enchantment $id")
final override val config by lazy { loadConfig() }
final override val config by lazy { _config ?: loadConfig()!! }
private val levels = mutableMapOf<Int, EcoEnchantLevel>()
@ -67,7 +68,7 @@ abstract class EcoEnchantBase(
/**
* Load the config for this enchant.
*/
protected abstract fun loadConfig(): Config
protected open fun loadConfig(): Config? = null
override fun getLevel(level: Int): EcoEnchantLevel {
return levels.getOrPut(level) {

View File

@ -3,23 +3,21 @@ package com.willfp.ecoenchants.enchant.impl
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchant.EcoEnchantLevel
import com.willfp.libreforge.BlankHolder.conditions
import com.willfp.libreforge.BlankHolder.effects
import com.willfp.libreforge.SilentViolationContext
import com.willfp.libreforge.effects.Effects
class LibreforgeEcoEnchant(
id: String,
private val _config: Config,
_config: Config,
plugin: EcoEnchantsPlugin
) : EcoEnchantBase(id, plugin) {
) : EcoEnchantBase(id, plugin, _config) {
private val effects = Effects.compile(
config.getSubsections("effects"),
if (plugin.isLoaded) context.with("effects") else SilentViolationContext
)
override fun loadConfig(): Config {
return _config
}
override fun createLevel(level: Int): EcoEnchantLevel {
return EcoEnchantLevel(this, level, effects, conditions, plugin)
}

View File

@ -15,6 +15,9 @@ class VanillaEcoEnchantLike(
) : EcoEnchantLike {
override val config = plugin.vanillaEnchantsYml.getSubsection(enchantment.key.key)
override val maximumLevel
get() = enchantment.maxLevel
override val type: EnchantmentType =
EnchantmentTypes[plugin.vanillaEnchantsYml.getString("${enchantment.key.key}.type")]
?: EnchantmentTypes.values().first()