From 99ff0a34001fab17b084b570856f135438cc03f1 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 19 Dec 2023 13:18:52 +0200 Subject: [PATCH] Option to ignore bosses from damage amount check --- .../jobs/config/GeneralConfigManager.java | 5 ++- .../jobs/listeners/JobsPaymentListener.java | 45 +++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 30bd130d..434b55c0 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -105,7 +105,7 @@ public class GeneralConfigManager { EmptyServerAccountActionBar, ActionBarsMessageByDefault, aBarSilentMode, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, ShowActionNames, hideItemAttributes, DisableJoiningJobThroughGui, FireworkLevelupUse, UseRandom, UsePerPermissionForLeaving, - EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, useMaxPaymentCurve, blockOwnershipTakeOver, + EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, MonsterDamageIgnoreBosses, useMaxPaymentCurve, blockOwnershipTakeOver, hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers, BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse, DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled, @@ -910,6 +910,9 @@ public class GeneralConfigManager { "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.addComment("ExploitProtections.General.MonsterDamage.IgnoreBosses", "When enabled we will avoid checking damage done to ender dragon, wither and warden", + "This can help out in case you have server with custom damage sources which might not be registered and payouts might not be given out"); + MonsterDamageIgnoreBosses = c.get("ExploitProtections.General.MonsterDamage.IgnoreBosses", true); c.addComment("ExploitProtections.McMMO", "McMMO abilities"); c.addComment("ExploitProtections.McMMO.TreeFellerMultiplier", "Players will get part of money from cutting trees with treefeller ability enabled.", diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 1f3e5dd6..a6eb10b7 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -153,9 +153,9 @@ public final class JobsPaymentListener implements Listener { .build(); private final Cache entityLastDamager = CacheBuilder.newBuilder() - .expireAfterWrite(5, TimeUnit.MINUTES) - .weakKeys() - .build(); + .expireAfterWrite(5, TimeUnit.MINUTES) + .weakKeys() + .build(); private Cache cowMilkingTimer; public JobsPaymentListener(Jobs plugin) { @@ -1246,7 +1246,8 @@ public final class JobsPaymentListener implements Listener { //Gross but works entityLastDamager.put(ent.getUniqueId(), (Player) ((EntityDamageByEntityEvent) event).getDamager()); - if(!Jobs.getGCManager().MonsterDamageUse) return; + if (!Jobs.getGCManager().MonsterDamageUse) + return; double damage = event.getFinalDamage(); double s = ((Damageable) ent).getHealth(); @@ -1296,14 +1297,15 @@ public final class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { - if(!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) return; LivingEntity lVictim = event.getEntity(); Entity killer; - if(!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent)) { - if(entityLastDamager.getIfPresent(event.getEntity().getUniqueId()) == null) return; + if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent)) { + if (entityLastDamager.getIfPresent(event.getEntity().getUniqueId()) == null) + return; killer = entityLastDamager.getIfPresent(event.getEntity().getUniqueId()); } else { killer = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager(); @@ -1324,16 +1326,31 @@ public final class JobsPaymentListener implements Listener { } if (Jobs.getGCManager().MonsterDamageUse) { - UUID lVictimUUID = lVictim.getUniqueId(); - Double damage = damageDealtByPlayers.getIfPresent(lVictimUUID); - if (damage != null) { - double perc = (damage * 100D) / Util.getMaxHealth(lVictim); + boolean ignore = false; + if (Jobs.getGCManager().MonsterDamageIgnoreBosses) { + CMIEntityType etype = CMIEntityType.getByType(lVictim.getType()); + switch (etype) { + case ENDER_DRAGON: + case WITHER: + case WARDEN: + ignore = true; + break; + } + } - damageDealtByPlayers.invalidate(lVictimUUID); + if (!ignore) { + UUID lVictimUUID = lVictim.getUniqueId(); + Double damage = damageDealtByPlayers.getIfPresent(lVictimUUID); - if (perc < Jobs.getGCManager().MonsterDamagePercentage) - return; + if (damage != null) { + double perc = (damage * 100D) / Util.getMaxHealth(lVictim); + + damageDealtByPlayers.invalidate(lVictimUUID); + + if (perc < Jobs.getGCManager().MonsterDamagePercentage) + return; + } } }