From 8ce06bcffcf4336de3dbe184b826abc4a57c3a74 Mon Sep 17 00:00:00 2001 From: Zrips Date: Thu, 11 May 2017 16:53:34 +0300 Subject: [PATCH] Compatibility with MyPet plugin to give out money when players pet kills mobs --- .classpath | 1 + com/gamingmesh/jobs/Jobs.java | 15 ++++- com/gamingmesh/jobs/MyPet/MyPetManager.java | 59 +++++++++++++++++++ com/gamingmesh/jobs/PlayerManager.java | 8 ++- com/gamingmesh/jobs/commands/list/browse.java | 1 - .../jobs/config/ExploreManager.java | 1 - .../jobs/config/LanguageManager.java | 1 - .../jobs/config/NameTranslatorManager.java | 1 - .../jobs/listeners/JobsPaymentListener.java | 13 ++-- 9 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 com/gamingmesh/jobs/MyPet/MyPetManager.java diff --git a/.classpath b/.classpath index d4165f42..f27d03c8 100644 --- a/.classpath +++ b/.classpath @@ -11,5 +11,6 @@ + diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index da88650f..a04b16bd 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -40,9 +40,9 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import com.gamingmesh.jobs.Gui.GuiManager; +import com.gamingmesh.jobs.MyPet.MyPetManager; import com.gamingmesh.jobs.MythicMobs.MythicMobInterface; import com.gamingmesh.jobs.MythicMobs.MythicMobs2; -import com.gamingmesh.jobs.MythicMobs.MythicMobs2Listener; import com.gamingmesh.jobs.MythicMobs.MythicMobs4; import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.api.JobsExpGainEvent; @@ -116,6 +116,7 @@ public class Jobs extends JavaPlugin { private static McMMOlistener McMMOlistener = null; private static MythicMobInterface MythicManager; + private static MyPetManager myPetManager; private static ConfigManager configManager; private static GeneralConfigManager GconfigManager; @@ -162,15 +163,21 @@ public class Jobs extends JavaPlugin { return PistonProtectionListener; } + public void setMyPetManager() { + myPetManager = new MyPetManager(); + } + + public static MyPetManager getMyPetManager() { + return myPetManager; + } + public void setMythicManager() { try { Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI"); - Debug.D("one"); MythicManager = new MythicMobs2(this); } catch (ClassNotFoundException e) { try { Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper"); - Debug.D("two"); MythicManager = new MythicMobs4(this); } catch (ClassNotFoundException ex) { @@ -746,6 +753,8 @@ public class Jobs extends JavaPlugin { getServer().getPluginManager().registerEvents(McMMOlistener, this); } + setMyPetManager(); + setMythicManager(); if (MythicManager.Check() && GconfigManager.MythicMobsEnabled) { MythicManager.registerListener(); diff --git a/com/gamingmesh/jobs/MyPet/MyPetManager.java b/com/gamingmesh/jobs/MyPet/MyPetManager.java new file mode 100644 index 00000000..c365ea6c --- /dev/null +++ b/com/gamingmesh/jobs/MyPet/MyPetManager.java @@ -0,0 +1,59 @@ +package com.gamingmesh.jobs.MyPet; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; + +import de.Keyle.MyPet.MyPetApi; +import de.Keyle.MyPet.api.entity.MyPet; +import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; +import de.Keyle.MyPet.api.repository.PlayerManager; + +public class MyPetManager { + + PlayerManager mp; + de.Keyle.MyPet.api.repository.MyPetManager mppm; + private boolean enabled = false; + + public MyPetManager() { + setup(); + } + + public boolean isMyPet(Object ent) { + if (!enabled || ent == null) + return false; + if (!(ent instanceof MyPetBukkitEntity)) + return false; + + return true; + } + + public UUID getOwnerOfPet(Object ent) { + if (!enabled || ent == null) + return null; + if (!(ent instanceof MyPetBukkitEntity)) + return null; + + MyPet myPet = ((MyPetBukkitEntity) ent).getMyPet(); + + try { + UUID uuid = myPet.getOwner().getPlayer().getUniqueId(); + return uuid; + } catch (Exception e) { + return null; + } + } + + public void setup() { + Plugin pl = Bukkit.getPluginManager().getPlugin("MyPet"); + if (pl == null) + return; + mp = MyPetApi.getPlayerManager(); + mppm = MyPetApi.getMyPetManager(); + enabled = true; + Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[Jobs] &6MyPet was found - Enabling capabilities.")); + } + +} diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 0d388ada..153ba456 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -757,7 +757,7 @@ public class PlayerManager { if (Jobs.getMcMMOlistener().mcMMOPresent) boost.add(BoostOf.McMMO, new BoostMultiplier().add(Jobs.getMcMMOlistener().getMultiplier(player.getPlayer()))); - if (ent != null && ent instanceof Tameable) { + if (ent != null && (ent instanceof Tameable)) { Tameable t = (Tameable) ent; if (t.isTamed() && t.getOwner() instanceof Player) { Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); @@ -766,6 +766,12 @@ public class PlayerManager { } } + if (ent != null && Jobs.getMyPetManager().isMyPet(ent)) { + Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); + if (amount != null) + boost.add(BoostOf.PetPay, new BoostMultiplier().add(amount)); + } + if (victim != null && victim.hasMetadata(this.getMobSpawnerMetadata())) { Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner"); if (amount != null) diff --git a/com/gamingmesh/jobs/commands/list/browse.java b/com/gamingmesh/jobs/commands/list/browse.java index e36d4964..05c4752c 100644 --- a/com/gamingmesh/jobs/commands/list/browse.java +++ b/com/gamingmesh/jobs/commands/list/browse.java @@ -11,7 +11,6 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.Perm; public class browse implements Cmd { diff --git a/com/gamingmesh/jobs/config/ExploreManager.java b/com/gamingmesh/jobs/config/ExploreManager.java index 57b557e0..7980c9bd 100644 --- a/com/gamingmesh/jobs/config/ExploreManager.java +++ b/com/gamingmesh/jobs/config/ExploreManager.java @@ -11,7 +11,6 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.ExploreChunk; import com.gamingmesh.jobs.container.ExploreRegion; import com.gamingmesh.jobs.container.ExploreRespond; -import com.gamingmesh.jobs.stuff.Debug; public class ExploreManager { diff --git a/com/gamingmesh/jobs/config/LanguageManager.java b/com/gamingmesh/jobs/config/LanguageManager.java index 0e056f5f..dd3c226d 100644 --- a/com/gamingmesh/jobs/config/LanguageManager.java +++ b/com/gamingmesh/jobs/config/LanguageManager.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.LocaleReader; diff --git a/com/gamingmesh/jobs/config/NameTranslatorManager.java b/com/gamingmesh/jobs/config/NameTranslatorManager.java index a3351a9c..ebc20e23 100644 --- a/com/gamingmesh/jobs/config/NameTranslatorManager.java +++ b/com/gamingmesh/jobs/config/NameTranslatorManager.java @@ -14,7 +14,6 @@ import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.LocaleReader; import com.gamingmesh.jobs.container.NameList; import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.Debug; public class NameTranslatorManager { diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 587043f3..1cc47b22 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -815,6 +816,9 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { + // make sure plugin is enabled + if (!this.plugin.isEnabled()) + return; //disabling plugin in world if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) return; @@ -846,15 +850,16 @@ public class JobsPaymentListener implements Listener { return; } - // make sure plugin is enabled - if (!this.plugin.isEnabled()) - return; - Player pDamager = null; // Checking if killer is player if (e.getDamager() instanceof Player) { pDamager = (Player) e.getDamager(); + // Checking if killer is MyPet animal + } else if (Jobs.getMyPetManager().isMyPet(e.getDamager())) { + UUID uuid = Jobs.getMyPetManager().getOwnerOfPet(e.getDamager()); + if (uuid != null) + pDamager = Bukkit.getPlayer(uuid); // Checking if killer is tamed animal } else if (e.getDamager() instanceof Tameable) { Tameable t = (Tameable) e.getDamager();