1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Reworked the initialization of dependencies

This commit is contained in:
montlikadani 2020-01-26 17:48:23 +01:00
parent 066c0dd2b6
commit 0b43b7e91a
22 changed files with 907 additions and 834 deletions

Binary file not shown.

View File

@ -24,18 +24,17 @@ import com.gamingmesh.jobs.CMILib.Reflections;
import com.gamingmesh.jobs.CMILib.VersionChecker; import com.gamingmesh.jobs.CMILib.VersionChecker;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
import com.gamingmesh.jobs.Gui.GuiManager; import com.gamingmesh.jobs.Gui.GuiManager;
import com.gamingmesh.jobs.McMMO.McMMO1_X_listener;
import com.gamingmesh.jobs.McMMO.McMMO2_X_listener;
import com.gamingmesh.jobs.McMMO.McMMOManager;
import com.gamingmesh.jobs.MyPet.MyPetManager;
import com.gamingmesh.jobs.MythicMobs.MythicMobInterface;
import com.gamingmesh.jobs.MythicMobs.MythicMobs2;
import com.gamingmesh.jobs.MythicMobs.MythicMobs4;
import com.gamingmesh.jobs.Placeholders.NewPlaceholderAPIHook; import com.gamingmesh.jobs.Placeholders.NewPlaceholderAPIHook;
import com.gamingmesh.jobs.Placeholders.Placeholder; import com.gamingmesh.jobs.Placeholders.Placeholder;
import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook; import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook;
import com.gamingmesh.jobs.hooks.HookManager;
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.MythicMobs2;
import com.gamingmesh.jobs.hooks.MythicMobs.MythicMobs4;
import com.gamingmesh.jobs.hooks.WorldGuard.WorldGuardManager;
import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.WorldGuard.WorldGuardManager;
import com.gamingmesh.jobs.api.JobsExpGainEvent; import com.gamingmesh.jobs.api.JobsExpGainEvent;
import com.gamingmesh.jobs.api.JobsPrePaymentEvent; import com.gamingmesh.jobs.api.JobsPrePaymentEvent;
import com.gamingmesh.jobs.commands.JobsCommands; import com.gamingmesh.jobs.commands.JobsCommands;
@ -63,7 +62,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
@ -73,7 +71,9 @@ import java.util.Map.Entry;
import java.util.logging.Logger; import java.util.logging.Logger;
public class Jobs extends JavaPlugin { public class Jobs extends JavaPlugin {
private static String version = ""; private static String version = "";
private static PlayerManager pManager = null; private static PlayerManager pManager = null;
private static JobsCommands cManager = null; private static JobsCommands cManager = null;
private static Language lManager = null; private static Language lManager = null;
@ -91,14 +91,17 @@ public class Jobs extends JavaPlugin {
private static ShopManager shopManager = null; private static ShopManager shopManager = null;
private static Loging loging = null; private static Loging loging = null;
private static BlockProtectionManager BpManager = null; private static BlockProtectionManager BpManager = null;
private static JobsManager DBManager = null; private static JobsManager DBManager = null;
private static PistonProtectionListener PistonProtectionListener = null; private static PistonProtectionListener PistonProtectionListener = null;
private static McMMOManager McMMOManager = null;
@Deprecated
private static McMMOManager McMMOManager = null;
@Deprecated
private static MythicMobInterface MythicManager = null; private static MythicMobInterface MythicManager = null;
@Deprecated
private static MyPetManager myPetManager = null; private static MyPetManager myPetManager = null;
@Deprecated
private static WorldGuardManager worldGuardManager = null; private static WorldGuardManager worldGuardManager = null;
private static ConfigManager configManager = null; private static ConfigManager configManager = null;
@ -136,17 +139,7 @@ public class Jobs extends JavaPlugin {
private static PointsData pointsDatabase = null; private static PointsData pointsDatabase = null;
private void setMcMMOlistener() { @Deprecated
try {
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
getServer().getPluginManager().registerEvents(new McMMO2_X_listener(this), this);
consoleMsg("&e[Jobs] Registered McMMO 2.x listener");
} catch (ClassNotFoundException e) {
getServer().getPluginManager().registerEvents(new McMMO1_X_listener(this), this);
consoleMsg("&e[Jobs] Registered McMMO 1.x listener");
}
}
public static McMMOManager getMcMMOManager() { public static McMMOManager getMcMMOManager() {
if (McMMOManager == null) if (McMMOManager == null)
McMMOManager = new McMMOManager(); McMMOManager = new McMMOManager();
@ -161,10 +154,7 @@ public class Jobs extends JavaPlugin {
return PistonProtectionListener; return PistonProtectionListener;
} }
private void setMyPetManager() { @Deprecated
myPetManager = new MyPetManager();
}
public static MyPetManager getMyPetManager() { public static MyPetManager getMyPetManager() {
if (myPetManager == null && getInstance().getServer().getPluginManager().getPlugin("MyPet") != null) { if (myPetManager == null && getInstance().getServer().getPluginManager().getPlugin("MyPet") != null) {
myPetManager = new MyPetManager(); myPetManager = new MyPetManager();
@ -206,10 +196,12 @@ public class Jobs extends JavaPlugin {
return true; return true;
} }
@Deprecated
public static WorldGuardManager getWorldGuardManager() { public static WorldGuardManager getWorldGuardManager() {
return worldGuardManager; return worldGuardManager;
} }
@Deprecated
public void setMythicManager() { public void setMythicManager() {
try { try {
Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI"); Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI");
@ -225,16 +217,7 @@ public class Jobs extends JavaPlugin {
consoleMsg("&e[Jobs] MythicMobs detected."); consoleMsg("&e[Jobs] MythicMobs detected.");
} }
private boolean setWorldGuard() { @Deprecated
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin != null) {
worldGuardManager = new WorldGuardManager();
consoleMsg("&e[Jobs] WorldGuard detected.");
return true;
}
return false;
}
public static MythicMobInterface getMythicManager() { public static MythicMobInterface getMythicManager() {
return MythicManager; return MythicManager;
} }
@ -626,13 +609,8 @@ public class Jobs extends JavaPlugin {
if (GconfigManager.useBlockProtection) if (GconfigManager.useBlockProtection)
pm.registerEvents(PistonProtectionListener, instance); pm.registerEvents(PistonProtectionListener, instance);
if (getMcMMOManager().CheckmcMMO()) { if (HookManager.getMcMMOManager().CheckmcMMO()) {
try { HookManager.setMcMMOlistener();
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
pm.registerEvents(new McMMO2_X_listener(instance), instance);
} catch (ClassNotFoundException e) {
pm.registerEvents(new McMMO1_X_listener(instance), instance);
}
} }
} }
@ -888,17 +866,7 @@ public class Jobs extends JavaPlugin {
getServer().getPluginManager().registerEvents(new JobsPayment14Listener(), this); getServer().getPluginManager().registerEvents(new JobsPayment14Listener(), this);
} }
if (getMcMMOManager().CheckmcMMO()) HookManager.loadHooks();
setMcMMOlistener();
if (getServer().getPluginManager().isPluginEnabled("MyPet")) {
setMyPetManager();
}
setWorldGuard();
setMythicManager();
if (GconfigManager.MythicMobsEnabled && MythicManager != null && MythicManager.Check())
MythicManager.registerListener();
setPistonProtectionListener(); setPistonProtectionListener();
if (GconfigManager.useBlockProtection) { if (GconfigManager.useBlockProtection) {

View File

@ -1 +0,0 @@
/MyPetManager.class

View File

@ -1,6 +0,0 @@
/MythicMobs2Listener.class
/MythicMobsManager.class
/MythicMobInterface.class
/MythicMobs2.class
/MythicMobs4.class
/MythicMobs4Listener.class

View File

@ -65,6 +65,7 @@ import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.dao.JobsDAOData; import com.gamingmesh.jobs.dao.JobsDAOData;
import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.economy.PointsData; import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.PerformCommands; import com.gamingmesh.jobs.stuff.PerformCommands;
import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.stuff.Util;
@ -985,8 +986,8 @@ public class PlayerManager {
if (player == null || prog == null) if (player == null || prog == null)
return boost; return boost;
if (Jobs.getMcMMOManager().mcMMOPresent || Jobs.getMcMMOManager().mcMMOOverHaul) if (HookManager.getMcMMOManager().mcMMOPresent || HookManager.getMcMMOManager().mcMMOOverHaul)
boost.add(BoostOf.McMMO, new BoostMultiplier().add(Jobs.getMcMMOManager().getMultiplier(player.getPlayer()))); boost.add(BoostOf.McMMO, new BoostMultiplier().add(HookManager.getMcMMOManager().getMultiplier(player.getPlayer())));
if (ent != null && (ent instanceof Tameable)) { if (ent != null && (ent instanceof Tameable)) {
Tameable t = (Tameable) ent; Tameable t = (Tameable) ent;
@ -997,7 +998,7 @@ public class PlayerManager {
} }
} }
if (ent != null && Jobs.getMyPetManager() != null && Jobs.getMyPetManager().isMyPet(ent)) { if (ent != null && HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(ent)) {
Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay");
if (amount != null) if (amount != null)
boost.add(BoostOf.PetPay, new BoostMultiplier().add(amount)); boost.add(BoostOf.PetPay, new BoostMultiplier().add(amount));

View File

@ -1,6 +0,0 @@
/MythicMobs2Listener.class
/MythicMobsManager.class
/MythicMobInterface.class
/MythicMobs2.class
/MythicMobs4.class
/MythicMobs4Listener.class

View File

@ -14,6 +14,7 @@ import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.config.RestrictedAreaManager; import com.gamingmesh.jobs.config.RestrictedAreaManager;
import com.gamingmesh.jobs.container.CuboidArea; import com.gamingmesh.jobs.container.CuboidArea;
import com.gamingmesh.jobs.container.RestrictedArea; import com.gamingmesh.jobs.container.RestrictedArea;
import com.gamingmesh.jobs.hooks.HookManager;
public class area implements Cmd { public class area implements Cmd {
@ -58,8 +59,8 @@ public class area implements Cmd {
"%tool%", CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getName())); "%tool%", CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getName()));
return true; return true;
} }
if (wg && Jobs.getWorldGuardManager() != null) { if (wg && HookManager.getWorldGuardManager() != null) {
name = Jobs.getWorldGuardManager().getNameByName(name); name = HookManager.getWorldGuardManager().getNameByName(name);
if (name == null) { if (name == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgDontExist")); sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgDontExist"));
return true; return true;

View File

@ -11,6 +11,7 @@ import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
public class bonus implements Cmd { public class bonus implements Cmd {
@ -53,7 +54,8 @@ public class bonus implements Cmd {
printBoost(sender, boost, BoostOf.NearSpawner); printBoost(sender, boost, BoostOf.NearSpawner);
printBoost(sender, boost, BoostOf.PetPay); printBoost(sender, boost, BoostOf.PetPay);
if (Jobs.getMcMMOManager().mcMMOPresent || Jobs.getMcMMOManager().mcMMOOverHaul && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D) if (HookManager.getMcMMOManager().mcMMOPresent ||
HookManager.getMcMMOManager().mcMMOOverHaul && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D)
printBoost(sender, boost, BoostOf.McMMO); printBoost(sender, boost, BoostOf.McMMO);
player.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); player.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));

View File

@ -18,6 +18,7 @@ import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.NameList; import com.gamingmesh.jobs.container.NameList;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.stuff.Util;
public class NameTranslatorManager { public class NameTranslatorManager {
@ -101,9 +102,7 @@ public class NameTranslatorManager {
NameList got = ListOfMMEntities.get(materialName.toLowerCase()); NameList got = ListOfMMEntities.get(materialName.toLowerCase());
if (got != null && got.getName() != null) if (got != null && got.getName() != null)
return got.getName(); return got.getName();
if (Jobs.getMythicManager() == null) return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName);
return materialName;
return Jobs.getMythicManager().getDisplayName(materialName);
default: default:
break; break;
} }

View File

@ -17,6 +17,7 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.CuboidArea; import com.gamingmesh.jobs.container.CuboidArea;
import com.gamingmesh.jobs.container.RestrictedArea; import com.gamingmesh.jobs.container.RestrictedArea;
import com.gamingmesh.jobs.hooks.HookManager;
public class RestrictedAreaManager { public class RestrictedAreaManager {
@ -110,7 +111,8 @@ public class RestrictedAreaManager {
for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) { for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) {
if (area.inRestrictedArea(player.getLocation())) if (area.inRestrictedArea(player.getLocation()))
return area.getMultiplier(); return area.getMultiplier();
if (area.getWgName() != null && Jobs.getWorldGuardManager() != null && Jobs.getWorldGuardManager().inArea(player.getLocation(), area.getWgName())) if (area.getWgName() != null && HookManager.getWorldGuardManager() != null
&& HookManager.getWorldGuardManager().inArea(player.getLocation(), area.getWgName()))
return area.getMultiplier(); return area.getMultiplier();
} }
@ -124,8 +126,8 @@ public class RestrictedAreaManager {
areas.add(area.getValue()); areas.add(area.getValue());
} }
if (Jobs.getWorldGuardManager() != null) if (HookManager.getWorldGuardManager() != null)
areas.addAll(Jobs.getWorldGuardManager().getArea(loc)); areas.addAll(HookManager.getWorldGuardManager().getArea(loc));
return areas; return areas;
} }

View File

@ -0,0 +1,113 @@
package com.gamingmesh.jobs.hooks;
import org.bukkit.plugin.PluginManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.hooks.McMMO.McMMO1_X_listener;
import com.gamingmesh.jobs.hooks.McMMO.McMMO2_X_listener;
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.MythicMobs2;
import com.gamingmesh.jobs.hooks.MythicMobs.MythicMobs4;
import com.gamingmesh.jobs.hooks.WorldGuard.WorldGuardManager;
public class HookManager {
private static McMMOManager McMMOManager = null;
private static MythicMobInterface MythicManager = null;
private static MyPetManager myPetManager = null;
private static WorldGuardManager worldGuardManager = null;
private static PluginManager pm = null;
public static void loadHooks() {
pm = Jobs.getInstance().getServer().getPluginManager();
if (getMcMMOManager().CheckmcMMO())
setMcMMOlistener();
setMyPetManager();
setWorldGuard();
setMythicManager();
if (Jobs.getGCManager().MythicMobsEnabled && MythicManager != null && MythicManager.Check())
MythicManager.registerListener();
}
public static MyPetManager getMyPetManager() {
if (myPetManager == null) {
setMyPetManager();
}
return myPetManager;
}
public static WorldGuardManager getWorldGuardManager() {
if (worldGuardManager == null) {
worldGuardManager = new WorldGuardManager();
}
return worldGuardManager;
}
public static McMMOManager getMcMMOManager() {
if (McMMOManager == null)
McMMOManager = new McMMOManager();
return McMMOManager;
}
public static MythicMobInterface getMythicManager() {
return MythicManager;
}
private static boolean setWorldGuard() {
if (pm.getPlugin("WorldGuard") != null && pm.isPluginEnabled("WorldGuard")) {
worldGuardManager = new WorldGuardManager();
Jobs.consoleMsg("&e[Jobs] WorldGuard detected.");
return true;
}
return false;
}
private static void setMythicManager() {
try {
Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI");
MythicManager = new MythicMobs2(Jobs.getInstance());
} catch (ClassNotFoundException e) {
try {
Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper");
MythicManager = new MythicMobs4(Jobs.getInstance());
} catch (ClassNotFoundException ex) {
}
}
if (MythicManager == null) {
Jobs.consoleMsg("&cYour MythicMobs version is not supported by Jobs! Supported versions: 2.4.5+, 4.6.5");
return;
}
Jobs.consoleMsg("&e[Jobs] MythicMobs detected.");
}
public static void setMcMMOlistener() {
Jobs ins = Jobs.getInstance();
try {
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
pm.registerEvents(new McMMO2_X_listener(ins), ins);
Jobs.consoleMsg("&e[Jobs] Registered McMMO 2.x listener");
} catch (ClassNotFoundException e) {
pm.registerEvents(new McMMO1_X_listener(ins), ins);
Jobs.consoleMsg("&e[Jobs] Registered McMMO 1.x listener");
}
}
private static void setMyPetManager() {
if (pm.getPlugin("MyPet") != null && pm.isPluginEnabled("MyPet")) {
myPetManager = new MyPetManager();
Jobs.consoleMsg("&e[Jobs] MyPet detected.");
}
}
}

View File

@ -1,93 +1,92 @@
package com.gamingmesh.jobs.McMMO; package com.gamingmesh.jobs.hooks.McMMO;
import java.lang.reflect.InvocationTargetException; import java.util.HashMap;
import java.util.HashMap;
import org.bukkit.GameMode;
import org.bukkit.GameMode; import org.bukkit.entity.Player;
import org.bukkit.entity.Player; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority;
import org.bukkit.event.EventPriority; import org.bukkit.event.Listener;
import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.actions.ItemActionInfo;
import com.gamingmesh.jobs.actions.ItemActionInfo; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.hooks.HookManager;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
public class McMMO1_X_listener implements Listener { public class McMMO1_X_listener implements Listener {
private Jobs plugin; private Jobs plugin;
public McMMO1_X_listener(Jobs plugin) { public McMMO1_X_listener(Jobs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler @EventHandler
public void OnItemrepair(McMMOPlayerRepairCheckEvent event) { public void OnItemrepair(McMMOPlayerRepairCheckEvent event) {
//disabling plugin in world // make sure plugin is enabled
if (event.getPlayer() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld())) if (!plugin.isEnabled())
return; return;
// make sure plugin is enabled
if (!plugin.isEnabled()) Player player = event.getPlayer();
return; //disabling plugin in world
if (player == null || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld()))
Player player = event.getPlayer(); return;
ItemStack resultStack = event.getRepairedObject(); ItemStack resultStack = event.getRepairedObject();
if (resultStack == null)
if (resultStack == null) return;
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) return;
return;
// check if in creative
// check if in creative if (player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative())
if (player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative()) return;
return;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); if (jPlayer == null)
if (jPlayer == null) return;
return;
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR)); }
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void OnAbilityOn(McMMOPlayerAbilityActivateEvent event) {
public void OnAbilityOn(McMMOPlayerAbilityActivateEvent event) { HashMap<String, Long> InfoMap = HookManager.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId());
HashMap<String, Long> InfoMap = Jobs.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId()); if (InfoMap == null) {
if (InfoMap == null) { InfoMap = new HashMap<>();
InfoMap = new HashMap<>(); HookManager.getMcMMOManager().getMap().put(event.getPlayer().getUniqueId(), InfoMap);
Jobs.getMcMMOManager().getMap().put(event.getPlayer().getUniqueId(), InfoMap); }
}
try {
try { Object ab = event.getClass().getMethod("getAbility").invoke(event);
Object ab = event.getClass().getMethod("getAbility").invoke(event); // Lets use fixed timer as this tend to return 0
// Lets use fixed timer as this tend to return 0 // int maxLenght = (int) ab.getClass().getMethod("getMaxLength").invoke(ab);
// int maxLenght = (int) ab.getClass().getMethod("getMaxLength").invoke(ab); InfoMap.put(String.valueOf(ab), System.currentTimeMillis() + (30 * 1000));
InfoMap.put(String.valueOf(ab), System.currentTimeMillis() + (30 * 1000)); } catch (Exception e) {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace();
e.printStackTrace(); }
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void OnAbilityOff(McMMOPlayerAbilityDeactivateEvent event) {
public void OnAbilityOff(McMMOPlayerAbilityDeactivateEvent event) { HashMap<String, Long> InfoMap = HookManager.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId());
HashMap<String, Long> InfoMap = Jobs.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId()); if (InfoMap != null) {
if (InfoMap != null) { try {
try { Object ab = event.getClass().getMethod("getAbility").invoke(event);
Object ab = event.getClass().getMethod("getAbility").invoke(event); InfoMap.remove(String.valueOf(ab));
InfoMap.remove(String.valueOf(ab)); if (InfoMap.isEmpty())
if (InfoMap.isEmpty()) HookManager.getMcMMOManager().getMap().remove(event.getPlayer().getUniqueId());
Jobs.getMcMMOManager().getMap().remove(event.getPlayer().getUniqueId()); } catch (Exception e) {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace();
e.printStackTrace(); }
}
}
} }
} }
}

View File

@ -1,78 +1,78 @@
package com.gamingmesh.jobs.McMMO; package com.gamingmesh.jobs.hooks.McMMO;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.ItemActionInfo; import com.gamingmesh.jobs.actions.ItemActionInfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; import com.gamingmesh.jobs.hooks.HookManager;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
public class McMMO2_X_listener implements Listener {
public class McMMO2_X_listener implements Listener {
private Jobs plugin;
private Jobs plugin;
public McMMO2_X_listener(Jobs plugin) {
this.plugin = plugin; public McMMO2_X_listener(Jobs plugin) {
} this.plugin = plugin;
}
@EventHandler
public void OnItemrepair(McMMOPlayerRepairCheckEvent event) { @EventHandler
//disabling plugin in world public void OnItemrepair(McMMOPlayerRepairCheckEvent event) {
if (event.getPlayer() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld())) // make sure plugin is enabled
return; if (!plugin.isEnabled())
// make sure plugin is enabled return;
if (!plugin.isEnabled())
return; Player player = event.getPlayer();
// disabling plugin in world
Player player = event.getPlayer(); if (player == null || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld()))
return;
ItemStack resultStack = event.getRepairedObject();
ItemStack resultStack = event.getRepairedObject();
if (resultStack == null) if (resultStack == null)
return; return;
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return; return;
// check if in creative // check if in creative
if (player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative()) if (player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative())
return; return;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null) if (jPlayer == null)
return; return;
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR)); Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void OnAbilityOn(McMMOPlayerAbilityActivateEvent event) { public void OnAbilityOn(McMMOPlayerAbilityActivateEvent event) {
HashMap<String, Long> InfoMap = Jobs.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId()); HashMap<String, Long> InfoMap = HookManager.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId());
if (InfoMap == null) { if (InfoMap == null) {
InfoMap = new HashMap<>(); InfoMap = new HashMap<>();
Jobs.getMcMMOManager().getMap().put(event.getPlayer().getUniqueId(), InfoMap); HookManager.getMcMMOManager().getMap().put(event.getPlayer().getUniqueId(), InfoMap);
} }
InfoMap.put(event.getAbility().toString(), System.currentTimeMillis() + (30 * 1000));
} InfoMap.put(event.getAbility().toString(), System.currentTimeMillis() + (30 * 1000));
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void OnAbilityOff(McMMOPlayerAbilityDeactivateEvent event) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
HashMap<String, Long> InfoMap = Jobs.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId()); public void OnAbilityOff(McMMOPlayerAbilityDeactivateEvent event) {
if (InfoMap != null) { HashMap<String, Long> InfoMap = HookManager.getMcMMOManager().getMap().get(event.getPlayer().getUniqueId());
InfoMap.remove(event.getAbility().toString()); if (InfoMap != null) {
if (InfoMap.isEmpty()) InfoMap.remove(event.getAbility().toString());
Jobs.getMcMMOManager().getMap().remove(event.getPlayer().getUniqueId()); if (InfoMap.isEmpty())
} HookManager.getMcMMOManager().getMap().remove(event.getPlayer().getUniqueId());
} }
}
} }

