Completed 1.20.3 rewrite, awaiting bugfixing

This commit is contained in:
Will FP
2023-12-07 15:13:26 +00:00
parent 3dceea0b38
commit 72d51a56ae
69 changed files with 424 additions and 1155 deletions

View File

@@ -8,7 +8,6 @@ version = rootProject.version
subprojects {
dependencies {
compileOnly(project(":eco-core:core-proxy"))
compileOnly(project(":eco-core:core-plugin"))
}
}

View File

@@ -1,12 +1,12 @@
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 com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.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 data: VanillaEnchantmentData
@@ -21,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,8 +1,7 @@
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 com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,12 +1,12 @@
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 com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.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 data: VanillaEnchantmentData
@@ -21,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,8 +1,7 @@
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 com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,12 +1,12 @@
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 com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.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 data: VanillaEnchantmentData
@@ -21,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,8 +1,7 @@
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 com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,11 +1,12 @@
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 com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.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 data: VanillaEnchantmentData
@@ -20,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,8 +1,7 @@
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 com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,11 +1,12 @@
package com.willfp.ecoenchants.proxy.v1_19_R2
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_19_R2.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val data: VanillaEnchantmentData
@@ -20,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,11 +1,8 @@
package com.willfp.ecoenchants.proxy.v1_19_R2
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import net.minecraft.core.Registry
import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,11 +1,12 @@
package com.willfp.ecoenchants.proxy.v1_19_R3
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_19_R3.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val data: VanillaEnchantmentData
@@ -20,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,11 +1,8 @@
package com.willfp.ecoenchants.proxy.v1_19_R3
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import net.minecraft.core.Registry
import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,11 +1,12 @@
package com.willfp.ecoenchants.proxy.v1_20_R1
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_20_R1.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val data: VanillaEnchantmentData
@@ -20,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,11 +1,8 @@
package com.willfp.ecoenchants.proxy.v1_20_R1
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import net.minecraft.core.Registry
import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {

View File

@@ -1,9 +1,10 @@
package com.willfp.ecoenchants.proxy.v1_20_R2
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import com.willfp.ecoenchants.enchant.registration.legacy.LegacyDelegatedEnchantment
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_20_R2.enchantments.CraftEnchantment
class EcoCraftEnchantment(
@@ -20,7 +21,26 @@ class EcoCraftEnchantment(
return data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
@Suppress("UNCHECKED_CAST")
fun register() {
EcoEnchants.register(this)
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, org.bukkit.enchantments.Enchantment>).apply { remove(key) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, org.bukkit.enchantments.Enchantment>).apply { remove(name) }
}
org.bukkit.enchantments.Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
org.bukkit.enchantments.Enchantment.registerEnchantment(this)
}
}

View File

@@ -1,7 +1,7 @@
package com.willfp.ecoenchants.proxy.v1_20_R2
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import com.willfp.ecoenchants.enchant.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.enchant.VanillaEnchantmentData
import net.minecraft.core.registries.BuiltInRegistries
import org.bukkit.enchantments.Enchantment

View File

@@ -1,28 +0,0 @@
package com.willfp.ecoenchants.proxy.v1_20_R3
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_20_R3.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
key: NamespacedKey,
private val data: VanillaEnchantmentData
) : CraftEnchantment(key, target) {
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 data.conflicts?.contains(other.key) ?: super.conflictsWith(other)
}
fun register() {
EcoEnchants.register(this)
}
}

View File

@@ -1,26 +0,0 @@
package com.willfp.ecoenchants.proxy.v1_20_R3
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.proxy.v1_20_R3.EcoCraftEnchantment
import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
import net.minecraft.core.registries.BuiltInRegistries
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
override fun registerNewCraftEnchantment(
enchantment: Enchantment,
data: VanillaEnchantmentData
) {
for (enchant in BuiltInRegistries.ENCHANTMENT) {
val key = org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey.fromMinecraft(
BuiltInRegistries.ENCHANTMENT.getKey(enchant)
)
if (key.key != enchantment.key.key) {
continue
}
EcoCraftEnchantment(enchant, key, data).register()
}
}
}

View File

@@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.registration.modern.ModernEnchantmentRegistererProxy
import com.willfp.ecoenchants.proxy.v1_20_R3.registration.DelegatedCraftEnchantment
import com.willfp.ecoenchants.proxy.v1_20_R3.registration.ModifiedVanillaCraftEnchantment
import com.willfp.ecoenchants.proxy.v1_20_R3.registration.VanillaEcoEnchantsEnchantment
import net.minecraft.core.MappedRegistry
import net.minecraft.core.Registry
@@ -29,8 +30,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
.get(Bukkit.getServer())
as HashMap<Class<*>, org.bukkit.Registry<*>>
// Replace bukkit enchantment registry
init {
override fun replaceRegistry() {
val server = Bukkit.getServer() as CraftServer
registries[Enchantment::class.java] = CraftRegistry(
@@ -40,7 +40,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
val enchant = EcoEnchants.getByID(key.key)
if (enchant == null) {
CraftEnchantment(key, registry)
ModifiedVanillaCraftEnchantment(key, registry)
} else {
DelegatedCraftEnchantment(enchant, registry)
}

View File

@@ -3,7 +3,6 @@ package com.willfp.ecoenchants.proxy.v1_20_R3.registration
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchants.wrap
import io.papermc.paper.enchantments.EnchantmentRarity
import net.kyori.adventure.text.Component
import net.minecraft.world.item.enchantment.Enchantment
@@ -65,7 +64,7 @@ class DelegatedCraftEnchantment(
}
override fun displayName(level: Int): Component {
return StringUtils.toComponent(this.wrap().getFormattedName(level))
return StringUtils.toComponent(enchant.getFormattedName(level))
}
override fun isTradeable(): Boolean {

View File

@@ -0,0 +1,13 @@
package com.willfp.ecoenchants.proxy.v1_20_R3.registration
import com.willfp.ecoenchants.enchant.vanillaEnchantmentData
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_20_R3.enchantments.CraftEnchantment
class ModifiedVanillaCraftEnchantment(
key: NamespacedKey,
target: Enchantment
) : CraftEnchantment(key, target) {
override fun getMaxLevel(): Int = this.vanillaEnchantmentData?.maxLevel ?: super.getMaxLevel()
}

View File

@@ -6,7 +6,6 @@ dependencies {
include("*.jar")
}
)
compileOnly(project(":eco-core:core-proxy"))
compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
compileOnly("net.essentialsx:EssentialsX:2.19.7")
compileOnly("commons-lang:commons-lang:2.6")

View File

@@ -13,13 +13,11 @@ import com.willfp.ecoenchants.config.VanillaEnchantsYml
import com.willfp.ecoenchants.display.DisplayCache
import com.willfp.ecoenchants.display.EnchantDisplay
import com.willfp.ecoenchants.display.EnchantSorter
import com.willfp.ecoenchants.enchant.EcoEnchantLevel
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.EnchantGUI
import com.willfp.ecoenchants.enchant.FoundEcoEnchantLevel
import com.willfp.ecoenchants.enchant.registration.EnchantmentRegisterer
import com.willfp.ecoenchants.enchants.EcoEnchantLevel
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.EnchantGUI
import com.willfp.ecoenchants.enchants.FoundEcoEnchantLevel
import com.willfp.ecoenchants.enchants.LoreConversion
import com.willfp.ecoenchants.enchants.registerVanillaEnchants
import com.willfp.ecoenchants.integrations.EnchantRegistrations
import com.willfp.ecoenchants.integrations.plugins.CMIIntegration
import com.willfp.ecoenchants.integrations.plugins.EssentialsIntegration
@@ -40,6 +38,9 @@ import com.willfp.libreforge.registerSpecificRefreshFunction
import org.bukkit.entity.Player
import org.bukkit.event.Listener
internal lateinit var plugin: EcoEnchantsPlugin
private set
class EcoEnchantsPlugin : LibreforgePlugin() {
val targetsYml = TargetsYml(this)
val rarityYml = RarityYml(this)
@@ -51,7 +52,7 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
val enchantmentRegisterer: EnchantmentRegisterer = TODO()
init {
instance = this
plugin = this
}
override fun loadConfigCategories(): List<ConfigCategory> {
@@ -88,8 +89,6 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
}
override fun handleReload() {
registerVanillaEnchants(this)
DisplayCache.reload()
EnchantSorter.reload(this)
ExtraItemSupport.reload(this)
@@ -102,7 +101,7 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
EnchantingTableSupport(this),
LootSupport(this),
AnvilSupport(this),
LoreConversion(this),
//LoreConversion(this),
GrindstoneSupport(this)
)
}
@@ -127,11 +126,4 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
EnchantDisplay(this)
} else null
}
companion object {
/** Instance of EcoEnchants. */
@JvmStatic
lateinit var instance: EcoEnchantsPlugin
private set
}
}

