9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-24 17:49:16 +00:00
This commit is contained in:
Sjoerd van de Goor
2023-03-03 23:23:19 +01:00
parent 7e55b5fcee
commit 4e138cad9f

View File

@@ -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<String> mobs;
private BiFunction<String, Location, Entity> 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<String> 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<String>) getMobNames.invoke(mobManager);
return mobs;
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
e.printStackTrace();
}
}
return new ArrayList<>();
return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : null;
}
}