package cat.nyaa.autobloodmoon.api;


import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.Plugin;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;

public class InfernalMobsAPI {
    private static Method spawnMobMethod;
    private static Method isInfernalMobMethod;

    public static void load(Plugin InfernalMobs) {
        try {
            spawnMobMethod = Class.forName("com.jacob_vejvoda.infernal_mobs.InfernalMobsAPI").getMethod(
                    "spawnInfernalMob",
                    EntityType.class, Location.class, Collection.class
            );
            isInfernalMobMethod = Class.forName("com.jacob_vejvoda.infernal_mobs.InfernalMobsAPI").getMethod(
                    "asInfernalMob",
                    UUID.class
            );
        } catch (ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("deprecation")
    public static boolean spawnMob(String mobName, ArrayList<String> abilityList, Location loc) {
        try {
            EntityType type = EntityType.fromName(mobName);
            if (type == null) {
                return false;
            }
            Object mob = spawnMobMethod.invoke(null, type, loc, abilityList);
            return mob != null;
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean isInfernalMob(Entity mob) {
        try {
            if (isInfernalMobMethod.invoke(null, mob.getUniqueId()) != null) {
                return true;
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return false;
    }
}

@@ -167,40 +167,8 @@
 n;%0A%0A
-import java.lang.reflect.Field;%0A
 impo
@@ -301,24 +301,47 @@
 Collection;%0A
+import java.util.List;%0A
 import java.
@@ -471,16 +471,67 @@
 bMethod;
+%0A    private static Enum%3C?%3E%5B%5D enumAbilities = null;
 %0A%0A    pu
@@ -1068,33 +1068,755 @@
 ) %7B%0A            
-e
+// IM v5.1.25%0A            try %7B%0A                spawnMobMethod = Class.forName(%22com.jacob_vejvoda.infernal_mobs.api.InfernalMobsAPI%22).getMethod(%0A                        %22spawnInfernalMob%22,%0A                        EntityType.class, Location.class, Collection.class%0A                );%0A                isInfernalMobMethod = Class.forName(%22com.jacob_vejvoda.infernal_mobs.api.InfernalMobsAPI%22).getMethod(%0A                        %22asInfernalMob%22,%0A                        UUID.class%0A                );%0A                enumAbilities = (Enum%3C?%3E%5B%5D) Class.forName(%22com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities%22).getEnumConstants();%0A            %7D catch (NoSuchMethodException %7C ClassNotFoundException e1) %7B%0A                e1
 .printStackTrace
@@ -1811,32 +1811,46 @@
 ntStackTrace();%0A
+            %7D%0A
         %7D%0A    %7D%0A
@@ -1991,32 +1991,496 @@
 %7B%0A        try %7B%0A
+            List%3CEnum%3C?%3E%3E list = new ArrayList%3C%3E();%0A            if (enumAbilities != null) %7B%0A                for (String abilityName : abilityList) %7B%0A                    for (Enum%3C?%3E enumAbility : enumAbilities) %7B%0A                        if (abilityName.toUpperCase().equals(enumAbility.name())) %7B%0A                            list.add(enumAbility);%0A                            break;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A
             Enti
@@ -2662,16 +2662,40 @@
 pe, loc,
+ enumAbilities == null ?
  ability
@@ -2698,16 +2698,23 @@
 lityList
+ : list
 );%0A     

add support for infernalmobs 5.1.25