diff --git a/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java b/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java index dea27c957..985e97511 100644 --- a/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java +++ b/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java @@ -18,23 +18,17 @@ package com.volmit.iris.core.link; +import io.lumine.mythic.bukkit.MythicBukkit; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.plugin.Plugin; import javax.annotation.Nullable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collection; -import java.util.function.BiFunction; public class MythicMobsLink { - private Collection mobs; - private BiFunction spawnMobFunction; - public MythicMobsLink() { } @@ -56,59 +50,10 @@ public class MythicMobsLink { */ public @Nullable Entity spawnMob(String mob, Location location) { - if (!isEnabled()) return null; - - if (spawnMobFunction != null) { - return spawnMobFunction.apply(mob, location); - } - - try { - Class mythicMobClass = Class.forName("io.lumine.mythic.bukkit.MythicBukkit"); - Method getInst = mythicMobClass.getDeclaredMethod("inst"); - Object inst = getInst.invoke(null); - Method getAPIHelper = mythicMobClass.getDeclaredMethod("getAPIHelper"); - Object apiHelper = getAPIHelper.invoke(inst); - Method spawnMobMethod = apiHelper.getClass().getDeclaredMethod("spawnMythicMob", String.class, Location.class); - - spawnMobFunction = (str, loc) -> { - try { - return (Entity) spawnMobMethod.invoke(apiHelper, str, loc); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return null; - }; - - return spawnMobFunction.apply(mob, location); - } catch (Exception e) { - e.printStackTrace(); - - } - return null; + return isEnabled() ? MythicBukkit.inst().getMobManager().spawnMob(mob, location).getEntity().getBukkitEntity() : null; } public Collection getMythicMobTypes() { - if (mobs != null) { - return mobs; - } - - if (isEnabled()) { - - try { - Class mythicMobClass = Class.forName("io.lumine.xikage.mythicmobs.MythicMobs"); - Method getInst = mythicMobClass.getDeclaredMethod("inst"); - Object inst = getInst.invoke(null); - Method getMobManager = mythicMobClass.getDeclaredMethod("getMobManager"); - Object mobManager = getMobManager.invoke(inst); - Method getMobNames = mobManager.getClass().getDeclaredMethod("getMobNames"); - mobs = (Collection) getMobNames.invoke(mobManager); - return mobs; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException e) { - e.printStackTrace(); - } - } - - return new ArrayList<>(); + return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : null; } }