From 05ce2321396ce0e6f43fb5c3e000993b00131f4a Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 9 Jun 2023 20:14:17 +0100 Subject: [PATCH] Added 1.20 support --- eco-core/core-nms/v1_20_R1/build.gradle.kts | 6 +++++ .../proxy/v1_20_R1/EcoCraftEnchantment.kt | 26 +++++++++++++++++++ .../v1_20_R1/EcoCraftEnchantmentManager.kt | 26 +++++++++++++++++++ .../proxy/v1_20_R1/OpenInventory.kt | 11 ++++++++ settings.gradle.kts | 1 + 5 files changed, 70 insertions(+) create mode 100644 eco-core/core-nms/v1_20_R1/build.gradle.kts create mode 100644 eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt create mode 100644 eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt create mode 100644 eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/OpenInventory.kt diff --git a/eco-core/core-nms/v1_20_R1/build.gradle.kts b/eco-core/core-nms/v1_20_R1/build.gradle.kts new file mode 100644 index 00000000..c00e0806 --- /dev/null +++ b/eco-core/core-nms/v1_20_R1/build.gradle.kts @@ -0,0 +1,6 @@ +group = "com.willfp" +version = rootProject.version + +dependencies { + compileOnly("org.spigotmc:spigot:1.20-R0.1-SNAPSHOT") +} diff --git a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt new file mode 100644 index 00000000..9becddb6 --- /dev/null +++ b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantment.kt @@ -0,0 +1,26 @@ +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 net.minecraft.world.item.enchantment.Enchantment +import org.bukkit.craftbukkit.v1_20_R1.enchantments.CraftEnchantment + +class EcoCraftEnchantment( + target: Enchantment, + private val data: VanillaEnchantmentData +) : CraftEnchantment(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) + } +} diff --git a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt new file mode 100644 index 00000000..6c14b3dc --- /dev/null +++ b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/EcoCraftEnchantmentManager.kt @@ -0,0 +1,26 @@ +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 net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.core.registries.Registries +import org.bukkit.NamespacedKey +import org.bukkit.enchantments.Enchantment + +class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy { + override fun registerNewCraftEnchantment( + enchantment: Enchantment, + data: VanillaEnchantmentData + ) { + for (enchant in BuiltInRegistries.g) { + val key = org.bukkit.craftbukkit.v1_20_R1.util.CraftNamespacedKey.fromMinecraft( + BuiltInRegistries.g.b(enchant) + ) + if (key.key != enchantment.key.key) { + continue + } + EcoCraftEnchantment(enchant, data).register() + } + } +} diff --git a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/OpenInventory.kt b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/OpenInventory.kt new file mode 100644 index 00000000..a2b3af6d --- /dev/null +++ b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R1/OpenInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.ecoenchants.proxy.v1_20_R1 + +import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer +import org.bukkit.entity.Player + +class OpenInventory : OpenInventoryProxy { + override fun getOpenInventory(player: Player): Any { + return (player as CraftPlayer).handle.bR + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 147af1fd..ec34c040 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,3 +19,4 @@ include(":eco-core:core-nms:v1_18_R2") include(":eco-core:core-nms:v1_19_R1") include(":eco-core:core-nms:v1_19_R2") include(":eco-core:core-nms:v1_19_R3") +include(":eco-core:core-nms:v1_20_R1")