View File

@ -1,111 +1,115 @@
package com.gamingmesh.jobs.McMMO; package com.gamingmesh.jobs.hooks.McMMO;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
public class McMMOManager { public class McMMOManager {
public boolean mcMMOPresent = false; public boolean mcMMOPresent = false;
public boolean mcMMOOverHaul = false; public boolean mcMMOOverHaul = false;
private HashMap<UUID, HashMap<String, Long>> map = new HashMap<>(); private HashMap<UUID, HashMap<String, Long>> map = new HashMap<>();
public double getMultiplier(Player player) { public HashMap<UUID, HashMap<String, Long>> getMap() {
if (player == null) return map;
return 0D; }
HashMap<String, Long> InfoMap = map.get(player.getUniqueId()); public void setMap(HashMap<UUID, HashMap<String, Long>> map) {
if (InfoMap == null) this.map = map;
return 0D; }
if (mcMMOOverHaul) {
Long t = InfoMap.get(SuperAbilityType.TREE_FELLER.toString()); public double getMultiplier(Player player) {
if (t != null) { if (player == null)
if (t > System.currentTimeMillis()) return 0D;
return -(1 - Jobs.getGCManager().TreeFellerMultiplier);
InfoMap.remove(SuperAbilityType.TREE_FELLER.toString()); HashMap<String, Long> InfoMap = map.get(player.getUniqueId());
} if (InfoMap == null)
return 0D;
t = InfoMap.get(SuperAbilityType.GIGA_DRILL_BREAKER.toString());
if (t != null) { if (mcMMOOverHaul) {
if (t > System.currentTimeMillis()) Long t = InfoMap.get(SuperAbilityType.TREE_FELLER.toString());
return -(1 - Jobs.getGCManager().gigaDrillMultiplier); if (t != null) {
InfoMap.remove(SuperAbilityType.GIGA_DRILL_BREAKER.toString()); if (t > System.currentTimeMillis())
} return -(1 - Jobs.getGCManager().TreeFellerMultiplier);
InfoMap.remove(SuperAbilityType.TREE_FELLER.toString());
t = InfoMap.get(SuperAbilityType.SUPER_BREAKER.toString()); }
if (t != null) {
if (t > System.currentTimeMillis()) t = InfoMap.get(SuperAbilityType.GIGA_DRILL_BREAKER.toString());
return -(1 - Jobs.getGCManager().superBreakerMultiplier); if (t != null) {
InfoMap.remove(SuperAbilityType.SUPER_BREAKER.toString()); if (t > System.currentTimeMillis())
} return -(1 - Jobs.getGCManager().gigaDrillMultiplier);
} else if (mcMMOPresent) { InfoMap.remove(SuperAbilityType.GIGA_DRILL_BREAKER.toString());
Long t = InfoMap.get("TREE_FELLER"); }
if (t != null) {
if (t > System.currentTimeMillis()) t = InfoMap.get(SuperAbilityType.SUPER_BREAKER.toString());
return -(1 - Jobs.getGCManager().TreeFellerMultiplier); if (t != null) {
InfoMap.remove("TREE_FELLER"); if (t > System.currentTimeMillis())
} return -(1 - Jobs.getGCManager().superBreakerMultiplier);
InfoMap.remove(SuperAbilityType.SUPER_BREAKER.toString());
t = InfoMap.get("GIGA_DRILL_BREAKER"); }
if (t != null) { } else if (mcMMOPresent) {
if (t > System.currentTimeMillis()) Long t = InfoMap.get("TREE_FELLER");
return -(1 - Jobs.getGCManager().gigaDrillMultiplier); if (t != null) {
InfoMap.remove("GIGA_DRILL_BREAKER"); if (t > System.currentTimeMillis())
} return -(1 - Jobs.getGCManager().TreeFellerMultiplier);
InfoMap.remove("TREE_FELLER");
t = InfoMap.get("SUPER_BREAKER"); }
if (t != null) {
if (t > System.currentTimeMillis()) t = InfoMap.get("GIGA_DRILL_BREAKER");
return -(1 - Jobs.getGCManager().superBreakerMultiplier); if (t != null) {
InfoMap.remove("SUPER_BREAKER"); if (t > System.currentTimeMillis())
} return -(1 - Jobs.getGCManager().gigaDrillMultiplier);
} InfoMap.remove("GIGA_DRILL_BREAKER");
}
return 0D;
} t = InfoMap.get("SUPER_BREAKER");
if (t != null) {
public boolean CheckmcMMO() { if (t > System.currentTimeMillis())
Plugin McMMO = Bukkit.getPluginManager().getPlugin("mcMMO"); return -(1 - Jobs.getGCManager().superBreakerMultiplier);
if (McMMO != null) { InfoMap.remove("SUPER_BREAKER");
try { }
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType"); }
mcMMOOverHaul = true;
} catch (ClassNotFoundException c) { return 0D;
// Disabling skill API check; }
mcMMOOverHaul = false;
Jobs.consoleMsg("&e[Jobs] &6mcMMO was found - &cBut your McMMO version is outdated, please update for full support."); public boolean CheckmcMMO() {
try { Plugin McMMO = Bukkit.getPluginManager().getPlugin("mcMMO");
Class.forName("com.gmail.nossr50.api.AbilityAPI"); if (McMMO != null) {
mcMMOPresent = true; try {
} catch (ClassNotFoundException e) { Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
// Disabling skill API check; mcMMOOverHaul = true;
mcMMOPresent = false; } catch (ClassNotFoundException c) {
Jobs.consoleMsg("&e[Jobs] &6mcMMO was found - &cBut your McMMO version is outdated, please update for full support."); // Disabling skill API check;
// Still enabling event listener for repair mcMMOOverHaul = false;
return true; Jobs.consoleMsg("&e[Jobs] &6mcMMO was found - &cBut your McMMO version is outdated, please update for full support.");
}
// Still enabling event listener for repair try {
return true; Class.forName("com.gmail.nossr50.api.AbilityAPI");
} mcMMOPresent = true;
} catch (ClassNotFoundException e) {
Jobs.consoleMsg("&e[Jobs] &6mcMMO" + McMMO.getDescription().getVersion() + " was found - Enabling capabilities."); // Disabling skill API check;
return true; mcMMOPresent = false;
} Jobs.consoleMsg("&e[Jobs] &6mcMMO was found - &cBut your McMMO version is outdated, please update for full support.");
return false; // Still enabling event listener for repair
} return true;
}
public HashMap<UUID, HashMap<String, Long>> getMap() {
return map; // Still enabling event listener for repair
} return true;
}
public void setMap(HashMap<UUID, HashMap<String, Long>> map) {
this.map = map; Jobs.consoleMsg("&e[Jobs] &6mcMMO" + McMMO.getDescription().getVersion() + " was found - Enabling capabilities.");
} return true;
} }
return false;
}
}

View File

@ -1,61 +1,46 @@
package com.gamingmesh.jobs.MyPet; package com.gamingmesh.jobs.hooks.MyPet;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import de.Keyle.MyPet.MyPetApi;
import org.bukkit.plugin.Plugin; import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.MyPetBukkitEntity;
import com.gamingmesh.jobs.Jobs; import de.Keyle.MyPet.api.repository.PlayerManager;
import de.Keyle.MyPet.MyPetApi; public class MyPetManager {
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; PlayerManager mp;
import de.Keyle.MyPet.api.repository.PlayerManager; de.Keyle.MyPet.api.repository.MyPetManager mppm;
private boolean enabled = false;
public class MyPetManager {
public MyPetManager() {
PlayerManager mp; mp = MyPetApi.getPlayerManager();
de.Keyle.MyPet.api.repository.MyPetManager mppm; mppm = MyPetApi.getMyPetManager();
private boolean enabled = false; enabled = true;
}
public MyPetManager() {
setup(); public boolean isMyPet(Object ent) {
} if (!enabled || ent == null)
return false;
public boolean isMyPet(Object ent) { if (!(ent instanceof MyPetBukkitEntity))
if (!enabled || ent == null) return false;
return false;
if (!(ent instanceof MyPetBukkitEntity)) return true;
return false; }
return true; public UUID getOwnerOfPet(Object ent) {
} if (!enabled || ent == null)
return null;
public UUID getOwnerOfPet(Object ent) { if (!(ent instanceof MyPetBukkitEntity))
if (!enabled || ent == null) return null;
return null;
if (!(ent instanceof MyPetBukkitEntity)) MyPet myPet = ((MyPetBukkitEntity) ent).getMyPet();
return null;
try {
MyPet myPet = ((MyPetBukkitEntity) ent).getMyPet(); UUID uuid = myPet.getOwner().getPlayer().getUniqueId();
return uuid;
try { } catch (Exception e) {
UUID uuid = myPet.getOwner().getPlayer().getUniqueId(); return null;
return uuid; }
} catch (Exception e) { }
return null; }
}
}
public void setup() {
Plugin pl = Bukkit.getPluginManager().getPlugin("MyPet");
if (pl == null || !Bukkit.getPluginManager().isPluginEnabled("MyPet"))
return;
mp = MyPetApi.getPlayerManager();
mppm = MyPetApi.getMyPetManager();
enabled = true;
Jobs.consoleMsg("&e[Jobs] &6MyPet detected");
}
}

View File

@ -1,17 +1,14 @@
package com.gamingmesh.jobs.MythicMobs; package com.gamingmesh.jobs.hooks.MythicMobs;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
public interface MythicMobInterface { public interface MythicMobInterface {
boolean Check(); boolean Check();
boolean isMythicMob(LivingEntity lVictim); boolean isMythicMob(LivingEntity lVictim);
void registerListener(); void registerListener();
String getDisplayName(String id); String getDisplayName(String id);
}
}

View File

@ -1,71 +1,72 @@
package com.gamingmesh.jobs.MythicMobs; package com.gamingmesh.jobs.hooks.MythicMobs;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import net.elseland.xikage.MythicMobs.MythicMobs; import net.elseland.xikage.MythicMobs.MythicMobs;
import net.elseland.xikage.MythicMobs.API.MythicMobsAPI; import net.elseland.xikage.MythicMobs.API.MythicMobsAPI;
import net.elseland.xikage.MythicMobs.API.Exceptions.InvalidMobTypeException; import net.elseland.xikage.MythicMobs.API.Exceptions.InvalidMobTypeException;
import net.elseland.xikage.MythicMobs.Mobs.MythicMob; import net.elseland.xikage.MythicMobs.Mobs.MythicMob;
public class MythicMobs2 implements MythicMobInterface { public class MythicMobs2 implements MythicMobInterface {
public MythicMobsAPI MMAPI = null; public MythicMobsAPI MMAPI = null;
private Jobs plugin; private Jobs plugin;
public MythicMobs2(Jobs plugin) { public MythicMobs2(Jobs plugin) {
this.plugin = plugin; this.plugin = plugin;
}
}
@Override
@Override public void registerListener() {
public void registerListener() { Bukkit.getServer().getPluginManager().registerEvents(new MythicMobs2Listener(plugin), plugin);
Bukkit.getServer().getPluginManager().registerEvents(new MythicMobs2Listener(plugin), plugin); }
}
@Override
@Override public boolean isMythicMob(LivingEntity lVictim) {
public boolean isMythicMob(LivingEntity lVictim) { if (MMAPI == null || lVictim == null)
if (MMAPI == null || lVictim == null) return false;
return false;
if (MMAPI.getMobAPI().isMythicMob(lVictim)) if (MMAPI.getMobAPI().isMythicMob(lVictim))
return true; return true;
return false;
} return false;
}
@Override
public boolean Check() { @Override
Plugin mm = Bukkit.getPluginManager().getPlugin("MythicMobs"); public boolean Check() {
if (mm == null) Plugin mm = Bukkit.getPluginManager().getPlugin("MythicMobs");
return false; if (mm == null)
return false;
try {
Class.forName("net.elseland.xikage.MythicMobs.API.Bukkit.Events.MythicMobDeathEvent"); try {
Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI"); Class.forName("net.elseland.xikage.MythicMobs.API.Bukkit.Events.MythicMobDeathEvent");
Class.forName("net.elseland.xikage.MythicMobs.Mobs.MythicMob"); Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI");
} catch (ClassNotFoundException e) { Class.forName("net.elseland.xikage.MythicMobs.Mobs.MythicMob");
// Disabling } catch (ClassNotFoundException e) {
Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support."); // Disabling
return false; Jobs.consoleMsg("&e[Jobs] &6MythicMobs was found - &cBut your version is outdated, please update for full support.");
} return false;
}
MMAPI = ((MythicMobs) mm).getAPI();
Jobs.consoleMsg("&e[Jobs] &6MythicMobs2 was found - Enabling capabilities."); MMAPI = ((MythicMobs) mm).getAPI();
return true; Jobs.consoleMsg("&e[Jobs] &6MythicMobs2 was found - Enabling capabilities.");
return true;
} }
@Override @Override
public String getDisplayName(String id) { public String getDisplayName(String id) {
try { try {
MythicMob mm = MMAPI.getMobAPI().getMythicMob(id); MythicMob mm = MMAPI.getMobAPI().getMythicMob(id);
if (mm != null) if (mm != null)
return mm.getDisplayName(); return mm.getDisplayName();
} catch (InvalidMobTypeException e) { } catch (InvalidMobTypeException e) {
return ""; return "";
} }
return "";
} return "";
} }
}

View File

@ -1,68 +1,73 @@
package com.gamingmesh.jobs.MythicMobs; package com.gamingmesh.jobs.hooks.MythicMobs;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.MMKillInfo; import com.gamingmesh.jobs.actions.MMKillInfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import net.elseland.xikage.MythicMobs.API.Bukkit.Events.MythicMobDeathEvent; import net.elseland.xikage.MythicMobs.API.Bukkit.Events.MythicMobDeathEvent;
import net.elseland.xikage.MythicMobs.Mobs.MythicMob; import net.elseland.xikage.MythicMobs.Mobs.MythicMob;
public class MythicMobs2Listener implements Listener { public class MythicMobs2Listener implements Listener {
private Jobs plugin; private Jobs plugin;
public MythicMobs2Listener(Jobs plugin) { public MythicMobs2Listener(Jobs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler @EventHandler
public void OnMythicMobDeath(MythicMobDeathEvent event) { public void OnMythicMobDeath(MythicMobDeathEvent event) {
//disabling plugin in world // make sure plugin is enabled
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) if (!plugin.isEnabled())
return; return;
// Entity that died must be living
if (!(event.getEntity() instanceof LivingEntity)) //disabling plugin in world
return; if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
MythicMob lVictim = event.getMobType(); return;
// make sure plugin is enabled // Entity that died must be living
if (!plugin.isEnabled()) if (!(event.getEntity() instanceof LivingEntity))
return; return;
Player pDamager = null; Player pDamager = null;
// Checking if killer is player // Checking if killer is player
Entity ent = null; Entity ent = null;
if (event.getKiller() instanceof Player) if (event.getKiller() instanceof Player)
pDamager = (Player) event.getKiller(); pDamager = (Player) event.getKiller();
// Checking if killer is tamed animal // Checking if killer is tamed animal
else if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { else if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
ent = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager(); ent = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager();
} else } else
return; return;
if (pDamager == null) if (pDamager == null)
return; return;
// check if in creative
if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !pDamager.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative()) // check if in creative
return; if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !pDamager.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative())
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return; if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return;
// pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager); // pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
if (jDamager == null) if (jDamager == null)
return; return;
Jobs.action(jDamager, new MMKillInfo(lVictim.getInternalName(), ActionType.MMKILL), ent); MythicMob lVictim = event.getMobType();
} if (lVictim == null) {
} return;
}
Jobs.action(jDamager, new MMKillInfo(lVictim.getInternalName(), ActionType.MMKILL), ent);
}
}

