mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-03-11 13:29:35 +01:00
Improved vanilla enchant manipulation
This commit is contained in:
parent
48f4de9feb
commit
12e1b4bb42
@ -2,23 +2,23 @@ package com.willfp.ecoenchants.proxy.v1_17_R1
|
||||
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import net.minecraft.world.item.enchantment.Enchantment
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.craftbukkit.v1_17_R1.enchantments.CraftEnchantment
|
||||
|
||||
class EcoCraftEnchantment(
|
||||
target: Enchantment,
|
||||
private val _maxLevel: Int,
|
||||
private val conflicts: Collection<NamespacedKey>
|
||||
private val data: VanillaEnchantmentData
|
||||
) : CraftEnchantment(target) {
|
||||
override fun getMaxLevel(): Int = _maxLevel
|
||||
override fun getMaxLevel(): Int = data.maxLevel ?: super.getMaxLevel()
|
||||
|
||||
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
|
||||
if (other is EcoEnchant) {
|
||||
return other.conflictsWith(this)
|
||||
}
|
||||
|
||||
return conflicts.contains(other.key)
|
||||
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
|
||||
}
|
||||
|
||||
fun register() {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
|
||||
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
override fun registerNewCraftEnchantment(
|
||||
enchantment: Enchantment,
|
||||
maxLevel: Int,
|
||||
conflicts: Collection<NamespacedKey>
|
||||
data: VanillaEnchantmentData
|
||||
) {
|
||||
for (enchant in net.minecraft.core.IRegistry.X) {
|
||||
val key = org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey.fromMinecraft(
|
||||
@ -17,7 +17,7 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
if (key.key != enchantment.key.key) {
|
||||
continue
|
||||
}
|
||||
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
|
||||
EcoCraftEnchantment(enchant, data).register()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,23 @@ package com.willfp.ecoenchants.proxy.v1_18_R1
|
||||
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import net.minecraft.world.item.enchantment.Enchantment
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.craftbukkit.v1_18_R1.enchantments.CraftEnchantment
|
||||
|
||||
class EcoCraftEnchantment(
|
||||
target: Enchantment,
|
||||
private val _maxLevel: Int,
|
||||
private val conflicts: Collection<NamespacedKey>
|
||||
private val data: VanillaEnchantmentData
|
||||
) : CraftEnchantment(target) {
|
||||
override fun getMaxLevel(): Int = _maxLevel
|
||||
override fun getMaxLevel(): Int = data.maxLevel ?: super.getMaxLevel()
|
||||
|
||||
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
|
||||
if (other is EcoEnchant) {
|
||||
return other.conflictsWith(this)
|
||||
}
|
||||
|
||||
return conflicts.contains(other.key)
|
||||
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
|
||||
}
|
||||
|
||||
fun register() {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_18_R1
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
|
||||
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
override fun registerNewCraftEnchantment(
|
||||
enchantment: Enchantment,
|
||||
maxLevel: Int,
|
||||
conflicts: Collection<NamespacedKey>
|
||||
data: VanillaEnchantmentData
|
||||
) {
|
||||
for (enchant in net.minecraft.core.IRegistry.Y) {
|
||||
val key = org.bukkit.craftbukkit.v1_18_R1.util.CraftNamespacedKey.fromMinecraft(
|
||||
@ -17,7 +17,7 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
if (key.key != enchantment.key.key) {
|
||||
continue
|
||||
}
|
||||
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
|
||||
EcoCraftEnchantment(enchant, data).register()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,23 @@ package com.willfp.ecoenchants.proxy.v1_18_R2
|
||||
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import net.minecraft.world.item.enchantment.Enchantment
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.craftbukkit.v1_18_R2.enchantments.CraftEnchantment
|
||||
|
||||
class EcoCraftEnchantment(
|
||||
target: Enchantment,
|
||||
private val _maxLevel: Int,
|
||||
private val conflicts: Collection<NamespacedKey>
|
||||
private val data: VanillaEnchantmentData
|
||||
) : CraftEnchantment(target) {
|
||||
override fun getMaxLevel(): Int = _maxLevel
|
||||
override fun getMaxLevel(): Int = data.maxLevel ?: super.getMaxLevel()
|
||||
|
||||
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
|
||||
if (other is EcoEnchant) {
|
||||
return other.conflictsWith(this)
|
||||
}
|
||||
|
||||
return conflicts.contains(other.key)
|
||||
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
|
||||
}
|
||||
|
||||
fun register() {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_18_R2
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
|
||||
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
override fun registerNewCraftEnchantment(
|
||||
enchantment: Enchantment,
|
||||
maxLevel: Int,
|
||||
conflicts: Collection<NamespacedKey>
|
||||
data: VanillaEnchantmentData
|
||||
) {
|
||||
for (enchant in net.minecraft.core.IRegistry.V) {
|
||||
val key = org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey.fromMinecraft(
|
||||
@ -17,7 +17,7 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
if (key.key != enchantment.key.key) {
|
||||
continue
|
||||
}
|
||||
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
|
||||
EcoCraftEnchantment(enchant, data).register()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,22 @@ package com.willfp.ecoenchants.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import net.minecraft.world.item.enchantment.Enchantment
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.craftbukkit.v1_19_R1.enchantments.CraftEnchantment
|
||||
|
||||
class EcoCraftEnchantment(
|
||||
target: Enchantment,
|
||||
private val _maxLevel: Int,
|
||||
private val conflicts: Collection<NamespacedKey>
|
||||
private val data: VanillaEnchantmentData
|
||||
) : CraftEnchantment(target) {
|
||||
override fun getMaxLevel(): Int = _maxLevel
|
||||
override fun getMaxLevel(): Int = data.maxLevel ?: super.getMaxLevel()
|
||||
|
||||
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
|
||||
if (other is EcoEnchant) {
|
||||
return other.conflictsWith(this)
|
||||
}
|
||||
|
||||
return conflicts.contains(other.key)
|
||||
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
|
||||
}
|
||||
|
||||
fun register() {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
|
||||
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
override fun registerNewCraftEnchantment(
|
||||
enchantment: Enchantment,
|
||||
maxLevel: Int,
|
||||
conflicts: Collection<NamespacedKey>
|
||||
data: VanillaEnchantmentData
|
||||
) {
|
||||
for (enchant in net.minecraft.core.IRegistry.W) {
|
||||
val key = org.bukkit.craftbukkit.v1_19_R1.util.CraftNamespacedKey.fromMinecraft(
|
||||
@ -17,7 +17,7 @@ class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
|
||||
if (key.key != enchantment.key.key) {
|
||||
continue
|
||||
}
|
||||
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
|
||||
EcoCraftEnchantment(enchant, data).register()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.willfp.ecoenchants.rarity.EnchantmentRarities
|
||||
import com.willfp.ecoenchants.rarity.EnchantmentRarity
|
||||
import com.willfp.ecoenchants.type.EnchantmentType
|
||||
import com.willfp.ecoenchants.type.EnchantmentTypes
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
@ -147,13 +148,21 @@ class VanillaEcoEnchantLike(
|
||||
}
|
||||
}
|
||||
|
||||
private val enchantmentOptions = arrayOf(
|
||||
"max-level",
|
||||
"conflicts"
|
||||
)
|
||||
|
||||
fun registerVanillaEnchants(plugin: EcoEnchantsPlugin) {
|
||||
for (vanilla in plugin.vanillaEnchantsYml.getKeys(false)) {
|
||||
if (plugin.vanillaEnchantsYml.has("$vanilla.max-level")) {
|
||||
if (enchantmentOptions.any { plugin.vanillaEnchantsYml.has("$vanilla.$it") }) {
|
||||
plugin.getProxy(EcoCraftEnchantmentManagerProxy::class.java).registerNewCraftEnchantment(
|
||||
Enchantment.getByKey(NamespacedKey.minecraft(vanilla))!!,
|
||||
plugin.vanillaEnchantsYml.getInt("$vanilla.max-level"),
|
||||
plugin.vanillaEnchantsYml.getStrings("$vanilla.conflicts").map { NamespacedKey.minecraft(it) }
|
||||
VanillaEnchantmentData(
|
||||
plugin.vanillaEnchantsYml.getIntOrNull("$vanilla.max-level"),
|
||||
plugin.vanillaEnchantsYml.getStringsOrNull("$vanilla.conflicts")
|
||||
?.map { NamespacedKey.minecraft(it) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
# Rarity option does not affect vanilla enchantments.
|
||||
# The option is there for the display option to sort by rarity.
|
||||
|
||||
# If you enable custom max levels for a vanilla enchant you have to also specify conflicts,
|
||||
# if you don't the enchantment will have no conflicts at all, and vice-versa; changing conflicts
|
||||
# will require you to specify the max level.
|
||||
|
||||
protection:
|
||||
name: "Protection"
|
||||
description: "Reduces incoming damage by &a%placeholder%%"
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.willfp.ecoenchants.proxy.proxies
|
||||
|
||||
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
|
||||
interface EcoCraftEnchantmentManagerProxy {
|
||||
fun registerNewCraftEnchantment(enchantment: Enchantment, maxLevel: Int, conflicts: Collection<NamespacedKey>)
|
||||
fun registerNewCraftEnchantment(enchantment: Enchantment, data: VanillaEnchantmentData)
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.willfp.ecoenchants.vanilla
|
||||
|
||||
import org.bukkit.NamespacedKey
|
||||
|
||||
data class VanillaEnchantmentData(
|
||||
val maxLevel: Int?,
|
||||
val conflicts: Collection<NamespacedKey>?
|
||||
)
|
Loading…
Reference in New Issue
Block a user