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.UUID;

public class InfernalMobsAPI {
    private static Plugin InfernalMobsPlugin;
    private static Field mobManagerField;
    private static Method spawnMobMethod;
    private static Method isInfernalMobMethod;
    private static Object mobManager;

    public static void load(Plugin InfernalMobs) {
        InfernalMobsAPI.InfernalMobsPlugin = InfernalMobs;
        try {
            mobManagerField = InfernalMobsPlugin.getClass().getDeclaredField("mobManager");
            mobManagerField.setAccessible(true);
            mobManager = mobManagerField.get(InfernalMobsPlugin);
            spawnMobMethod = mobManager.getClass().getDeclaredMethod("spawnMob", EntityType.class, Location.class, ArrayList.class);
            isInfernalMobMethod = InfernalMobsPlugin.getClass().getDeclaredMethod("idSearch", UUID.class);
            isInfernalMobMethod.setAccessible(true);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    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(mobManager, type, loc, abilityList);
            return mob != null;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return false;
    }

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

@@ -308,16 +308,45 @@
 ayList;%0A
+import java.util.Collection;%0A
 import j
@@ -396,96 +396,8 @@
 I %7B%0A
-    private static Plugin InfernalMobsPlugin;%0A    private static Field mobManagerField;%0A
     
@@ -484,46 +484,8 @@
 hod;
-%0A    private static Object mobManager;
 %0A%0A  
@@ -545,259 +545,145 @@
     
-InfernalMobsAPI.InfernalMobsPlugin = InfernalMobs;%0A        try %7B%0A            mobManagerField = InfernalMobsPlugin.getClass().getDeclaredField(%22mobManager%22);%0A            mobManagerField.setAccessible(true);%0A            mobManager = mobManagerField.get(
+try %7B%0A            spawnMobMethod = Class.forName(%22com.jacob_vejvoda.infernal_mobs.InfernalMobsAPI%22).getMethod(%0A                    %22spawn
 Infe
@@ -693,17 +693,10 @@
 lMob
-sPlugin);
+%22,
 %0A   
@@ -708,76 +708,15 @@
     
-spawnMobMethod = mobManager.getClass().getDeclaredMethod(%22spawnMob%22,
+       
  Ent
@@ -750,23 +750,37 @@
 ss, 
-ArrayList.class
+Collection.class%0A            
 );%0A 
@@ -816,81 +816,92 @@
 d = 
-I
+Class.forName(%22com.jacob_vejvoda.i
 nfernal
-MobsPlugin.getClass().getDeclaredMethod(%22idSearch%22, UUID.class);%0A
+_mobs.InfernalMobsAPI%22).getMethod(%0A        
     
@@ -900,33 +900,34 @@
                 
-i
+%22a
 sInfernalMobMeth
@@ -926,186 +926,54 @@
 lMob
-Method.setAccessible(true);%0A        %7D catch (NoSuchMethodException e) %7B%0A            e.printStackTrace();%0A        %7D catch (NoSuchFieldException e) %7B%0A            e.printStackTrace(
+%22,%0A                    UUID.class%0A            
 );%0A 
@@ -984,37 +984,43 @@
    %7D catch (
-IllegalAccess
+ReflectiveOperation
 Exception e)
@@ -1061,25 +1061,24 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%0A    p
@@ -1371,18 +1371,12 @@
 oke(
-mobManager
+null
 , ty
@@ -1716,15 +1716,8 @@
 if (
-((int) 
 isIn
@@ -1743,26 +1743,12 @@
 oke(
-InfernalMobsPlugin
+null
 , mo
@@ -1767,15 +1767,16 @@
 d())
-)
  != 
--1
+null
 ) %7B%0A

update InfernalMobsAPI