mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-26 18:39:24 +00:00
Added tier arg parser
This commit is contained in:
@@ -2,21 +2,19 @@ package com.willfp.ecoarmor
|
||||
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.eco.core.display.DisplayModule
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.util.ListUtils
|
||||
import com.willfp.ecoarmor.commands.CommandEcoarmor
|
||||
import com.willfp.ecoarmor.config.EcoArmorYml
|
||||
import com.willfp.ecoarmor.display.ArmorDisplay
|
||||
import com.willfp.ecoarmor.sets.ArmorSets
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils
|
||||
import com.willfp.ecoarmor.sets.EffectiveDurabilityListener
|
||||
import com.willfp.ecoarmor.sets.PreventSkullPlaceListener
|
||||
import com.willfp.ecoarmor.sets.*
|
||||
import com.willfp.ecoarmor.upgrades.AdvancementShardListener
|
||||
import com.willfp.ecoarmor.upgrades.CrystalListener
|
||||
import com.willfp.ecoarmor.upgrades.TierArgParser
|
||||
import com.willfp.ecoarmor.upgrades.Tiers
|
||||
import com.willfp.ecoarmor.util.DiscoverRecipeListener
|
||||
import com.willfp.ecoarmor.util.EffectListener
|
||||
import com.willfp.libreforge.LibReforgePlugin
|
||||
import com.willfp.libreforge.chains.EffectChains
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
class EcoArmorPlugin : LibReforgePlugin(687, 10002, "&c") {
|
||||
@@ -25,6 +23,7 @@ class EcoArmorPlugin : LibReforgePlugin(687, 10002, "&c") {
|
||||
init {
|
||||
instance = this
|
||||
ecoArmorYml = EcoArmorYml(this)
|
||||
Items.registerArgParser(TierArgParser())
|
||||
registerHolderProvider { ListUtils.toSingletonList(ArmorUtils.getActiveSet(it)) }
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,8 @@ enum class ArmorSlot(
|
||||
}
|
||||
val material = itemStack.type
|
||||
val split = material.name.lowercase(Locale.getDefault()).split("_").toTypedArray()
|
||||
val name = split[split.size - 1]
|
||||
return when (name) {
|
||||
"helmet", "head" -> HELMET
|
||||
"chestplate" -> CHESTPLATE
|
||||
"elytra" -> ELYTRA
|
||||
"leggings" -> LEGGINGS
|
||||
"boots" -> BOOTS
|
||||
else -> null
|
||||
}
|
||||
|
||||
return getSlot(split[split.size - 1])
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -189,18 +189,7 @@ object ArmorUtils {
|
||||
tier: Tier
|
||||
) {
|
||||
val meta = itemStack.itemMeta ?: return
|
||||
if (!meta.persistentDataContainer.has(
|
||||
PLUGIN.namespacedKeyFactory.create("set"),
|
||||
PersistentDataType.STRING
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
meta.persistentDataContainer.set(
|
||||
PLUGIN.namespacedKeyFactory.create("tier"),
|
||||
PersistentDataType.STRING,
|
||||
tier.id
|
||||
)
|
||||
setTierKey(meta, tier)
|
||||
val slot = getSlot(itemStack) ?: return
|
||||
val armor = tier.properties[slot].armor
|
||||
val toughness = tier.properties[slot].toughness
|
||||
@@ -300,9 +289,35 @@ object ArmorUtils {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
itemStack.itemMeta = meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tier on item.
|
||||
*
|
||||
* @param meta The item to check.
|
||||
* @param tier The tier to set.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun setTierKey(
|
||||
meta: ItemMeta,
|
||||
tier: Tier
|
||||
) {
|
||||
if (!meta.persistentDataContainer.has(
|
||||
PLUGIN.namespacedKeyFactory.create("set"),
|
||||
PersistentDataType.STRING
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
meta.persistentDataContainer.set(
|
||||
PLUGIN.namespacedKeyFactory.create("tier"),
|
||||
PersistentDataType.STRING,
|
||||
tier.id
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if player is wearing advanced set.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.willfp.ecoarmor.upgrades
|
||||
|
||||
import com.willfp.eco.core.items.args.LookupArgParser
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.function.Predicate
|
||||
|
||||
class TierArgParser : LookupArgParser {
|
||||
override fun parseArguments(
|
||||
args: Array<String>,
|
||||
meta: ItemMeta
|
||||
): Predicate<ItemStack>? {
|
||||
var tier: Tier? = null
|
||||
|
||||
for (arg in args) {
|
||||
val split = arg.split(":").toTypedArray()
|
||||
if (split.size == 1 || !split[0].equals("tier", ignoreCase = true)) {
|
||||
continue
|
||||
}
|
||||
val match = Tiers.getByID(split[1].lowercase()) ?: continue
|
||||
tier = match
|
||||
break
|
||||
}
|
||||
|
||||
tier ?: return null
|
||||
|
||||
ArmorUtils.setTierKey(meta, tier)
|
||||
|
||||
return Predicate { test ->
|
||||
val testMeta = test.itemMeta ?: return@Predicate false
|
||||
tier == ArmorUtils.getTier(testMeta)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,15 @@ class EffectListener(
|
||||
fun onArmorChange(event: ArmorChangeEvent) {
|
||||
val player = event.player
|
||||
|
||||
for (itemStack in player.inventory.armorContents) {
|
||||
if (itemStack == null) {
|
||||
continue
|
||||
}
|
||||
|
||||
val tier = ArmorUtils.getTier(itemStack) ?: continue
|
||||
ArmorUtils.setTier(itemStack, tier)
|
||||
}
|
||||
|
||||
player.updateEffects()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user