From a29cff2db1ab0df01ca50d8d09a157630a8e76d9 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Thu, 20 Jul 2017 16:52:49 -0400 Subject: [PATCH] Properly block Scythe healing when hitting teammates --- .../items/legendaries/DemonicScythe.java | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/DemonicScythe.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/DemonicScythe.java index a35cd627e..06d840826 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/DemonicScythe.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/DemonicScythe.java @@ -1,9 +1,13 @@ package mineplex.game.clans.items.legendaries; +import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import mineplex.core.common.util.C; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.ClansUtility; import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class DemonicScythe extends LegendaryItem @@ -21,14 +25,48 @@ public class DemonicScythe extends LegendaryItem C.cYellow + "Attack" + C.cWhite + " to use" + C.cGreen + " Leach Health", }, Material.RECORD_8); } + + private boolean isTeammate(Entity attacker, Entity defender) + { + if (attacker == null || defender == null) return false; + // Don't count attacks towards teammates + if (attacker instanceof Player && defender instanceof Player) + { + ClansUtility.ClanRelation relation = ClansManager.getInstance().getRelation((Player) attacker, (Player) defender); + if (relation == ClansUtility.ClanRelation.ALLY + || relation == ClansUtility.ClanRelation.SAFE + || relation == ClansUtility.ClanRelation.SELF) + { + return true; + } + } + return false; + } @Override public void onAttack(CustomDamageEvent event, Player wielder) { - if (!event.isCancelled()) + if (event.isCancelled()) { - event.AddMod("Scythe of the Fallen Lord", 8); - wielder.setHealth(Math.min(wielder.getMaxHealth(), wielder.getHealth() + 2)); + return; } + if (ClansManager.getInstance().isSafe(wielder)) + { + return; + } + if (event.GetDamageeEntity() instanceof Player && ClansManager.getInstance().isSafe(event.GetDamageePlayer())) + { + return; + } + if (wielder.getGameMode().equals(GameMode.CREATIVE)) + { + return; + } + if (isTeammate(wielder, event.GetDamageeEntity())) + { + return; + } + event.AddMod("Scythe of the Fallen Lord", 8); + wielder.setHealth(Math.min(wielder.getMaxHealth(), wielder.getHealth() + 2)); } } \ No newline at end of file