diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/EcoArmorPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/EcoArmorPlugin.kt index 58a4ea3..3fcb599 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/EcoArmorPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/EcoArmorPlugin.kt @@ -4,6 +4,7 @@ import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.PluginCommand import com.willfp.eco.core.display.DisplayModule import com.willfp.eco.core.integrations.IntegrationLoader +import com.willfp.eco.util.ListUtils import com.willfp.ecoarmor.commands.CommandEcoarmor import com.willfp.ecoarmor.config.EcoArmorYml import com.willfp.ecoarmor.display.ArmorDisplay @@ -31,14 +32,7 @@ class EcoArmorPlugin : EcoPlugin(687, 10002, "&c") { instance = this ecoArmorYml = EcoArmorYml(this) init(this) - registerHolderProvider { player -> - val active = ArmorUtils.getActiveSet(player) - if (active == null) { - emptyList() - } else { - listOf(active) - } - } + registerHolderProvider { ListUtils.toSingletonList(ArmorUtils.getActiveSet(it)) } } override fun handleEnable() { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/AdvancedHolder.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/AdvancedHolder.kt deleted file mode 100644 index dde6ef7..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/AdvancedHolder.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.willfp.ecoarmor.sets - -import com.willfp.libreforge.Holder -import com.willfp.libreforge.conditions.ConfiguredCondition -import com.willfp.libreforge.effects.ConfiguredEffect - -class AdvancedHolder( - override val conditions: Set, - override val effects: Set) : Holder { -} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSet.kt index bef3461..0380a8d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSet.kt @@ -16,6 +16,7 @@ import com.willfp.ecoarmor.sets.ArmorUtils.setAdvanced import com.willfp.ecoarmor.sets.ArmorUtils.setTier import com.willfp.ecoarmor.upgrades.Tier import com.willfp.ecoarmor.upgrades.Tiers +import com.willfp.ecoarmor.util.notNullMapOf import com.willfp.libreforge.Holder import com.willfp.libreforge.conditions.Conditions import com.willfp.libreforge.conditions.ConfiguredCondition @@ -51,12 +52,12 @@ class ArmorSet( /** * Items in set. */ - private val items: MutableMap = EnumMap(ArmorSlot::class.java) + private val items = notNullMapOf() /** * Items in advanced set. */ - private val advancedItems: MutableMap = EnumMap(ArmorSlot::class.java) + private val advancedItems = notNullMapOf() /** * Advancement shard item. @@ -88,8 +89,8 @@ class ArmorSet( advancedEffects.add(conf) } } - regularHolder = RegularHolder(conditions, effects) - advancedHolder = AdvancedHolder(conditions, advancedEffects) + regularHolder = SimpleHolder(conditions, effects) + advancedHolder = SimpleHolder(conditions, advancedEffects) ArmorSets.addNewSet(this) for (slot in ArmorSlot.values()) { val item = construct(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), false) @@ -105,9 +106,7 @@ class ArmorSet( val shardLore = config.getStrings("advancementShardLore") shardLore.replaceAll { Display.PREFIX + it } val shard = ItemStackBuilder( - Items.lookup( - plugin.configYml.getString("advancement-shard-material").lowercase(Locale.getDefault()) - ).item + Items.lookup(plugin.configYml.getString("advancement-shard-material")) ) .setDisplayName(config.getString("advancementShardName")) .addEnchantment(Enchantment.DURABILITY, 3) @@ -240,7 +239,7 @@ class ArmorSet( * @return The item. */ fun getItemStack(slot: ArmorSlot): ItemStack { - return items[slot]!! + return items[slot] } /** @@ -250,7 +249,7 @@ class ArmorSet( * @return The item. */ fun getAdvancedItemStack(slot: ArmorSlot): ItemStack { - return advancedItems[slot]!! + return advancedItems[slot] } /** @@ -260,16 +259,12 @@ class ArmorSet( * @return The tier. */ fun getDefaultTier(slot: ArmorSlot?): Tier { - if (slot == null) return Tiers.defaultTier + slot ?: return Tiers.defaultTier val tier = Tiers.getByID(config.getSubsection(slot.name.lowercase()).getString("defaultTier")) return tier ?: Tiers.defaultTier } override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other !is ArmorSet) { return false } @@ -286,4 +281,9 @@ class ArmorSet( + id + "}") } -} \ No newline at end of file +} + +class SimpleHolder( + override val conditions: Set, + override val effects: Set +) : Holder \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/RegularHolder.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/RegularHolder.kt deleted file mode 100644 index e851e4f..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/RegularHolder.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.willfp.ecoarmor.sets - -import com.willfp.libreforge.Holder -import com.willfp.libreforge.conditions.ConfiguredCondition -import com.willfp.libreforge.effects.ConfiguredEffect - -class RegularHolder( - override val conditions: Set, - override val effects: Set) : Holder { -} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt index 8c91fde..6a4754a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt @@ -30,8 +30,8 @@ class CrystalListener(private val plugin: EcoPlugin) : Listener { } val previousTier = ArmorUtils.getTier(current) var allowed = false - val prereq = crystalTier.getRequiredTiersForApplication() - if (prereq.isEmpty() || prereq.contains(previousTier)) { + val requiredTiers = crystalTier.getRequiredTiersForApplication() + if (requiredTiers.isEmpty() || requiredTiers.contains(previousTier)) { allowed = true } if (!allowed) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/Tier.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/Tier.kt index 12f35ad..a999b59 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/Tier.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/Tier.kt @@ -10,24 +10,19 @@ import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe import com.willfp.eco.util.StringUtils import com.willfp.ecoarmor.sets.ArmorSlot import com.willfp.ecoarmor.sets.ArmorUtils.getCrystalTier -import com.willfp.ecoarmor.util.NotNullMap +import com.willfp.ecoarmor.util.notNullMapOf import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType import java.util.* class Tier( - config: Config, + private val config: Config, plugin: EcoPlugin ) : PluginDependent(plugin) { /** * The tier name. */ - val id: String - - /** - * The config of the crystal. - */ - val config: Config + val id = config.getString("id") /** * The display name of the crystal. @@ -57,16 +52,14 @@ class Tier( /** * Item properties. */ - val properties: NotNullMap = NotNullMap(EnumMap(ArmorSlot::class.java)) + val properties = notNullMapOf() /** * Create a new Tier. */ init { - id = config.getString("id") - this.config = config Tiers.addNewTier(this) - + craftable = this.config.getBool("crystal.craftable") displayName = this.config.getString("display") requiredTiersForApplication = this.config.getStrings("requiresTiers") @@ -101,11 +94,13 @@ class Tier( .getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".attackKnockbackPercentage") ) } + CustomItem( plugin.namespacedKeyFactory.create("crystal_" + id.lowercase(Locale.getDefault())), { test: ItemStack? -> this == getCrystalTier(test!!) }, out ).register() + if (this.craftable) { val recipeOut = out.clone() recipeOut.amount = this.config.getInt("crystal.giveAmount") @@ -130,6 +125,7 @@ class Tier( crystalRecipe = null } } + /** * Get the required tiers for application. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/NotNullMap.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/NotNullMap.kt index 77c6958..908228d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/NotNullMap.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/NotNullMap.kt @@ -4,4 +4,13 @@ class NotNullMap(private val handle: MutableMap) : MutableMap override fun get(key: K): V { return handle[key]!! } -} \ No newline at end of file +} + +inline fun Map.toNotNullMap(): NotNullMap = + NotNullMap(this.toMutableMap()) + +inline fun notNullMapOf(): NotNullMap = + mutableMapOf().toNotNullMap() + +inline fun notNullMapOf(vararg pairs: Pair): NotNullMap = + mutableMapOf(*pairs).toNotNullMap() \ No newline at end of file