1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

MythicMobs 5.x support

This commit is contained in:
Zrips 2022-03-21 14:59:24 +02:00
parent 3a0be51ef3
commit a984589dce
6 changed files with 173 additions and 12 deletions

12
pom.xml
View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId>
<artifactId>jobs</artifactId>
<version>5.0.1.4</version>
<version>5.0.2.1</version>
<name>Jobs</name>
<url>http://maven.apache.org</url>
@ -77,9 +77,15 @@
<dependency>
<groupId>io.lumine.xikage</groupId>
<artifactId>MythicMobs</artifactId>
<version>4.9.1</version>
<version>4.11.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.lumine</groupId>
<artifactId>Mythic-Dist</artifactId>
<version>5.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- WorldGuard old version -->
<dependency>
<groupId>com.sk89q</groupId>
@ -191,7 +197,7 @@
<artifactId>CMILib</artifactId>
<version>latest</version>
<scope>system</scope>
<systemPath>${basedir}/libs/CMILib1.1.0.2.jar</systemPath>
<systemPath>${basedir}/libs/CMILib1.1.2.3.jar</systemPath>
</dependency>
<!-- WildStacker -->
<dependency>

View File

@ -92,7 +92,6 @@ import com.gamingmesh.jobs.economy.BufferedEconomy;
import com.gamingmesh.jobs.economy.BufferedPayment;
import com.gamingmesh.jobs.economy.Economy;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.listeners.JobsListener;

View File