View File

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

View File

@ -1,69 +1,74 @@
package com.gamingmesh.jobs.MythicMobs; package com.gamingmesh.jobs.hooks.MythicMobs;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.MMKillInfo; import com.gamingmesh.jobs.actions.MMKillInfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import io.lumine.xikage.mythicmobs.mobs.MythicMob; import io.lumine.xikage.mythicmobs.mobs.MythicMob;
public class MythicMobs4Listener implements Listener { public class MythicMobs4Listener implements Listener {
private Jobs plugin; private Jobs plugin;
public MythicMobs4Listener(Jobs plugin) { public MythicMobs4Listener(Jobs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler @EventHandler
public void OnMythicMobDeath(MythicMobDeathEvent event) { public void OnMythicMobDeath(MythicMobDeathEvent event) {
//disabling plugin in world // make sure plugin is enabled
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) if (!plugin.isEnabled())
return; return;
// Entity that died must be living
if (!(event.getEntity() instanceof LivingEntity)) //disabling plugin in world
return; if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
MythicMob lVictim = event.getMobType(); return;
// make sure plugin is enabled // Entity that died must be living
if (!plugin.isEnabled()) if (!(event.getEntity() instanceof LivingEntity))
return; return;
Player pDamager = null; Player pDamager = null;
// Checking if killer is player // Checking if killer is player
Entity ent = null; Entity ent = null;
if (event.getKiller() instanceof Player) if (event.getKiller() instanceof Player)
pDamager = (Player) event.getKiller(); pDamager = (Player) event.getKiller();
// Checking if killer is tamed animal // Checking if killer is tamed animal
else if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { else if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
ent = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager(); ent = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager();
} else } else
return; return;
if (pDamager == null) if (pDamager == null)
return; return;
// check if in creative
if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !pDamager.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative()) // check if in creative
return; if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !pDamager.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative())
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return; if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return;
// pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager); // pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
if (jDamager == null) if (jDamager == null)
return; return;
Jobs.action(jDamager, new MMKillInfo(lVictim.getInternalName(), ActionType.MMKILL), ent); MythicMob lVictim = event.getMobType();
} if (lVictim == null) {
} return;
}
Jobs.action(jDamager, new MMKillInfo(lVictim.getInternalName(), ActionType.MMKILL), ent);
}
}

