Don't apply attributes on friendlies. Fixes PC-369

This commit is contained in:
samczsun 2016-05-24 15:58:44 -04:00
parent 9af2c7e9f4
commit 2680c2b244
No known key found for this signature in database
GPG Key ID: B0AFDBD87206805D
6 changed files with 27 additions and 0 deletions

View File

@ -1,8 +1,12 @@
package mineplex.game.clans.items.attributes;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -127,4 +131,21 @@ public abstract class ItemAttribute
}
return s;
}
protected 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;
}
}

View File

@ -41,6 +41,7 @@ public class FlamingAttribute extends AttackAttribute
if(attacker instanceof Player && ClansManager.getInstance().isSafe((Player) attacker)) return;
if(defender instanceof Player && ClansManager.getInstance().isSafe((Player) defender)) return;
if(attacker instanceof Player && ((Player)attacker).getGameMode().equals(GameMode.CREATIVE)) return;
if (isTeammate(attacker, defender)) return;
defender.setFireTicks(_fireDuration);
}

View File

@ -54,6 +54,7 @@ public class FrostedAttribute extends ItemAttribute
if (victim != null)
{
if (isTeammate(event.GetDamagerPlayer(true), victim)) return;
victim.addPotionEffect(generateSlowEffect()); // Slow attacking player
}
}

View File

@ -42,6 +42,7 @@ public class HasteAttribute extends AttackAttribute
@Override
public void triggerAttack(Entity attacker, Entity defender)
{
if (isTeammate(attacker, defender)) return;
if (attacker instanceof Player)
{
Player player = (Player) attacker;

View File

@ -28,6 +28,7 @@ public class JaggedAttribute extends AttackAttribute {
@Override
public void triggerAttack(Entity attacker, Entity defender) {
if (isTeammate(attacker, defender)) return;
defender.setVelocity(new Vector(0, 0, 0));
if (defender instanceof LivingEntity)
((LivingEntity) defender).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 1, false, false));

View File

@ -37,6 +37,8 @@ public class VampiricAttribute extends ItemAttribute
public void onAttack(CustomDamageEvent event)
{
Player damager = event.GetDamagerPlayer(false);
if (isTeammate(damager, event.GetDamageePlayer())) return;
double damage = event.GetDamage();
double healAmount = damage * (_healPercent / 100d);