@ -10,10 +10,13 @@ import com.gamingmesh.jobs.hooks.McMMO.McMMOManager;
import com.gamingmesh.jobs.hooks.MyPet.MyPetManager;
import com.gamingmesh.jobs.hooks.MythicMobs.MythicMobInterface;
import com.gamingmesh.jobs.hooks.MythicMobs.MythicMobs4;
import com.gamingmesh.jobs.hooks.MythicMobs.MythicMobs5;
import com.gamingmesh.jobs.hooks.WorldGuard.WorldGuardManager;
import com.gamingmesh.jobs.hooks.stackMob.StackMobHandler;
import com.gamingmesh.jobs.hooks.wildStacker.WildStackerHandler;
import net.Zrips.CMILib.Logs.CMIDebug;
public class HookManager {
private static McMMOManager McMMOManager;
@ -39,8 +42,9 @@ public class HookManager {
setStackMobHandler();
setWildStackerHandler();
if (checkMythicMobs())
if (checkMythicMobs()) {
MythicManager.registerListener();
}
}
public static StackMobHandler getStackMobHandler() {
@ -59,7 +63,7 @@ public class HookManager {
return wildStackerHandler;
}
public static MyPetManager getMyPetManager() {
public static MyPetManager getMyPetManager() {
if (myPetManager == null) {
setMyPetManager();
}
@ -82,7 +86,7 @@ public class HookManager {
return McMMOManager;
}
public static MythicMobInterface getMythicManager() {
public static MythicMobInterface getMythicManager() {
return MythicManager;
}
@ -101,18 +105,22 @@ public class HookManager {
}
private static void setMythicManager() {
if (!JobsHook.MythicMobs.isEnabled())
if (!JobsHook.MythicMobs.isPresent())
return;
try {
Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper");
MythicManager = new MythicMobs4(PLUGIN);
Jobs.consoleMsg("&e[Jobs] MythicMobs 4.x detected.");
} catch (ClassNotFoundException ex) {
Jobs.consoleMsg("&cYour MythicMobs version is not supported by Jobs! Supported versions: 4.9.1+");
return;
try {
Class.forName("io.lumine.mythic.bukkit.BukkitAPIHelper");
MythicManager = new MythicMobs5(PLUGIN);
Jobs.consoleMsg("&e[Jobs] MythicMobs 5.x detected.");
} catch (ClassNotFoundException e) {
Jobs.consoleMsg("&cYour MythicMobs version is not supported by Jobs! Supported versions: 4.9.1+");
}
}
Jobs.consoleMsg("&e[Jobs] MythicMobs detected.");
}
public static void setMcMMOlistener() {

View File

@ -13,6 +13,7 @@ public enum JobsHook {
mcMMO;
private Boolean enabled;
private Boolean present;
public boolean isEnabled() {
if (enabled == null) {
@ -21,4 +22,12 @@ public enum JobsHook {
return enabled;
}
public boolean isPresent() {
if (present == null) {
present = JavaPlugin.getPlugin(Jobs.class).getServer().getPluginManager().getPlugin(name()) != null;
}
return present;
}
}

View File

@ -0,0 +1,78 @@
package com.gamingmesh.jobs.hooks.MythicMobs;
import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.Plugin;
import com.gamingmesh.jobs.Jobs;
import io.lumine.mythic.api.mobs.MythicMob;
import io.lumine.mythic.bukkit.BukkitAPIHelper;
import io.lumine.mythic.bukkit.MythicBukkit;
//import io.lumine.xikage.mythicmobs.MythicMobs;
//import io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper;
//import io.lumine.xikage.mythicmobs.mobs.MythicMob;
public class MythicMobs5 implements MythicMobInterface {
public BukkitAPIHelper apiHelper;
private Jobs plugin;
public MythicMobs5(Jobs plugin) {
this.plugin = plugin;
}
@Override
public void registerListener() {
plugin.getServer().getPluginManager().registerEvents(new MythicMobs5Listener(), plugin);
}
@Override
public boolean isMythicMob(LivingEntity lVictim) {
return apiHelper != null && lVictim != null && apiHelper.isMythicMob(lVictim);
}
@Override
public boolean check() {
Plugin mm = plugin.getServer().getPluginManager().getPlugin("MythicMobs");
if (mm == null)
return false;
try {
Class.forName("io.lumine.mythic.api.mobs.MythicMob");
Class.forName("io.lumine.mythic.bukkit.BukkitAPIHelper");
Class.forName("io.lumine.mythic.bukkit.events.MythicMobDeathEvent");
} catch (ClassNotFoundException e) {
// Disabling
Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support.");
return false;
}
apiHelper = ((MythicBukkit) mm).getAPIHelper();
Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - Enabling capabilities.");
return true;
}
static boolean failed = false;
@Override
public String getDisplayName(String id) {
if (failed || apiHelper == null)
return "";
MythicMob mm = apiHelper.getMythicMob(id);
try {
if (mm != null && mm.getDisplayName() != null)
return mm.getDisplayName().toString();
} catch (Throwable e) {
if (!failed) {
failed = true;
e.printStackTrace();
Jobs.consoleMsg("&cEncountered error when checking MythicMob entity name. Support for mythicMobs will be suspended for time beying. Please report this issue.");
}
}
return "";
}
}

View File

@ -0,0 +1,61 @@
package com.gamingmesh.jobs.hooks.MythicMobs;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.MMKillInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
import io.lumine.mythic.api.mobs.MythicMob;
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
public final class MythicMobs5Listener implements Listener {
@EventHandler
public void onMythicMobDeath(MythicMobDeathEvent event) {
// Entity that died must be living
if (!(event.getEntity() instanceof LivingEntity))
return;
if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
Player pDamager = null;
// Checking if killer is player
Entity ent = null;
if (event.getKiller() instanceof Player)
pDamager = (Player) event.getKiller();
// Checking if killer is tamed animal
else if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
ent = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager();
} else
return;
if (pDamager == null)
return;
// check if in creative
if (!JobsPaymentListener.payIfCreative(pDamager))
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return;
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
if (jDamager == null)
return;
// pay
MythicMob lVictim = event.getMobType();
if (lVictim != null) {
Jobs.action(jDamager, new MMKillInfo(lVictim.getInternalName(), ActionType.MMKILL), ent);
}
}
}