View File

@ -1,103 +1,104 @@
package com.gamingmesh.jobs.WorldGuard; package com.gamingmesh.jobs.hooks.WorldGuard;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.RestrictedArea; import com.gamingmesh.jobs.container.RestrictedArea;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionContainer;
public class WorldGuardManager { public class WorldGuardManager {
private WorldGuardPlugin wg; private WorldGuardPlugin wg;
private boolean useOld = false; private boolean useOld = false;
public WorldGuardManager() { public WorldGuardManager() {
Plugin pl = Bukkit.getPluginManager().getPlugin("WorldGuard"); Plugin pl = Bukkit.getPluginManager().getPlugin("WorldGuard");
if (pl != null && (pl instanceof WorldGuardPlugin)) { if (pl != null && (pl instanceof WorldGuardPlugin)) {
if (pl.getDescription().getVersion().equals("6.1")) { if (pl.getDescription().getVersion().equals("6.1")) {
wg = (WorldGuardPlugin) pl; wg = (WorldGuardPlugin) pl;
useOld = true; useOld = true;
} }
} }
} }
public List<RestrictedArea> getArea(Location loc) { public List<RestrictedArea> getArea(Location loc) {
try { try {
if (useOld) { if (useOld) {
ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc); ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc);
for (ProtectedRegion one : regions.getRegions()) { for (ProtectedRegion one : regions.getRegions()) {
if (!Jobs.getRestrictedAreaManager().isExist(one.getId())) if (!Jobs.getRestrictedAreaManager().isExist(one.getId()))
continue; continue;
return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId()); return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId());
} }
} else { } else {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld())); RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld()));
for (ProtectedRegion one : regions.getRegions().values()) { for (ProtectedRegion one : regions.getRegions().values()) {
if (!Jobs.getRestrictedAreaManager().isExist(one.getId())) if (!Jobs.getRestrictedAreaManager().isExist(one.getId()))
continue; continue;
return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId()); return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId());
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
} }
return new ArrayList<RestrictedArea>();
} return new ArrayList<RestrictedArea>();
}
public boolean inArea(Location loc, String name) {
if (useOld) { public boolean inArea(Location loc, String name) {
ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc); if (useOld) {
for (ProtectedRegion one : regions.getRegions()) { ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc);
if (!one.getId().equalsIgnoreCase(name)) for (ProtectedRegion one : regions.getRegions()) {
continue; if (!one.getId().equalsIgnoreCase(name))
if (!one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) continue;
continue; if (!one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))
return true; continue;
} return true;
} else { }
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); } else {
RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld())); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
for (ProtectedRegion one : regions.getRegions().values()) { RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld()));
if (!one.getId().equalsIgnoreCase(name)) for (ProtectedRegion one : regions.getRegions().values()) {
continue; if (!one.getId().equalsIgnoreCase(name))
if (!one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) continue;
continue; if (!one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))
return true; continue;
} return true;
} }
return false; }
} return false;
}
public String getNameByName(String name) {
for (World one : Bukkit.getWorlds()) { public String getNameByName(String name) {
Map<String, ProtectedRegion> regions = null; for (World one : Bukkit.getWorlds()) {
if (useOld) { Map<String, ProtectedRegion> regions = null;
regions = wg.getRegionContainer().get(one).getRegions(); if (useOld) {
} else { regions = wg.getRegionContainer().get(one).getRegions();
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); } else {
regions = container.get(BukkitAdapter.adapt(one)).getRegions(); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
} regions = container.get(BukkitAdapter.adapt(one)).getRegions();
for (Entry<String, ProtectedRegion> oneR : regions.entrySet()) { }
if (!oneR.getKey().equalsIgnoreCase(name)) for (Entry<String, ProtectedRegion> oneR : regions.entrySet()) {
continue; if (!oneR.getKey().equalsIgnoreCase(name))
return oneR.getKey(); continue;
} return oneR.getKey();
} }
return null; }
} return null;
}
}
}

