package cat.nyaa.autobloodmoon.api;


import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;

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 Method spawnMob;
    private static Method isInfernalMob;

    public static void load(Plugin InfernalMobs) {
        InfernalMobsAPI.InfernalMobsPlugin = InfernalMobs;
        try {
            spawnMob = InfernalMobsPlugin.getClass().getDeclaredMethod("cSpawn", CommandSender.class,
                    String.class, Location.class, ArrayList.class);
            spawnMob.setAccessible(true);
            isInfernalMob = InfernalMobsPlugin.getClass().getDeclaredMethod("idSearch", UUID.class);
            isInfernalMob.setAccessible(true);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

    }

    public static boolean spawnMob(String mobName, ArrayList<String> abilityList, Location loc) {
        try {
            return (Boolean) spawnMob.invoke(InfernalMobsPlugin, Bukkit.getConsoleSender(), mobName, loc, abilityList);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return false;
    }

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

@@ -35,34 +35,8 @@
 ;%0A%0A%0A
-import org.bukkit.Bukkit;%0A
 impo
@@ -81,29 +81,21 @@
 kit.
-command.CommandSender
+entity.Entity
 ;%0Aim
@@ -115,32 +115,36 @@
 it.entity.Entity
+Type
 ;%0Aimport org.buk
@@ -163,16 +163,48 @@
 lugin;%0A%0A
+import java.lang.reflect.Field;%0A
 import j
@@ -409,16 +409,58 @@
 Plugin;%0A
+    private static Field mobManagerField;%0A
     priv
@@ -485,16 +485,22 @@
 spawnMob
+Method
 ;%0A    pr
@@ -532,16 +532,60 @@
 ernalMob
+Method;%0A    private static Object mobManager
 ;%0A%0A    p
@@ -715,24 +715,31 @@
         
-spawnMob
+mobManagerField
  = Infer
@@ -778,72 +778,235 @@
 ared
-Method(%22cSpawn%22, CommandSender.class,%0A                    String
+Field(%22mobManager%22);%0A            mobManagerField.setAccessible(true);%0A            mobManager = mobManagerField.get(InfernalMobsPlugin);%0A            spawnMobMethod = mobManager.getClass().getDeclaredMethod(%22spawnMob%22, EntityType
 .cla
@@ -1047,50 +1047,8 @@
 s);%0A
-            spawnMob.setAccessible(true);%0A
     
@@ -1068,16 +1068,22 @@
 ernalMob
+Method
  = Infer
@@ -1175,16 +1175,22 @@
 ernalMob
+Method
 .setAcce
@@ -1293,157 +1293,443 @@
    %7D
-%0A%0A    %7D%0A%0A    public static boolean spawnMob(String mobName, ArrayList%3CString%3E abilityList, Location loc) %7B%0A        try %7B%0A            return (Boolean)
+ catch (NoSuchFieldException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IllegalAccessException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A    %7D%0A%0A    public static boolean spawnMob(String mobName, ArrayList%3CString%3E abilityList, Location loc) %7B%0A        try %7B%0A            EntityType type = EntityType.fromName(mobName);%0A            if (type == null) %7B%0A                return false;%0A            %7D%0A            Object mob =
  spa
@@ -1733,24 +1733,30 @@
 spawnMob
+Method
 .invoke(
 Infernal
@@ -1751,81 +1751,75 @@
 oke(
-InfernalMobsPlugin, Bukkit.getConsoleSender(), mobName, loc, abilityList)
+mobManager, type, loc, abilityList);%0A            return mob != null
 ;%0A  
@@ -2118,16 +2118,22 @@
 ernalMob
+Method
 .invoke(

update InfernalMobsAPI