package cat.nyaa.nyaacore.utils;

import net.minecraft.world.entity.projectile.EntityThrownTrident;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.entity.Trident;
import org.bukkit.inventory.ItemStack;

import java.lang.reflect.Field;

public final class TridentUtils {

    private static final Class<?> entityThrownTrident = net.minecraft.world.entity.projectile.EntityThrownTrident.class;

    private static Field entityThrownTridentFieldDealtDamage;

    static {
        try {
            entityThrownTridentFieldDealtDamage = entityThrownTrident.getDeclaredField("ar");//1.17&1.17.1 = ar,1.16.3 = ai(not support)
            entityThrownTridentFieldDealtDamage.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    public static ItemStack getTridentItemStack(Trident entity) {
        EntityThrownTrident thrownTrident = (EntityThrownTrident) ((CraftEntity) entity).getHandle();
        // net.minecraft.server.v1_16_R3.ItemStack nmsItemStack = thrownTrident.trident;
        net.minecraft.world.item.ItemStack nmsItemStack = thrownTrident.aq;
        return CraftItemStack.asBukkitCopy(nmsItemStack);
    }

    public static void setTridentItemStack(Trident entity, ItemStack itemStack) {
        EntityThrownTrident thrownTrident = (EntityThrownTrident) ((CraftEntity) entity).getHandle();
        // thrownTrident.trident = CraftItemStack.asNMSCopy(itemStack);
        thrownTrident.aq = CraftItemStack.asNMSCopy(itemStack);
    }

    public static boolean getTridentDealtDamage(Trident entity) {
        try {
            EntityThrownTrident thrownTrident = (EntityThrownTrident) ((CraftEntity) entity).getHandle();
            return (boolean) entityThrownTridentFieldDealtDamage.get(thrownTrident);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    public static void setTridentDealtDamage(Trident entity, boolean dealtDamage) {
        try {
            EntityThrownTrident thrownTrident = (EntityThrownTrident) ((CraftEntity) entity).getHandle();
            entityThrownTridentFieldDealtDamage.set(thrownTrident, dealtDamage);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -123,25 +123,25 @@
 tbukkit.v1_1
-7
+8
 _R1.entity.C
@@ -156,73 +156,8 @@
 ty;%0A
-import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;%0A
 impo
@@ -297,191 +297,51 @@
 s %7B%0A
-%0A    private static final Class%3C?%3E entityThrownTrident = net.minecraft.world.entity.projectile.EntityThrownTrident.class;%0A%0A    private static Field entityThrownTridentFieldDealtDamage
+    private static Field FIELD_DEALT_DAMAGE
 ;%0A%0A 
@@ -370,33 +370,43 @@
 y %7B%0A            
-e
+var cls = E
 ntityThrownTride
@@ -411,46 +411,52 @@
 dent
-FieldDealtDamage = entityThrownTrident
+.class;%0A            FIELD_DEALT_DAMAGE = cls
 .get
@@ -475,103 +475,43 @@
 d(%22a
-r%22);//1.17&1.17.1 = ar,1.16.3 = ai(not support)%0A            entityThrownTridentFieldDealtDamage
+s%22);%0A            FIELD_DEALT_DAMAGE
 .set
@@ -613,32 +613,48 @@
        %7D%0A    %7D%0A%0A
+    @Deprecated%0A
     public stati
@@ -715,106 +715,37 @@
     
-EntityThrownTrident thrownTrident = (EntityThrownTrident) ((CraftEntity) entity).getHandle
+return entity.getItem
 ();%0A    
     
@@ -744,541 +744,131 @@
     
-    // net.minecraft.server.v1_16_R3.ItemStack nmsItemStack = thrownTrident.trident;%0A        net.minecraft.world.item.ItemStack nmsItemStack = thrownTrident.aq;%0A        return CraftItemStack.asBukkitCopy(nmsItemStack);%0A    %7D%0A%0A    public static void setTridentItemStack(Trident entity, ItemStack itemStack) %7B%0A        EntityThrownTrident thrownTrident = (EntityThrownTrident) ((CraftEntity) entity).getHandle();%0A        // thrownTrident.trident = CraftItemStack.asNMSCopy(itemStack);%0A        thrownTrident.aq = CraftItemStack.asNMSCopy
+%7D%0A%0A    @Deprecated%0A    public static void setTridentItemStack(Trident entity, ItemStack itemStack) %7B%0A        entity.setItem
 (ite
@@ -1102,43 +1102,26 @@
 an) 
-entityThrownTridentFieldDealtDamage
+FIELD_DEALT_DAMAGE
 .get
@@ -1462,43 +1462,26 @@
     
-entityThrownTridentFieldDealtDamage
+FIELD_DEALT_DAMAGE
 .set

fix TridentUtil