View File

@@ -4,10 +4,8 @@ import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.savedDisplayName
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.type.EnchantmentTypes
import org.bukkit.Bukkit
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchant.wrap
import org.bukkit.NamespacedKey
import org.bukkit.command.CommandSender
import org.bukkit.enchantments.Enchantment
@@ -48,7 +46,7 @@ class CommandEnchant(plugin: EcoPlugin) : PluginCommand(
sender.sendMessage(
plugin.langYml.getMessage("added-enchant", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%enchant%", enchant.wrap().displayName)
.replace("%enchant%", enchant.wrap().getFormattedName(0))
.replace("%player%", player.savedDisplayName)
)
} else {
@@ -59,7 +57,7 @@ class CommandEnchant(plugin: EcoPlugin) : PluginCommand(
sender.sendMessage(
plugin.langYml.getMessage("removed-enchant", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%enchant%", enchant.wrap().displayName)
.replace("%enchant%", enchant.wrap().getFormattedName(0))
.replace("%player%", player.savedDisplayName)
)
}

View File

@@ -3,7 +3,7 @@ package com.willfp.ecoenchants.commands
import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.EnchantGUI
import com.willfp.ecoenchants.enchant.EnchantGUI
import org.bukkit.ChatColor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

View File

@@ -2,7 +2,7 @@ package com.willfp.ecoenchants.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.Subcommand
import com.willfp.ecoenchants.enchants.EnchantGUI
import com.willfp.ecoenchants.enchant.EnchantGUI
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

View File

@@ -7,8 +7,8 @@ import com.willfp.eco.core.items.builder.EnchantedBookBuilder
import com.willfp.eco.util.NumberUtils
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.wrap
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.rarity.EnchantmentRarity
import com.willfp.ecoenchants.type.EnchantmentType
@@ -51,7 +51,7 @@ class CommandGiveRandomBook(plugin: EcoPlugin) : PluginCommand(
val enchantment = EcoEnchants.values()
.filter {
when (filter) {
is EnchantmentRarity -> it.enchantmentRarity == filter
is EnchantmentRarity -> it.rarity == filter
is EnchantmentType -> it.type == filter
else -> true
} && it.maxLevel >= minLevel
@@ -64,7 +64,7 @@ class CommandGiveRandomBook(plugin: EcoPlugin) : PluginCommand(
val level = NumberUtils.randInt(minLevel, maxLevel.coerceAtMost(enchantment.maxLevel))
val item = EnchantedBookBuilder()
.addStoredEnchantment(enchantment, level)
.addStoredEnchantment(enchantment.enchantment, level)
.build()
DropQueue(player)
@@ -75,7 +75,7 @@ class CommandGiveRandomBook(plugin: EcoPlugin) : PluginCommand(
sender.sendMessage(
plugin.langYml.getMessage("gave-random-book", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%player%", player.name)
.replace("%enchantment%", enchantment.wrap().getFormattedName(level))
.replace("%enchantment%", enchantment.getFormattedName(level))
)
}

View File

@@ -3,9 +3,6 @@ package com.willfp.ecoenchants.config
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.BaseConfig
import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.ExtendableConfig
import com.willfp.ecoenchants.enchants.EcoEnchant
import org.bukkit.enchantments.Enchantment
class TypesYml(plugin: EcoPlugin) : BaseConfig("types", plugin, true, ConfigType.YAML)
class TargetsYml(plugin: EcoPlugin) : BaseConfig("targets", plugin, true, ConfigType.YAML)

View File

@@ -1,4 +1,4 @@
package com.willfp.ecoenchants.enchants
package com.willfp.ecoenchants.display
class DescriptionPlaceholder(
val id: String,

View File

@@ -9,8 +9,8 @@ import com.willfp.eco.core.fast.fast
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.commands.CommandToggleDescriptions.Companion.seesEnchantmentDescriptions
import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.wrap
import com.willfp.ecoenchants.target.EnchantmentTargets.isEnchantable
import com.willfp.libreforge.ItemProvidedHolder
import org.bukkit.Material

View File

@@ -7,7 +7,7 @@ import com.willfp.eco.util.NumberUtils
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.formatEco
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchantLike
import com.willfp.ecoenchants.enchant.EcoEnchantLike
import org.bukkit.entity.Player
// This is an object to be able to invalidate the cache on reload
@@ -35,20 +35,18 @@ fun EcoEnchantLike.getFormattedName(
level: Int,
showNotMet: Boolean = false
): String {
val plugin = EcoEnchantsPlugin.instance
return DisplayCache.nameCache.get(DisplayableEnchant(this, level, showNotMet)) {
val numerals = plugin.configYml.getBool("display.numerals.enabled") &&
level <= plugin.configYml.getInt("display.numerals.threshold")
val typeFormat = this.type.format
val name = this.unformattedDisplayName
val name = this.rawDisplayName
val number = if (numerals) NumberUtils.toNumeral(level) else level.toString()
val dontShowNumber = (level == 1 && this.enchant.maxLevel == 1) || level < 1
val dontShowNumber = (level == 1 && this.enchantment.maxLevel == 1) || level < 1
val notMetFormat = if (showNotMet) plugin.configYml.getString("display.not-met.format") else ""
if (plugin.configYml.getBool("display.above-max-level.enabled") && level > this.enchant.maxLevel) {
if (plugin.configYml.getBool("display.above-max-level.enabled") && level > this.enchantment.maxLevel) {
val format = plugin.configYml.getString("display.above-max-level.format")
val levelOnly = plugin.configYml.getBool("display.above-max-level.level-only")
@@ -74,13 +72,11 @@ private val resetTags = arrayOf(
)
fun EcoEnchantLike.getFormattedDescription(level: Int, player: Player? = null): List<String> {
val plugin = EcoEnchantsPlugin.instance
return DisplayCache.descriptionCache.get(DisplayableEnchant(this, level)) {
val descriptionFormat = plugin.configYml.getString("display.descriptions.format")
val wrap = plugin.configYml.getInt("display.descriptions.word-wrap")
var description = descriptionFormat + this.getUnformattedDescription(level, player)
var description = descriptionFormat + this.getRawDescription(level, player)
// Replace reset tags with description format
for (tag in resetTags) {

View File

@@ -1,7 +1,7 @@
package com.willfp.ecoenchants.display
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.enchant.wrap
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.rarity.EnchantmentRarity
import com.willfp.ecoenchants.type.EnchantmentType
@@ -41,13 +41,13 @@ fun List<EnchantmentSorter>.getSafely(index: Int) =
object AlphabeticSorter : EnchantmentSorter {
override fun sort(enchantments: Collection<Enchantment>, children: List<EnchantmentSorter>): List<Enchantment> {
return enchantments.sortedBy { ChatColor.stripColor(it.wrap().displayName) }
return enchantments.sortedBy { ChatColor.stripColor(it.wrap().getFormattedName(0)) }
}
}
object LengthSorter : EnchantmentSorter {
override fun sort(enchantments: Collection<Enchantment>, children: List<EnchantmentSorter>): List<Enchantment> {
return enchantments.sortedBy { ChatColor.stripColor(it.wrap().displayName)!!.length }
return enchantments.sortedBy { ChatColor.stripColor(it.wrap().getFormattedName(0))!!.length }
}
}
@@ -93,7 +93,7 @@ object RaritySorter : EnchantmentSorter {
for (rarity in rarities) {
for (enchantment in children.getSafely(0).sort(enchantments, children.drop(1))) {
if (rarity != enchantment.wrap().enchantmentRarity) {
if (rarity != enchantment.wrap().rarity) {
continue
}

View File

@@ -24,6 +24,16 @@ interface EcoEnchant : KRegistrable, EcoEnchantLike {
*/
val maxLevel: Int
/**
* If this enchantment conflicts with all other enchantments.
*/
val conflictsWithEverything: Boolean
/**
* The conflicts.
*/
val conflicts: Set<Enchantment>
/**
* The enchantment targets.
*/

View File

@@ -8,8 +8,7 @@ import com.willfp.eco.core.placeholder.StaticPlaceholder
import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.DescriptionPlaceholder
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.display.DescriptionPlaceholder
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
import com.willfp.ecoenchants.rarity.EnchantmentRarity
import com.willfp.ecoenchants.type.EnchantmentType

View File

@@ -7,7 +7,6 @@ import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentPermanenceCurse
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentRepairing
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentReplenish
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentSoulbound
import com.willfp.ecoenchants.enchants.sendPrompts
import com.willfp.ecoenchants.integrations.EnchantRegistrations
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.target.EnchantmentTargets
@@ -39,42 +38,46 @@ object EcoEnchants : RegistrableCategory<EcoEnchant>("enchant", "enchants") {
override fun afterReload(plugin: LibreforgePlugin) {
plugin as EcoEnchantsPlugin
sendPrompts(plugin)
registerHardcodedEnchantments(plugin)
}
override fun acceptConfig(plugin: LibreforgePlugin, id: String, config: Config) {
plugin as EcoEnchantsPlugin
val enchant = createEnchantment(plugin, id, config) ?: return
registry.register(enchant)
plugin.enchantmentRegisterer.register(enchant)
EnchantRegistrations.registerEnchantments()
if (!config.has("effects")) {
return
}
private fun createEnchantment(plugin: LibreforgePlugin, id: String, config: Config): EcoEnchant? {
plugin as EcoEnchantsPlugin
if (config.has("effects")) {
// Libreforge
return LibreforgeEcoEnchant(
val enchant = LibreforgeEcoEnchant(
id,
config,
plugin
)
} else {
TODO()
}
doRegister(plugin, enchant)
}
private fun doRegister(plugin: EcoEnchantsPlugin, enchant: EcoEnchant) {
plugin.enchantmentRegisterer.register(enchant)
// Register delegated versions
registry.register(enchant.enchantment as EcoEnchant)
EnchantRegistrations.registerEnchantments()
}
/** Register the hardcoded enchantments. */
private fun registerHardcodedEnchantments(
plugin: EcoEnchantsPlugin
) {
EnchantmentPermanenceCurse(plugin)
EnchantmentRepairing(plugin)
EnchantmentReplenish(plugin)
val hardcodedEnchantments = listOf(
EnchantmentPermanenceCurse(plugin),
EnchantmentRepairing(plugin),
EnchantmentReplenish(plugin),
EnchantmentSoulbound(plugin)
)
for (enchantment in hardcodedEnchantments) {
if (enchantment.isPresent) {
doRegister(plugin, enchantment)
}
}
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.ecoenchants.enchants
package com.willfp.ecoenchants.enchant
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.config.base.LangYml
@@ -73,7 +73,7 @@ object EnchantGUI {
onRender { player, menu ->
val atCaptive = menu.getCaptiveItem(player, captiveRow, captiveColumn)
if (atCaptive.isEmpty || atCaptive == null || atCaptive.type == Material.BOOK) {
menu.setState(player, "enchants", EcoEnchants.values().sortForDisplay())
menu.setState(player, "enchants", EcoEnchants.values().map { it.enchantment }.sortForDisplay())
} else {
menu.setState(
player,
@@ -207,32 +207,32 @@ private val cachedEnchantmentSlots = Caffeine.newBuilder()
private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin, player: Player): Slot {
return cachedEnchantmentSlots.get(this) {
val level = if (plugin.configYml.getBool("enchantinfo.item.show-max-level")) {
enchant.maxLevel
it.maxLevel
} else {
1
}
slot(
EnchantedBookBuilder()
.addStoredEnchantment(enchant, level)
.addStoredEnchantment(enchantment, level)
.addItemFlag(ItemFlag.HIDE_ENCHANTS)
.setDisplayName(enchant.getFormattedName(level))
.addLoreLines(enchant.getFormattedDescription(level, player))
.setDisplayName(this.getFormattedName(level))
.addLoreLines(this.getFormattedDescription(level, player))
.addLoreLines {
plugin.configYml.getStrings("enchantinfo.item.lore")
.map {
it.replace("%max_level%", enchant.maxLevel.toString())
.replace("%rarity%", enchant.enchantmentRarity.displayName)
it.replace("%max_level%", enchantment.maxLevel.toString())
.replace("%rarity%", this.rarity.displayName)
.replace(
"%targets%",
enchant.targets.joinToString(", ") { target -> target.displayName }
this.targets.joinToString(", ") { target -> target.displayName }
)
.replace(
"%conflicts%",
if (enchant.conflictsWithEverything) {
if (this.conflictsWithEverything) {
plugin.langYml.getFormattedString("all-conflicts")
} else {
enchant.conflicts.joinToString(", ") { conflict ->
this.conflicts.joinToString(", ") { conflict ->
conflict.wrap().getFormattedName(0)
}.ifEmpty { plugin.langYml.getFormattedString("no-conflicts") }
}

View File

@@ -1,7 +1,7 @@
package com.willfp.ecoenchants.enchant
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchant.impl.VanillaEcoEnchantLike
import com.willfp.ecoenchants.plugin
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
@@ -14,7 +14,7 @@ fun Enchantment.wrap(): EcoEnchantLike {
}
return ecoEnchantLikes.getOrPut(this.key) {
VanillaEcoEnchantLike(this, EcoEnchantsPlugin.instance)
VanillaEcoEnchantLike(this, plugin)
}
}

View File

@@ -0,0 +1,24 @@
package com.willfp.ecoenchants.enchant
import com.willfp.ecoenchants.plugin
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
val Enchantment.vanillaEnchantmentData: VanillaEnchantmentData?
get() {
val vanilla = plugin.vanillaEnchantsYml.getSubsectionOrNull(key.key) ?: return null
return VanillaEnchantmentData(
vanilla.getIntOrNull("max-level"),
vanilla.getStringsOrNull("conflicts")?.map { NamespacedKey.minecraft(it) }
)
}
interface EcoCraftEnchantmentManagerProxy {
fun registerNewCraftEnchantment(enchantment: Enchantment, data: VanillaEnchantmentData)
}
data class VanillaEnchantmentData(
val maxLevel: Int?,
val conflicts: Collection<NamespacedKey>?
)

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoenchants.enchant.impl
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.util.containsIgnoreCase
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchantLevel
@@ -32,6 +33,14 @@ abstract class EcoEnchantBase(
override val maxLevel = config.getInt("max-level")
override val conflictsWithEverything: Boolean
get() = conflictIds.containsIgnoreCase("all")
|| conflictIds.containsIgnoreCase("everything")
override val conflicts = config.getStrings("conflicts")
.mapNotNull { Enchantment.getByKey(NamespacedKey.minecraft(it)) }
.toSet()
override val targets = config.getStrings("targets")
.mapNotNull { EnchantmentTargets[it] }
.toSet()

View File

@@ -12,11 +12,15 @@ abstract class HardcodedEcoEnchant(
id: String,
plugin: EcoEnchantsPlugin
) : EcoEnchantBase(id, plugin) {
final override fun loadConfig(): Config {
return File(plugin.dataFolder, "enchants")
private val file: File?
get() = File(plugin.dataFolder, "enchants")
.walk()
.firstOrNull { file -> file.nameWithoutExtension == id }
.readConfig(ConfigType.YAML)
val isPresent = file != null
final override fun loadConfig(): Config {
return file.readConfig(ConfigType.YAML)
}
override fun createLevel(level: Int): EcoEnchantLevel {

View File

@@ -2,7 +2,7 @@ package com.willfp.ecoenchants.enchant.impl.hardcoded
import com.willfp.eco.util.DurabilityUtils
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchant.impl.HardcodedEcoEnchant
import com.willfp.ecoenchants.target.EnchantLookup.getActiveEnchantLevelInSlot
import com.willfp.ecoenchants.target.EnchantLookup.hasEnchantActive
import com.willfp.libreforge.slot.impl.SlotTypeHands
@@ -10,12 +10,11 @@ import org.bukkit.Bukkit
class EnchantmentRepairing(
plugin: EcoEnchantsPlugin
) : EcoEnchant(
) : HardcodedEcoEnchant(
"repairing",
plugin,
force = false
plugin
) {
override fun onInit() {
override fun onRegister() {
val frequency = config.getInt("frequency").toLong()
plugin.scheduler.runTimer(frequency, frequency) {

View File

@@ -2,7 +2,8 @@ package com.willfp.ecoenchants.enchant.impl.hardcoded
import com.willfp.eco.core.EcoPlugin
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.impl.HardcodedEcoEnchant
import com.willfp.ecoenchants.target.EnchantLookup.hasEnchantActive
import org.bukkit.Bukkit
import org.bukkit.Material
@@ -17,13 +18,18 @@ import org.bukkit.inventory.ItemStack
class EnchantmentReplenish(
plugin: EcoEnchantsPlugin
) : EcoEnchant(
) : HardcodedEcoEnchant(
"replenish",
plugin,
force = false
plugin
) {
override fun onInit() {
this.registerListener(ReplenishHandler(this, plugin))
private var handler = ReplenishHandler(this, plugin)
override fun onRegister() {
plugin.eventManager.registerListener(handler)
}
override fun onRemove() {
plugin.eventManager.unregisterListener(handler)
}
private class ReplenishHandler(

View File

@@ -9,7 +9,8 @@ import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.items.Items
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchant.impl.HardcodedEcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.target.EnchantLookup.getActiveEnchantLevelInSlot
import com.willfp.ecoenchants.target.EnchantLookup.hasEnchantActive
import org.bukkit.entity.Player
@@ -24,13 +25,18 @@ import org.bukkit.persistence.PersistentDataType
class EnchantmentSoulbound(
plugin: EcoEnchantsPlugin
) : EcoEnchant(
) : HardcodedEcoEnchant(
"soulbound",
plugin,
force = false
plugin
) {
override fun onInit() {
this.registerListener(SoulboundHandler(plugin, this))
private val handler = SoulboundHandler(plugin, this)
override fun onRegister() {
plugin.eventManager.registerListener(handler)
}
override fun onRemove() {
plugin.eventManager.unregisterListener(handler)
}
private class SoulboundHandler(
@@ -92,7 +98,7 @@ class EnchantmentSoulbound(
if (enchant.config.getBool("single-use")) {
val meta = item.itemMeta
meta.removeEnchant(enchant)
meta.removeEnchant(enchant.enchantment)
item.itemMeta = meta
}
}
@@ -139,7 +145,7 @@ class EnchantmentSoulbound(
)
fun preventDroppingSoulboundItems(event: PlayerDeathEvent) {
event.drops.removeIf { it.fast().persistentDataContainer.has(soulboundKey, PersistentDataType.INTEGER)
&& it.itemMeta.hasEnchant(enchant)
&& it.itemMeta.hasEnchant(enchant.enchantment)
}
}
}

View File

@@ -3,7 +3,7 @@ package com.willfp.ecoenchants.enchant.registration.legacy
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.enchant.wrap
import io.papermc.paper.enchantments.EnchantmentRarity
import net.kyori.adventure.text.Component
import org.bukkit.enchantments.Enchantment

View File

@@ -3,4 +3,8 @@ package com.willfp.ecoenchants.enchant.registration.modern
import com.willfp.ecoenchants.enchant.registration.EnchantmentRegisterer
interface ModernEnchantmentRegistererProxy : EnchantmentRegisterer {
/**
* Replace the bukkit enchantment registry with the new EcoEnchants one.
*/
fun replaceRegistry()
}

View File

@@ -1,336 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.config
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.config.readConfig
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
import com.willfp.eco.core.placeholder.context.PlaceholderContext
import com.willfp.eco.core.placeholder.templates.SimpleInjectablePlaceholder
import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.containsIgnoreCase
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.target.EnchantmentTargets
import com.willfp.ecoenchants.type.EnchantmentTypes
import com.willfp.libreforge.SilentViolationContext
import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.ConditionList
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.effects.emptyEffectList
import com.willfp.libreforge.slot.SlotType
import net.kyori.adventure.text.Component
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
import org.bukkit.enchantments.EnchantmentTarget
import org.bukkit.entity.EntityCategory
import org.bukkit.event.Listener
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.bukkit.permissions.Permission
import org.bukkit.permissions.PermissionDefault
import java.io.File
import java.util.Objects
@Suppress("DEPRECATION")
abstract class EcoEnchant(
override val id: String,
configProvider: (EcoEnchant) -> Config,
protected val plugin: EcoEnchantsPlugin
) : Enchantment(NamespacedKey.minecraft(id)), EcoEnchantLike, KRegistrable {
final override val config by lazy { configProvider(this) }
override val enchant by lazy { this }
private val levels = Caffeine.newBuilder()
.build<Int, EcoEnchantLevel>()
override val displayName = config.getFormattedString("display-name")
override val unformattedDisplayName = config.getString("display-name")
val conditions: ConditionList
val targets = config.getStrings("targets")
.mapNotNull { EnchantmentTargets[it] }
val slots: Set<SlotType>
get() = targets.map { it.slot }.toSet()
override val type = EnchantmentTypes[config.getString("type")] ?: EnchantmentTypes.values().first()
override val enchantmentRarity =
EnchantmentRarities[config.getString("rarity")] ?: EnchantmentRarities.values().first()
private val conflictNames = config.getStrings("conflicts")
private val _listeners = mutableListOf<Listener>()
val listeners: List<Listener>
get() = this._listeners
val conflictsWithEverything: Boolean
get() = conflictNames.containsIgnoreCase("all")
|| conflictNames.containsIgnoreCase("everything")
val conflicts: Collection<Enchantment>
get() = if (conflictsWithEverything) values().toList()
else conflictNames.mapNotNull { getByKey(NamespacedKey.minecraft(it)) }
constructor(
config: Config,
plugin: EcoEnchantsPlugin
) : this(config.getString("id"), { config }, plugin)
constructor(
id: String,
config: Config,
plugin: EcoEnchantsPlugin
) : this(id, { config }, plugin)
@JvmOverloads
constructor(
id: String,
plugin: EcoEnchantsPlugin,
force: Boolean = true
) : this(
id,
{
if (force) {
EnchantmentConfig(id, it::class.java, plugin)
} else {
val file = File(plugin.dataFolder, "enchants")
.walk()
.firstOrNull { file -> file.nameWithoutExtension == id }
file?.readConfig(ConfigType.YAML) ?: config {
"dont-register" to true
}
}
},
plugin
)
init {
checkDependencies()
config.injectPlaceholders(
object : SimpleInjectablePlaceholder("level") {
override fun getValue(args: String, context: PlaceholderContext): String? {
return context.itemStack?.fast()?.getEnchantmentLevel(this@EcoEnchant)?.toString()
}
}
)
PlayerlessPlaceholder(plugin, "${id}_name") {
this.getFormattedName(0, false)
}.register()
conditions = Conditions.compile(
config.getSubsections("conditions"),
if (plugin.isLoaded) ViolationContext(plugin, "Enchantment $id")
else SilentViolationContext
)
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.$id") == null) {
val permission = Permission(
"ecoenchants.fromtable.$id",
"Allows getting $id from an Enchanting Table",
PermissionDefault.TRUE
)
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.*") == null) {
Bukkit.getPluginManager().addPermission(
Permission(
"ecoenchants.fromtable.*",
"Allows getting all enchantments from an Enchanting Table",
PermissionDefault.TRUE
)
)
}
permission.addParent(
Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.*")!!,
true
)
Bukkit.getPluginManager().addPermission(permission)
}
// Non-forced enchantments with deleted configs will have this as their entire config (see above),
// and that way the enchantment isn't registered.
if (!config.getBool("dont-register")) {
register()
if (plugin.isEnabled) {
doOnInit()
}
}
}
private fun checkDependencies() {
val missingPlugins = mutableSetOf<String>()
for (dependency in config.getStrings("dependencies")) {
if (!Bukkit.getPluginManager().plugins.map { it.name }.containsIgnoreCase(dependency)) {
missingPlugins += dependency
}
}
if (missingPlugins.isNotEmpty()) {
config.set("dont-register", true) // Just in case.
throw MissingDependencyException(missingPlugins)
}
}
private fun doOnInit() {
onInit()
}
protected open fun onInit() {
// Override when needed
}
private fun register() {
EcoEnchants.addNewEnchant(this)
}
fun getLevel(level: Int): EcoEnchantLevel = levels.get(level) {
createLevel(it)
}
open fun createLevel(level: Int) =
EcoEnchantLevel(this, level, emptyEffectList(), conditions, plugin)
fun registerListener(listener: Listener) {
this.plugin.eventManager.registerListener(listener)
this._listeners += listener
}
@Deprecated(
message = "getName is a legacy Spigot API",
replaceWith = ReplaceWith("this.displayName(level)")
)
override fun getName(): String = this.id.uppercase()
override fun getMaxLevel(): Int = this.config.getInt("max-level")
override fun getStartLevel(): Int = 1
@Deprecated(
message = "getItemTargets is an incompatible Spigot API",
replaceWith = ReplaceWith("this.targets")
)
override fun getItemTarget(): EnchantmentTarget = EnchantmentTarget.ALL
val isEnchantable: Boolean = this.config.getBool("enchantable")
@Deprecated(
message = "Treasure enchantments do not exist in EcoEnchants",
replaceWith = ReplaceWith("this.isEnchantable")
)
override fun isTreasure(): Boolean = !isEnchantable
override fun isCursed(): Boolean {
return false
}
fun conflictsWithDirectly(other: Enchantment): Boolean {
return conflictNames.containsIgnoreCase(other.key.key) || conflictsWithEverything
}
override fun conflictsWith(other: Enchantment): Boolean {
if (conflictsWithDirectly(other)) {
return true
}
if (other !is EcoEnchant) {
return false
}
return other.conflictsWithDirectly(this)
}
override fun canEnchantItem(item: ItemStack): Boolean {
if (
item.fast().getEnchants(true).keys
.map { it.wrap() }
.count { it.type == this.type } >= this.type.limit
) {
return false
}
if (item.fast().getEnchants(true).any { (enchant, _) -> enchant.conflictsWithDeep(this) }) {
return false
}
if (item.fast().getEnchants(true).size >= plugin.configYml.getInt("anvil.enchant-limit").infiniteIfNegative()) {
return false
}
if (item.type == Material.ENCHANTED_BOOK) {
return true
}
return targets.any { it.matches(item) }
}
override fun displayName(level: Int): Component {
return StringUtils.toComponent(this.wrap().getFormattedName(level))
}
override fun isTradeable(): Boolean = this.config.getBool("tradeable")
override fun isDiscoverable(): Boolean = this.config.getBool("discoverable")
@Deprecated(
message = "EcoEnchants do not have damage increase, this method is for sharpness/boa/smite",
replaceWith = ReplaceWith("0.0f")
)
override fun getDamageIncrease(level: Int, entityCategory: EntityCategory): Float = 0.0f
@Deprecated(
message = "getActiveSlots is an incompatible Paper API",
replaceWith = ReplaceWith("this.slots")
)
override fun getActiveSlots() = emptySet<EquipmentSlot>()
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
message = "Enchant display overrides this system"
)
override fun translationKey(): String = "ecoenchants:enchantment.$id"
@Deprecated(
message = "EcoEnchants uses a custom system for enchantment rarity",
replaceWith = ReplaceWith("this.enchantRarity")
)
override fun getRarity(): io.papermc.paper.enchantments.EnchantmentRarity {
return io.papermc.paper.enchantments.EnchantmentRarity.RARE
}
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
if (other !is EcoEnchant) {
return false
}
return other.id == this.id
}
override fun hashCode(): Int {
return Objects.hash(id)
}
override fun toString(): String {
return "EcoEnchant{$key}"
}
}

View File

@@ -1,42 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.EcoPlugin
import com.willfp.libreforge.Holder
import com.willfp.libreforge.conditions.ConditionList
import com.willfp.libreforge.effects.EffectList
import java.util.Objects
class EcoEnchantLevel(
val enchant: EcoEnchant,
val level: Int,
override val effects: EffectList,
override val conditions: ConditionList,
plugin: EcoPlugin
) : Holder {
override val id = plugin.createNamespacedKey("${enchant.id}_$level")
override fun equals(other: Any?): Boolean {
if (other !is EcoEnchantLevel) {
return false
}
return this.id == other.id
}
override fun toString(): String {
return id.toString()
}
override fun hashCode(): Int {
return Objects.hash(this.id)
}
}
data class FoundEcoEnchantLevel(
val level: EcoEnchantLevel,
val activeLevel: Int
): Holder {
override val effects = level.effects
override val conditions = level.conditions
override val id = level.id
}

View File

@@ -1,131 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.placeholder.InjectablePlaceholder
import com.willfp.eco.core.placeholder.PlaceholderInjectable
import com.willfp.eco.core.placeholder.StaticPlaceholder
import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
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
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.util.*
interface EcoEnchantLike {
val config: Config
val type: EnchantmentType
val displayName: String
val unformattedDisplayName: String
val enchant: Enchantment
val enchantmentRarity: EnchantmentRarity
// Includes all extra logic not found in vanilla canEnchantItem
fun canEnchantItem(item: ItemStack): Boolean
// Java backwards compatibility
fun getUnformattedDescription(level: Int): String {
return getUnformattedDescription(level, null)
}
}
private val ecoEnchantLikes = Caffeine.newBuilder()
.build<NamespacedKey, EcoEnchantLike>()
fun Enchantment.wrap(): EcoEnchantLike {
if (this is EcoEnchant) {
return this
}
return ecoEnchantLikes.get(this.key) {
VanillaEcoEnchantLike(this, EcoEnchantsPlugin.instance) // Jank
}
}
fun Enchantment.conflictsWithDeep(other: Enchantment): Boolean {
return this.conflictsWith(other) || other.conflictsWith(this)
}
class VanillaEcoEnchantLike(
override val enchant: Enchantment,
private val plugin: EcoEnchantsPlugin
) : EcoEnchantLike {
override val config = plugin.vanillaEnchantsYml.getSubsection(enchant.key.key)
override val type: EnchantmentType =
EnchantmentTypes[plugin.vanillaEnchantsYml.getString("${enchant.key.key}.type")]
?: EnchantmentTypes.values().first()
override val enchantmentRarity: EnchantmentRarity =
EnchantmentRarities[plugin.vanillaEnchantsYml.getString("${enchant.key.key}.rarity")]
?: EnchantmentRarities.values().first()
override val displayName = plugin.vanillaEnchantsYml.getFormattedString("${enchant.key.key}.name")
override val unformattedDisplayName = plugin.vanillaEnchantsYml.getString("${enchant.key.key}.name")
override fun canEnchantItem(item: ItemStack): Boolean {
// Yes this code is copied from EcoEnchant, but I can't be bothered to abstract it properly
if (
item.fast().getEnchants(true).keys
.map { it.wrap() }
.count { it.type == this.type } >= this.type.limit
) {
return false
}
if (item.fast().getEnchants(true).any { (enchant, _) -> enchant.conflictsWithDeep(this.enchant) }) {
return false
}
if (item.fast().getEnchants(true).size >= plugin.configYml.getInt("anvil.enchant-limit").infiniteIfNegative()) {
return false
}
if (item.type == Material.ENCHANTED_BOOK) {
return true
}
return enchant.canEnchantItem(item)
}
override fun equals(other: Any?): Boolean {
if (other !is VanillaEcoEnchantLike) {
return false
}
return this.enchant == other.enchant
}
override fun hashCode(): Int {
return Objects.hash(this.enchant)
}
}
private val enchantmentOptions = arrayOf(
"max-level",
"conflicts"
)
fun registerVanillaEnchants(plugin: EcoEnchantsPlugin) {
for (vanilla in plugin.vanillaEnchantsYml.getKeys(false)) {
if (enchantmentOptions.any { plugin.vanillaEnchantsYml.has("$vanilla.$it") }) {
plugin.getProxy(EcoCraftEnchantmentManagerProxy::class.java).registerNewCraftEnchantment(
Enchantment.getByKey(NamespacedKey.minecraft(vanilla))!!,
VanillaEnchantmentData(
plugin.vanillaEnchantsYml.getIntOrNull("$vanilla.max-level"),
plugin.vanillaEnchantsYml.getStringsOrNull("$vanilla.conflicts")
?.map { NamespacedKey.minecraft(it) }
)
)
}
}
}

View File

@@ -1,127 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentPermanenceCurse
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentRepairing
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentReplenish
import com.willfp.ecoenchants.enchant.impl.hardcoded.EnchantmentSoulbound
import com.willfp.ecoenchants.integrations.EnchantRegistrations
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.target.EnchantmentTargets
import com.willfp.ecoenchants.type.EnchantmentTypes
import com.willfp.libreforge.loader.LibreforgePlugin
import com.willfp.libreforge.loader.configs.RegistrableCategory
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
@Suppress("UNUSED")
object EcoEnchants : RegistrableCategory<EcoEnchant>("enchant", "enchants") {
override fun clear(plugin: LibreforgePlugin) {
for (enchant in values()) {
removeEnchant(enchant)
for (listener in enchant.listeners) {
plugin.eventManager.unregisterListener(listener)
}
}
}
override fun beforeReload(plugin: LibreforgePlugin) {
plugin as EcoEnchantsPlugin
EnchantmentRarities.update(plugin)
EnchantmentTargets.update(plugin)
EnchantmentTypes.update(plugin)
}
override fun afterReload(plugin: LibreforgePlugin) {
plugin as EcoEnchantsPlugin
sendPrompts(plugin)
registerHardcodedEnchantments(plugin)
}
override fun acceptConfig(plugin: LibreforgePlugin, id: String, config: Config) {
plugin as EcoEnchantsPlugin
if (config.has("effects")) {
try {
LibReforgeEcoEnchant(
id,
config,
plugin
)
} catch (e: MissingDependencyException) {
addPluginPrompt(plugin, e.plugins)
}
}
}
/**
* Remove [Enchantment] from EcoEnchants.
*
* @param enchant The [Enchantment] to remove.
*/
@JvmStatic
@Suppress("UNCHECKED_CAST", "DEPRECATION")
fun removeEnchant(enchant: Enchantment) {
if (enchant is EcoEnchant) {
registry.remove(enchant.id)
EnchantRegistrations.removeEnchant(enchant)
}
Enchantment::class.java.getDeclaredField("byKey")
.apply {
isAccessible = true
(get(null) as MutableMap<NamespacedKey, Enchantment>).apply { remove(enchant.key) }
}
Enchantment::class.java.getDeclaredField("byName")
.apply {
isAccessible = true
(get(null) as MutableMap<String, Enchantment>).apply { remove(enchant.name) }
}
}
/**
* Add new [EcoEnchant] to EcoEnchants.
*
* Only for internal use, enchants are automatically added in the
* constructor.
*
* @param enchant The [EcoEnchant] to add.
*/
internal fun addNewEnchant(enchant: EcoEnchant) {
register(enchant)
}
/**
* Register a new [Enchantment] with the server.
*
* @param enchantment The [Enchantment] to add.
*/
@JvmStatic
fun register(enchantment: Enchantment) {
Enchantment::class.java.getDeclaredField("acceptingNew")
.apply {
isAccessible = true
set(null, true)
}
removeEnchant(enchantment)
Enchantment.registerEnchantment(enchantment)
EnchantRegistrations.registerEnchantments()
}
/** Register the hardcoded enchantments. */
private fun registerHardcodedEnchantments(
plugin: EcoEnchantsPlugin
) {
EnchantmentPermanenceCurse(plugin)
EnchantmentRepairing(plugin)
EnchantmentReplenish(plugin)
EnchantmentSoulbound(plugin)
}
}

View File

@@ -1,18 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.ExtendableConfig
class EnchantmentConfig(
name: String,
source: Class<*>,
plugin: EcoPlugin
) : ExtendableConfig(
name,
true,
plugin,
source,
"enchants/",
ConfigType.YAML
)

View File

@@ -1,27 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.libreforge.SilentViolationContext
import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.effects.Effects
import com.willfp.libreforge.effects.emptyEffectList
class LibReforgeEcoEnchant(
id: String,
config: Config,
plugin: EcoEnchantsPlugin
) : EcoEnchant(
id,
config,
plugin
) {
private val effects = Effects.compile(
config.getSubsections("effects"),
if (plugin.isLoaded) ViolationContext(plugin, "Enchantment $id")
else SilentViolationContext
)
override fun createLevel(level: Int): EcoEnchantLevel =
EcoEnchantLevel(this, level, effects, conditions, plugin)
}

View File

@@ -1,116 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.fast.fast
import com.willfp.eco.util.NumberUtils
import org.bukkit.ChatColor
import org.bukkit.enchantments.Enchantment
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.InventoryOpenEvent
import org.bukkit.event.player.PlayerItemHeldEvent
import org.bukkit.inventory.BlockInventoryHolder
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.EnchantmentStorageMeta
class LoreConversion(
private val plugin: EcoPlugin
) : Listener {
@EventHandler
fun loreConverter(event: PlayerItemHeldEvent) {
if (!plugin.configYml.getBool("lore-conversion.enabled")) {
return
}
convertLore(event.player.inventory.getItem(event.newSlot))
}
@EventHandler
fun aggressiveLoreConverter(event: InventoryOpenEvent) {
if (!plugin.configYml.getBool("lore-conversion.enabled")) {
return
}
if (!plugin.configYml.getBool("lore-conversion.aggressive")) {
return
}
val inventory = event.inventory
if (inventory.holder !is BlockInventoryHolder) {
return
}
for (itemStack in inventory.contents) {
convertLore(itemStack)
}
}
private fun convertLore(itemStack: ItemStack?) {
if (itemStack == null) {
return
}
val meta = itemStack.itemMeta ?: return
val toAdd = mutableMapOf<Enchantment, Int>()
val lore = itemStack.fast().lore.toMutableList()
for (line in lore.toList()) {
val uncolored = ChatColor.stripColor(line) ?: continue
var enchant: EcoEnchant?
var level: Int
val split = uncolored.split(" ").toMutableList()
if (split.isEmpty()) {
continue
}
if (split.size == 1) {
enchant = EcoEnchants.getByName(split[0])
level = 1
} else {
val attemptFullLine = EcoEnchants.getByName(line)
if (attemptFullLine != null) {
enchant = attemptFullLine
level = 1
} else {
var levelString = split.last()
split.remove(levelString)
levelString = levelString.trim { it <= ' ' }
level = try {
NumberUtils.fromNumeral(levelString)
} catch (e: IllegalArgumentException) {
continue
}
val enchantName = split.joinToString(" ")
enchant = EcoEnchants.getByName(enchantName)
}
}
if (enchant == null) {
continue
}
toAdd[enchant] = level
}
if (meta is EnchantmentStorageMeta) {
lore.clear()
for ((enchant, level) in toAdd) {
meta.addStoredEnchant(enchant, level, true)
}
} else {
lore.clear()
for ((enchant, level) in toAdd) {
meta.addEnchant(enchant, level, true)
}
}
itemStack.itemMeta = meta
itemStack.fast().lore = lore
}
}

View File

@@ -1,34 +0,0 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.EcoPlugin
import com.willfp.ecoenchants.EcoEnchantsPlugin
class MissingDependencyException(
val plugins: Set<String>
) : Exception() {
override val message = "Missing the following plugins: ${plugins.joinToString(", ")}"
}
// Plugin names mapped to enchants that aren't installed.
private val prompts = mutableMapOf<String, Int>()
fun addPluginPrompt(plugin: EcoEnchantsPlugin, plugins: Set<String>) {
if (!plugin.isLoaded) {
return
}
for (pluginName in plugins) {
prompts[pluginName] = prompts.getOrDefault(pluginName, 0) + 1
}
}
fun sendPrompts(plugin: EcoPlugin) {
for ((pl, amount) in prompts) {
plugin.logger.apply {
warning("$amount enchantments were not loaded because they need $pl to be installed!")
warning("Either download $pl or delete the folder at /plugins/EcoEnchants/enchants/${pl.lowercase()} to remove this message")
}
}
prompts.clear()
}

View File

@@ -2,7 +2,7 @@ package com.willfp.ecoenchants.libreforge
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.fast.fast
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.enchant.wrap
import com.willfp.ecoenchants.type.EnchantmentType
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger

View File

@@ -4,9 +4,8 @@ import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.proxy.ProxyConstants
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.wrap
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.Tag
@@ -35,6 +34,10 @@ fun Int.infiniteIfNegative() = if (this < 1) Int.MAX_VALUE else this
private val FAIL = AnvilResult(null, null)
interface OpenInventoryProxy {
fun getOpenInventory(player: Player): Any
}
@Suppress("DEPRECATION")
class AnvilSupport(
private val plugin: EcoPlugin
@@ -155,7 +158,7 @@ class AnvilSupport(
val permanenceCurse = EcoEnchants.getByID("permanence_curse")
if (permanenceCurse != null) {
if (left.fast().getEnchants(true).containsKey(permanenceCurse)) {
if (left.fast().getEnchants(true).containsKey(permanenceCurse.enchantment)) {
return FAIL
}
}

View File

@@ -6,9 +6,9 @@ import com.willfp.eco.core.recipe.parts.EmptyTestableItem
import com.willfp.eco.util.NumberUtils
import com.willfp.eco.util.randDouble
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.conflictsWithDeep
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.conflictsWithDeep
import org.bukkit.Bukkit
import org.bukkit.GameMode
import org.bukkit.Material
@@ -93,16 +93,16 @@ class EnchantingTableSupport(
continue
}
val baseChance = enchantment.enchantmentRarity.tableChance * multiplier
val baseChance = enchantment.rarity.tableChance * multiplier
val chanceEvent = EnchantingTableChanceGenerateEvent(player, item, enchantment, baseChance)
val chanceEvent = EnchantingTableChanceGenerateEvent(player, item, enchantment.enchantment, baseChance)
Bukkit.getPluginManager().callEvent(chanceEvent)
if (NumberUtils.randFloat(0.0, 1.0) > chanceEvent.chance) {
continue
}
if (enchantment.enchantmentRarity.minimumLevel > cost) {
if (enchantment.rarity.minimumLevel > cost) {
continue
}
@@ -114,7 +114,7 @@ class EnchantingTableSupport(
break
}
if (toAdd.any { (it, _) -> enchantment.conflictsWithDeep(it) }) {
if (toAdd.any { (it, _) -> enchantment.enchantment.conflictsWithDeep(it) }) {
continue
}
@@ -140,7 +140,7 @@ class EnchantingTableSupport(
multiplier /= this.plugin.configYml.getDouble("enchanting-table.reduction")
toAdd[enchantment] = level
toAdd[enchantment.enchantment] = level
}
toAdd.forEach(event.enchantsToAdd::putIfAbsent)

View File

@@ -2,32 +2,15 @@ package com.willfp.ecoenchants.mechanics
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.fast.fast
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.wrap
import org.bukkit.ChatColor
import org.bukkit.Material
import com.willfp.ecoenchants.enchant.wrap
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.EntityType
import org.bukkit.entity.ExperienceOrb
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryType
import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.inventory.GrindstoneInventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.Damageable
import org.bukkit.inventory.meta.EnchantmentStorageMeta
import java.util.*
import javax.swing.text.html.HTML.Tag.P
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt
@Suppress("DEPRECATION")
class GrindstoneSupport(

View File

@@ -3,9 +3,9 @@ package com.willfp.ecoenchants.mechanics
import com.willfp.eco.core.fast.fast
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.conflictsWithDeep
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.conflictsWithDeep
import com.willfp.ecoenchants.target.EnchantmentTargets.isEnchantable
import org.bukkit.Material
import org.bukkit.event.EventHandler
@@ -53,11 +53,11 @@ class LootSupport(
continue
}
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.enchantmentRarity.lootChance * multiplier) {
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.rarity.lootChance * multiplier) {
continue
}
if (enchants.any { (it, _) -> enchantment.conflictsWithDeep(it) }) {
if (enchants.any { (it, _) -> enchantment.enchantment.conflictsWithDeep(it) }) {
continue
}
@@ -80,7 +80,7 @@ class LootSupport(
multiplier /= this.plugin.configYml.getDouble("villager.reduction")
enchants[enchantment] = level
enchants[enchantment.enchantment] = level
}
val meta = item.itemMeta

View File

@@ -3,9 +3,9 @@ package com.willfp.ecoenchants.mechanics
import com.willfp.eco.core.fast.fast
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.conflictsWithDeep
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.conflictsWithDeep
import com.willfp.ecoenchants.target.EnchantmentTargets.isEnchantable
import org.bukkit.Material
import org.bukkit.event.EventHandler
@@ -54,11 +54,11 @@ class VillagerSupport(
continue
}
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.enchantmentRarity.villagerChance * multiplier) {
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.rarity.villagerChance * multiplier) {
continue
}
if (enchants.any { (it, _) -> enchantment.conflictsWithDeep(it) }) {
if (enchants.any { (it, _) -> enchantment.enchantment.conflictsWithDeep(it) }) {
continue
}
@@ -85,10 +85,10 @@ class VillagerSupport(
if (result.type == Material.ENCHANTED_BOOK) {
// Only allow one enchantment
enchants.clear()
enchants[enchantment] = level
enchants[enchantment.enchantment] = level
break
} else {
enchants[enchantment] = level
enchants[enchantment.enchantment] = level
}
}

View File

@@ -4,9 +4,10 @@ import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.items.HashedItem
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchantLevel
import com.willfp.ecoenchants.enchants.FoundEcoEnchantLevel
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchantLevel
import com.willfp.ecoenchants.enchant.FoundEcoEnchantLevel
import com.willfp.ecoenchants.plugin
import com.willfp.libreforge.ItemProvidedHolder
import com.willfp.libreforge.slot.SlotType
import com.willfp.libreforge.slot.SlotTypes
@@ -302,7 +303,7 @@ object EnchantLookup {
// This is such a fucking disgusting way of implementing %active_level%,
// and it's probably quite slow too.
return if (EcoEnchantsPlugin.instance.configYml.getBool("extra-placeholders.active-level")) {
return if (plugin.configYml.getBool("extra-placeholders.active-level")) {
found.map {
val level = it.holder as EcoEnchantLevel

View File

@@ -6,12 +6,11 @@ import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
import com.willfp.eco.core.registry.Registrable
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.plugin
import com.willfp.libreforge.slot.SlotType
import com.willfp.libreforge.slot.SlotTypes
import com.willfp.libreforge.slot.impl.SlotTypeAny
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.lang.IllegalArgumentException
import java.util.Objects
interface EnchantmentTarget : Registrable {
@@ -62,7 +61,7 @@ class ConfiguredEnchantmentTarget(
internal object AllEnchantmentTarget : EnchantmentTarget {
override val id = "all"
override val displayName = EcoEnchantsPlugin.instance.langYml.getFormattedString("all")
override val displayName = plugin.langYml.getFormattedString("all")
override val slot = SlotTypeAny
override var items = emptyList<TestableItem>()
private set

View File

@@ -1,22 +1,20 @@
package com.willfp.ecoenchants.target
import com.github.benmanes.caffeine.cache.Caffeine
import com.google.common.collect.ImmutableSet
import com.willfp.eco.core.items.HashedItem
import com.willfp.eco.core.registry.Registry
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.plugin
import org.bukkit.Material
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemStack
import java.util.concurrent.TimeUnit
object EnchantmentTargets: Registry<EnchantmentTarget>() {
object EnchantmentTargets : Registry<EnchantmentTarget>() {
init {
register(AllEnchantmentTarget)
update(EcoEnchantsPlugin.instance)
update(plugin)
}
private fun getForItem(item: ItemStack): List<EnchantmentTarget> {

View File

@@ -1,6 +0,0 @@
group = "com.willfp"
version = rootProject.version
dependencies {
compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT")
}

View File

@@ -1,9 +0,0 @@
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, data: VanillaEnchantmentData)
}

View File

@@ -1,7 +0,0 @@
package com.willfp.ecoenchants.proxy.proxies
import org.bukkit.entity.Player
interface OpenInventoryProxy {
fun getOpenInventory(player: Player): Any
}

View File

@@ -1,8 +0,0 @@
package com.willfp.ecoenchants.vanilla
import org.bukkit.NamespacedKey
data class VanillaEnchantmentData(
val maxLevel: Int?,
val conflicts: Collection<NamespacedKey>?
)

View File

@@ -12,7 +12,6 @@ rootProject.name = "EcoEnchants"
// Core
include(":eco-core")
include(":eco-core:core-plugin")
include(":eco-core:core-proxy")
include(":eco-core:core-nms")
include(":eco-core:core-nms:v1_17_R1")
include(":eco-core:core-nms:v1_18_R1")