From 7aed8a72ae2eb133c759e5faa61807e1957513c3 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 21 May 2022 12:49:19 +0100 Subject: [PATCH] Added slot-specific effects/conditions --- .../com/willfp/ecoarmor/EcoArmorPlugin.kt | 1 + .../com/willfp/ecoarmor/sets/ArmorSet.kt | 48 ++++++++++++++- .../com/willfp/ecoarmor/sets/ArmorUtils.kt | 24 ++++++++ .../src/main/resources/ecoarmor.yml | 59 +++++++++++++++++++ 4 files changed, 129 insertions(+), 3 deletions(-) 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 781b5b8..4588298 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 @@ -28,6 +28,7 @@ class EcoArmorPlugin : LibReforgePlugin() { ecoArmorYml = EcoArmorYml(this) Items.registerArgParser(TierArgParser()) registerHolderProvider { ListUtils.toSingletonList(ArmorUtils.getActiveSet(it)) } + registerHolderProvider { ArmorUtils.getSlotHolders(it) } } override fun handleReloadAdditional() { 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 3aa59bc..8207a20 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 @@ -54,11 +54,21 @@ class ArmorSet( */ private val items = notNullMapOf() + /** + * Holders in set. + */ + private val slotHolders = notNullMapOf() + /** * Items in advanced set. */ private val advancedItems = notNullMapOf() + /** + * Holders in advanced set. + */ + private val advancedSlotHolders = notNullMapOf() + /** * Advancement shard item. */ @@ -126,11 +136,32 @@ class ArmorSet( advancedHolder = SimpleHolder(conditions, advancedEffects, "${id}_advanced") ArmorSets.addNewSet(this) for (slot in ArmorSlot.values()) { - val item = construct(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), false) + val slotConfig = config.getSubsection(slot.name.lowercase(Locale.getDefault())) + val item = construct(slot, slotConfig, false) items[slot] = item - constructRecipe(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), item) - val advancedItem = construct(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), true) + constructRecipe(slot, slotConfig, item) + val advancedItem = construct(slot, slotConfig, true) advancedItems[slot] = advancedItem + + slotHolders[slot] = SimpleHolder( + slotConfig.getSubsections("conditions").mapNotNull { + Conditions.compile(it, "Armor Set $id - $slot") + }.toSet(), + slotConfig.getSubsections("effects").mapNotNull { + Effects.compile(it, "Armor Set $id - $slot") + }.toSet(), + "${id}_${slot.name.lowercase()}" + ) + + advancedSlotHolders[slot] = SimpleHolder( + slotConfig.getSubsections("conditions").mapNotNull { + Conditions.compile(it, "Armor Set $id - $slot") + }.toSet(), + slotConfig.getSubsections("advancedEffects").mapNotNull { + Effects.compile(it, "Armor Set $id - $slot (Advanced)") + }.toSet(), + "${id}_${slot.name.lowercase()}_advanced" + ) } advancementShardItem = constructShard() } @@ -310,6 +341,17 @@ class ArmorSet( return tier ?: Tiers.defaultTier } + fun getSpecificHolder(itemStack: ItemStack): Holder? { + val slot = getSlot(itemStack) ?: return null + val advanced = isAdvanced(itemStack) + + return if (advanced) { + advancedSlotHolders[slot] + } else { + slotHolders[slot] + } + } + override fun equals(other: Any?): Boolean { if (other !is ArmorSet) { return false diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorUtils.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorUtils.kt index 065d572..a983a69 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorUtils.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorUtils.kt @@ -65,6 +65,30 @@ object ArmorUtils { } } + /** + * Get active holder for a player. + * + * @param player The player to check. + * @return The holder, or null if not found. + */ + @JvmStatic + fun getSlotHolders(player: Player): Iterable { + val holders = mutableListOf() + + for (itemStack in player.inventory.armorContents) { + if (itemStack == null) { + continue + } + + val set = getSetOnItem(itemStack) ?: continue + val holder = set.getSpecificHolder(itemStack) ?: continue + + holders.add(holder) + } + + return holders + } + /** * Get armor set that player is wearing. * diff --git a/eco-core/core-plugin/src/main/resources/ecoarmor.yml b/eco-core/core-plugin/src/main/resources/ecoarmor.yml index 5fa3dad..17919e4 100644 --- a/eco-core/core-plugin/src/main/resources/ecoarmor.yml +++ b/eco-core/core-plugin/src/main/resources/ecoarmor.yml @@ -85,6 +85,9 @@ sets: name: "&cReaper Helmet" advancedName: "Advanced&c Reaper Helmet" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&c&lREAPER SET BONUS" - "&8» &cDeal 25% more damage" @@ -109,6 +112,9 @@ sets: name: "&cReaper Chestplate" advancedName: "Advanced&c Reaper Chestplate" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&c&lREAPER SET BONUS" - "&8» &cDeal 25% more damage" @@ -133,6 +139,9 @@ sets: name: "&cReaper Elytra" advancedName: "Advanced&c Reaper Elytra" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&c&lREAPER SET BONUS" - "&8» &cDeal 25% more damage" @@ -157,6 +166,9 @@ sets: name: "&cReaper Leggings" advancedName: "Advanced&c Reaper Leggings" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&c&lREAPER SET BONUS" - "&8» &cDeal 25% more damage" @@ -181,6 +193,9 @@ sets: name: "&cReaper Boots" advancedName: "Advanced&c Reaper Boots" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&c&lREAPER SET BONUS" - "&8» &cDeal 25% more damage" @@ -276,6 +291,9 @@ sets: name: "&4Slayer Helmet" advancedName: "Advanced&4 Slayer Helmet" effectiveDurability: 768 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&4&lSLAYER SET BONUS" - "&8» &4Deal 50% more damage to bosses" @@ -302,6 +320,9 @@ sets: name: "&4Slayer Chestplate" advancedName: "Advanced&4 Slayer Chestplate" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&4&lSLAYER SET BONUS" - "&8» &4Deal 50% more damage to bosses" @@ -327,6 +348,9 @@ sets: name: "&4Slayer Elytra" advancedName: "Advanced &4Slayer Elytra" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&4&lSLAYER SET BONUS" - "&8» &4Deal 50% more damage to bosses" @@ -352,6 +376,9 @@ sets: name: "&4Slayer Leggings" advancedName: "Advanced&4 Slayer Leggings" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&4&lSLAYER SET BONUS" - "&8» &4Deal 50% more damage to bosses" @@ -377,6 +404,9 @@ sets: name: "&4Slayer Boots" advancedName: "Advanced&4 Slayer Boots" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&4&lSLAYER SET BONUS" - "&8» &4Deal 50% more damage to bosses" @@ -467,6 +497,9 @@ sets: name: "&5Angelic Helmet" advancedName: "Advanced&5 Angelic Helmet" effectiveDurability: 768 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&5&lANGELIC SET BONUS" - "&8» &dGain 10 more hearts" @@ -493,6 +526,9 @@ sets: name: "&5Angelic Chestplate" advancedName: "Advanced&5 Angelic Chestplate" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&5&lANGELIC SET BONUS" - "&8» &dGain 10 more hearts" @@ -519,6 +555,9 @@ sets: name: "&5Angelic Elytra" advancedName: "Advanced&5 Angelic Elytra" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&5&lANGELIC SET BONUS" - "&8» &dGain 10 more hearts" @@ -545,6 +584,9 @@ sets: name: "&5Angelic Leggings" advancedName: "Advanced&5 Angelic Leggings" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&5&lANGELIC SET BONUS" - "&8» &dGain 10 more hearts" @@ -571,6 +613,9 @@ sets: name: "&5Angelic Boots" advancedName: "Advanced&5 Angelic Boots" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&5&lANGELIC SET BONUS" - "&8» &dGain 10 more hearts" @@ -666,6 +711,9 @@ sets: name: "&bHuntress Helmet" advancedName: "Advanced&b Huntress Helmet" effectiveDurability: 1024 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&b&lHUNTRESS SET BONUS" - "&8» &bDeal 2.5x trident damage" @@ -692,6 +740,8 @@ sets: name: "&bHuntress Chestplate" advancedName: "Advanced&b Huntress Chestplate" effectiveDurability: 2048 + effects: [] + conditions: [] lore: - "&b&lHUNTRESS SET BONUS" - "&8» &bDeal 2.5x trident damage" @@ -718,6 +768,9 @@ sets: name: "&bHuntress Elytra" advancedName: "Advanced&b Huntress Elytra" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&b&lHUNTRESS SET BONUS" - "&8» &bDeal 2.5x trident damage" @@ -744,6 +797,9 @@ sets: name: "&bHuntress Leggings" advancedName: "Advanced&b Huntress Leggings" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&b&lHUNTRESS SET BONUS" - "&8» &bDeal 2.5x trident damage" @@ -770,6 +826,9 @@ sets: name: "&bHuntress Boots" advancedName: "Advanced&b Huntress Boots" effectiveDurability: 2048 + effects: [] + advancedEffects: [] + conditions: [] lore: - "&b&lHUNTRESS SET BONUS" - "&8» &bDeal 2.5x trident damage"