From 2b14078860ec3841c118c9f3f3edecbbd869618e Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 11 Jan 2017 13:12:58 +0200 Subject: [PATCH] New option to prevent payment if player is not doing enough damage to monster --- com/gamingmesh/jobs/Jobs.java | 6 -- .../jobs/config/GeneralConfigManager.java | 8 ++ .../jobs/listeners/JobsPaymentListener.java | 73 +++++++++++++++++-- plugin.yml | 2 +- 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index 9c5a1b4f..b8dc34a2 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -71,7 +71,6 @@ import com.gamingmesh.jobs.dao.JobsDAO; 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.i18n.Language; import com.gamingmesh.jobs.listeners.JobsListener; import com.gamingmesh.jobs.listeners.JobsPaymentListener; @@ -79,7 +78,6 @@ import com.gamingmesh.jobs.listeners.McMMOlistener; import com.gamingmesh.jobs.listeners.MythicMobsListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.stuff.ActionBar; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.JobsClassLoader; import com.gamingmesh.jobs.stuff.Loging; import com.gamingmesh.jobs.stuff.TabComplete; @@ -131,10 +129,6 @@ public class Jobs extends JavaPlugin { public static BufferedPaymentThread paymentThread = null; private static DatabaseSaveThread saveTask = null; - public static HashMap paymentLimit = new HashMap(); - public static HashMap ExpLimit = new HashMap(); - public static HashMap PointLimit = new HashMap(); - public static HashMap FastPayment = new HashMap(); private static NMS nms; diff --git a/com/gamingmesh/jobs/config/GeneralConfigManager.java b/com/gamingmesh/jobs/config/GeneralConfigManager.java index 8042de72..339f82d3 100644 --- a/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -103,6 +103,9 @@ public class GeneralConfigManager { public double MinimumOveralPaymentLimit; public double MinimumOveralPointsLimit; + public boolean MonsterDamageUse = false; + public double MonsterDamagePercentage; + public HashMap Boost = new HashMap(); public double DynamicPaymentMaxPenalty; @@ -717,6 +720,11 @@ public class GeneralConfigManager { PetPay = c.get("ExploitProtections.General.PetPay", 0.1) - 1D; VipPetPay = c.get("ExploitProtections.General.VipPetPay", 1.0) - 1D; + c.getW().addComment("ExploitProtections.General.MonsterDamage.Use", "This section controls how much damage player should do to monster for player to get paid", + "This prevents from killing monsters in one hit when they suffer in example fall damage"); + MonsterDamageUse = c.get("ExploitProtections.General.MonsterDamage.Use", false); + MonsterDamagePercentage = c.get("ExploitProtections.General.MonsterDamage.Percentage", 60); + c.getW().addComment("ExploitProtections.McMMO", "McMMO abilities"); c.getW().addComment("ExploitProtections.McMMO.TreeFellerMultiplier", "Players will get part of money from cutting trees with treefeller ability enabled.", "0.2 means 20% of original price"); diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index e8e92545..993e686a 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -29,6 +29,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Damageable; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.HumanEntity; @@ -46,6 +47,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; @@ -67,6 +69,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; +import org.bukkit.projectiles.ProjectileSource; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.actions.BlockActionInfo; @@ -84,17 +87,17 @@ import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.Debug; import com.google.common.base.Objects; public class JobsPaymentListener implements Listener { private Jobs plugin; private final String furnaceOwnerMetadata = "jobsFurnaceOwner"; - public final static String brewingOwnerMetadata = "jobsBrewingOwner"; - public static final String BlockMetadata = "BlockOwner"; - public static final String PlacedBlockMetadata = "JobsBlockOwner"; + private final String brewingOwnerMetadata = "jobsBrewingOwner"; + private final String BlockMetadata = "BlockOwner"; public static final String VegyMetadata = "VegyTimer"; - public static final String GlobalMetadata = "GlobalTimer"; - public static final String CowMetadata = "CowTimer"; + private final String CowMetadata = "CowTimer"; + private final String entityDamageByPlayer = "JobsEntityDamagePlayer"; public JobsPaymentListener(Jobs plugin) { this.plugin = plugin; @@ -753,6 +756,59 @@ public class JobsPaymentListener implements Listener { Jobs.action(jPlayer, new ItemActionInfo(event.getResult(), ActionType.SMELT)); } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEntityDamageByPlayer(EntityDamageEvent event) { + //disabling plugin in world + if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + return; + + if (!Jobs.getGCManager().MonsterDamageUse) + return; + + Entity ent = event.getEntity(); + if (ent instanceof Player) + return; + if (!(event instanceof EntityDamageByEntityEvent)) + return; + EntityDamageByEntityEvent attackevent = (EntityDamageByEntityEvent) event; + Entity damager = attackevent.getDamager(); + if (!(damager instanceof Player)) + return; + double damage = event.getFinalDamage(); + double s = ((Damageable) ent).getHealth(); + if (damage > s) + damage = s; + if (ent.hasMetadata(entityDamageByPlayer)) + damage += ent.getMetadata(entityDamageByPlayer).get(0).asDouble(); + ent.setMetadata(entityDamageByPlayer, new FixedMetadataValue(this.plugin, damage)); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEntityDamageByProjectile(EntityDamageByEntityEvent event) { + //disabling plugin in world + if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + return; + Entity ent = event.getEntity(); + Entity damager = event.getDamager(); + if (!(damager instanceof Projectile)) + return; + Projectile projectile = (Projectile) damager; + ProjectileSource shooter = projectile.getShooter(); + double damage = event.getFinalDamage(); + + double s = ((Damageable) ent).getHealth(); + + if (damage > s) + damage = s; + + if (shooter instanceof Player) { + if (ent.hasMetadata(entityDamageByPlayer)) + damage += ent.getMetadata(entityDamageByPlayer).get(0).asDouble(); + ent.setMetadata(entityDamageByPlayer, new FixedMetadataValue(this.plugin, damage)); + } + + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { //disabling plugin in world @@ -828,6 +884,13 @@ public class JobsPaymentListener implements Listener { return; } + if (Jobs.getGCManager().MonsterDamageUse && lVictim.hasMetadata(entityDamageByPlayer)) { + double damage = lVictim.getMetadata(entityDamageByPlayer).get(0).asDouble(); + double perc = (damage * 100D) / lVictim.getMaxHealth(); + if (perc < Jobs.getGCManager().MonsterDamagePercentage) + return; + } + Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), e.getDamager(), lVictim); // Payment for killing player with particular job, except NPC's diff --git a/plugin.yml b/plugin.yml index b34c202c..c21eb34a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.Jobs -version: 3.7.2 +version: 3.7.3 author: phrstbrn softdepend: [Vault, iConomy, MythicMobs, McMMO] commands: