From 351fe3c324ad01ac0909a446afa9350d7c44f9b6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 9 Jun 2022 19:38:03 +0100 Subject: [PATCH] Added 1.19 support --- eco-core/core-nms/v1_19_R1/build.gradle | 6 ++++ .../v1_19_R1/EcoCraftEnchantmentManager.java | 25 +++++++++++++ .../proxy/v1_19_R1/OpenInventory.java | 13 +++++++ .../enchants/EcoCraftEnchantment.java | 36 +++++++++++++++++++ settings.gradle | 1 + 5 files changed, 81 insertions(+) create mode 100644 eco-core/core-nms/v1_19_R1/build.gradle create mode 100644 eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.java create mode 100644 eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/OpenInventory.java create mode 100644 eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/enchants/EcoCraftEnchantment.java diff --git a/eco-core/core-nms/v1_19_R1/build.gradle b/eco-core/core-nms/v1_19_R1/build.gradle new file mode 100644 index 00000000..05e27d11 --- /dev/null +++ b/eco-core/core-nms/v1_19_R1/build.gradle @@ -0,0 +1,6 @@ +group 'com.willfp' +version rootProject.version + +dependencies { + compileOnly 'org.spigotmc:spigot:1.19-R0.1-SNAPSHOT' +} \ No newline at end of file diff --git a/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.java b/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.java new file mode 100644 index 00000000..c9dd2f49 --- /dev/null +++ b/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/EcoCraftEnchantmentManager.java @@ -0,0 +1,25 @@ +package com.willfp.ecoenchants.proxy.v1_19_R1; + +import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata; +import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments; +import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy; +import com.willfp.ecoenchants.proxy.v1_19_R1.enchants.EcoCraftEnchantment; +import net.minecraft.core.IRegistry; +import net.minecraft.world.item.enchantment.Enchantment; +import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.v1_19_R1.util.CraftNamespacedKey; + +import java.util.Map; + +public final class EcoCraftEnchantmentManager implements EcoCraftEnchantmentManagerProxy { + @Override + public void registerNewCraftEnchantments() { + Map metadataMap = VanillaEnchantments.getMetadataMap(); + + for (Enchantment enchantment : IRegistry.W) { + NamespacedKey key = CraftNamespacedKey.fromMinecraft(IRegistry.W.b(enchantment)); + VanillaEnchantmentMetadata metadata = metadataMap.get(org.bukkit.enchantments.Enchantment.getByKey(key)); + new EcoCraftEnchantment(enchantment, metadata).register(); + } + } +} diff --git a/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/OpenInventory.java b/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/OpenInventory.java new file mode 100644 index 00000000..7b5dedd6 --- /dev/null +++ b/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/OpenInventory.java @@ -0,0 +1,13 @@ +package com.willfp.ecoenchants.proxy.v1_19_R1; + +import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public final class OpenInventory implements OpenInventoryProxy { + @Override + public Object getOpenInventory(@NotNull final Player player) { + return ((CraftPlayer) player).getHandle().bU; + } +} diff --git a/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/enchants/EcoCraftEnchantment.java b/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/enchants/EcoCraftEnchantment.java new file mode 100644 index 00000000..555b20ea --- /dev/null +++ b/eco-core/core-nms/v1_19_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_19_R1/enchants/EcoCraftEnchantment.java @@ -0,0 +1,36 @@ +package com.willfp.ecoenchants.proxy.v1_19_R1.enchants; + +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import net.minecraft.world.item.enchantment.Enchantment; +import org.bukkit.craftbukkit.v1_19_R1.enchantments.CraftEnchantment; +import org.jetbrains.annotations.NotNull; + +public class EcoCraftEnchantment extends CraftEnchantment { + private final VanillaEnchantmentMetadata metadata; + + public EcoCraftEnchantment(@NotNull final Enchantment target, + @NotNull final VanillaEnchantmentMetadata metadata) { + super(target); + this.metadata = metadata; + } + + @Override + public int getMaxLevel() { + return metadata.maxLevel() == null ? this.getHandle().a() : metadata.maxLevel(); + } + + @Override + public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) { + if (other instanceof EcoEnchant) { + return other.conflictsWith(this); + } + + return metadata.conflicts() == null ? super.conflictsWith(other) : metadata.conflicts().contains(other.getKey()); + } + + public void register() { + EnchantmentUtils.register(this); + } +} diff --git a/settings.gradle b/settings.gradle index fddf08e8..23a9dd99 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,6 +6,7 @@ include ':eco-core:core-nms' include ':eco-core:core-nms:v1_17_R1' include ':eco-core:core-nms:v1_18_R1' include ':eco-core:core-nms:v1_18_R2' +include ':eco-core:core-nms:v1_19_R1' include ':eco-core:core-proxy' include ':eco-core:core-plugin' include ':eco-core:core-stub'