View File

@ -26,6 +26,7 @@ import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.*; import com.gamingmesh.jobs.actions.*;
import com.gamingmesh.jobs.api.JobsChunkChangeEvent; import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
import com.gamingmesh.jobs.container.*; import com.gamingmesh.jobs.container.*;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling;
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -1123,8 +1124,8 @@ public class JobsPaymentListener implements Listener {
if (e.getDamager().hasMetadata("NPC")) if (e.getDamager().hasMetadata("NPC"))
return; return;
if (Jobs.getGCManager().MythicMobsEnabled && Jobs.getMythicManager() != null) { if (Jobs.getGCManager().MythicMobsEnabled && HookManager.getMythicManager() != null
if (Jobs.getMythicManager().isMythicMob(lVictim)) && HookManager.getMythicManager().isMythicMob(lVictim)) {
return; return;
} }
@ -1144,8 +1145,8 @@ public class JobsPaymentListener implements Listener {
if (e.getDamager() instanceof Player) { if (e.getDamager() instanceof Player) {
pDamager = (Player) e.getDamager(); pDamager = (Player) e.getDamager();
// Checking if killer is MyPet animal // Checking if killer is MyPet animal
} else if (Jobs.getMyPetManager() != null && Jobs.getMyPetManager().isMyPet(e.getDamager())) { } else if (HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager())) {
UUID uuid = Jobs.getMyPetManager().getOwnerOfPet(e.getDamager()); UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(e.getDamager());
if (uuid != null) if (uuid != null)
pDamager = Bukkit.getPlayer(uuid); pDamager = Bukkit.getPlayer(uuid);
// Checking if killer is tamed animal // Checking if killer is tamed animal