mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-27 02:49:22 +00:00
Refactoring
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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<ConfiguredCondition>,
|
||||
override val effects: Set<ConfiguredEffect>) : Holder {
|
||||
}
|
||||
@@ -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<ArmorSlot, ItemStack> = EnumMap(ArmorSlot::class.java)
|
||||
private val items = notNullMapOf<ArmorSlot, ItemStack>()
|
||||
|
||||
/**
|
||||
* Items in advanced set.
|
||||
*/
|
||||
private val advancedItems: MutableMap<ArmorSlot, ItemStack> = EnumMap(ArmorSlot::class.java)
|
||||
private val advancedItems = notNullMapOf<ArmorSlot, ItemStack>()
|
||||
|
||||
/**
|
||||
* 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
|
||||
+ "}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleHolder(
|
||||
override val conditions: Set<ConfiguredCondition>,
|
||||
override val effects: Set<ConfiguredEffect>
|
||||
) : Holder
|
||||
@@ -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<ConfiguredCondition>,
|
||||
override val effects: Set<ConfiguredEffect>) : Holder {
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<EcoPlugin?>(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<ArmorSlot, TierProperties> = NotNullMap(EnumMap(ArmorSlot::class.java))
|
||||
val properties = notNullMapOf<ArmorSlot, TierProperties>()
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -4,4 +4,13 @@ class NotNullMap<K, V>(private val handle: MutableMap<K, V>) : MutableMap<K, V>
|
||||
override fun get(key: K): V {
|
||||
return handle[key]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified K, reified V> Map<K, V>.toNotNullMap(): NotNullMap<K, V> =
|
||||
NotNullMap(this.toMutableMap())
|
||||
|
||||
inline fun <reified K, reified V> notNullMapOf(): NotNullMap<K, V> =
|
||||
mutableMapOf<K, V>().toNotNullMap()
|
||||
|
||||
inline fun <reified K, reified V> notNullMapOf(vararg pairs: Pair<K, V>): NotNullMap<K, V> =
|
||||
mutableMapOf(*pairs).toNotNullMap()
|
||||
Reference in New Issue
Block a user