Properly block Scythe healing when hitting teammates
This commit is contained in:
parent
e5e0fd8eda
commit
a29cff2db1
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user