Fixed PC-707

Fixed arrows damaging the shooter.
Fixed all instances of arrows bouncing of targets.
This commit is contained in:
xGamingDudex 2016-06-27 22:38:37 +02:00 committed by cnr
parent 96d16be5b7
commit b8650d741d
2 changed files with 61 additions and 11 deletions

View File

@ -44,6 +44,7 @@ public class CustomDamageEvent extends Event implements Cancellable
private boolean _damageeBrute = false; private boolean _damageeBrute = false;
private boolean _damageToLevel = true; private boolean _damageToLevel = true;
private boolean _arrowShow = true; private boolean _arrowShow = true;
private boolean _projectileDamageSelf = false;
public CustomDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile projectile, Location knockbackOrigin, public CustomDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile projectile, Location knockbackOrigin,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor, String initialSource, DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor, String initialSource,
@ -169,6 +170,27 @@ public class CustomDamageEvent extends Event implements Cancellable
return _projectile; return _projectile;
} }
public boolean getProjectileDamageSelf()
{
return _projectileDamageSelf;
}
public void setProjectileDamageSelf(boolean projectileDamageSelf)
{
_projectileDamageSelf = projectileDamageSelf;
if(!projectileDamageSelf)
{
_cancellers.remove("Self Projectile Damage");
}
else
{
if(!_cancellers.contains("Self Projectile Damage"))
{
_cancellers.add("Self Projectile Damage");
}
}
}
public void setShowArrows(boolean show) public void setShowArrows(boolean show)
{ {
_arrowShow = show; _arrowShow = show;

View File

@ -8,7 +8,6 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.EntityEffect; import org.bukkit.EntityEffect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -241,10 +240,11 @@ public class DamageManager extends MiniPlugin
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGHEST) /**
public void removeDemArrowsCrazyMan(EntityDamageEvent event) * Removes arrows after hit, especially in cases where arrows may bounce, like if the damage was cancelled.
{ */
if (event.isCancelled()) @EventHandler(priority = EventPriority.MONITOR)
public void removeArrows(EntityDamageEvent event)
{ {
Projectile projectile = GetProjectile(event); Projectile projectile = GetProjectile(event);
@ -254,6 +254,20 @@ public class DamageManager extends MiniPlugin
projectile.remove(); projectile.remove();
} }
} }
/**
* Removes arrows after hit, especially in cases where arrows may bounce, like if the damage was cancelled.
*/
@EventHandler(priority = EventPriority.MONITOR)
public void removeArrows(CustomDamageEvent event)
{
Projectile projectile = event.GetProjectile();
if (projectile instanceof Arrow)
{
projectile.teleport(new Location(projectile.getWorld(), 0, 0, 0));
projectile.remove();
}
} }
/* /*
private boolean GoldPower(LivingEntity damager) private boolean GoldPower(LivingEntity damager)
@ -320,6 +334,12 @@ public class DamageManager extends MiniPlugin
return; return;
} }
if (event.GetProjectile() != null && event.GetDamageeEntity().equals(event.GetProjectile().getShooter()) && !event.getProjectileDamageSelf())
{
event.SetCancelled("Self Projectile Damage");
return;
}
if (event.GetDamageePlayer() != null) if (event.GetDamageePlayer() != null)
{ {
Player damagee = event.GetDamageePlayer(); Player damagee = event.GetDamageePlayer();
@ -440,6 +460,8 @@ public class DamageManager extends MiniPlugin
Player player = event.GetDamagerPlayer(true); Player player = event.GetDamagerPlayer(true);
if (player != null) if (player != null)
{ {
if (player.equals(event.GetDamageeEntity()) && !event.getProjectileDamageSelf()) return;
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 0.5f, 0.5f); player.playSound(player.getLocation(), Sound.ORB_PICKUP, 0.5f, 0.5f);
} }
} }
@ -464,6 +486,11 @@ public class DamageManager extends MiniPlugin
if (event.GetDamageeEntity().getHealth() <= 0) if (event.GetDamageeEntity().getHealth() <= 0)
return; return;
if (event.GetProjectile() != null &&
event.GetDamageeEntity().equals(event.GetProjectile().getShooter()) &&
!event.getProjectileDamageSelf())
return;
//Player Conditions //Player Conditions
if (event.GetDamageePlayer() != null) if (event.GetDamageePlayer() != null)
{ {
@ -524,6 +551,7 @@ public class DamageManager extends MiniPlugin
trajectory.multiply(0.6 * knockback); trajectory.multiply(0.6 * knockback);
trajectory.setY(Math.abs(trajectory.getY())); trajectory.setY(Math.abs(trajectory.getY()));
//Special handling for projectiles
if(event.GetProjectile() != null && event.getKnockbackOrigin() == null) if(event.GetProjectile() != null && event.getKnockbackOrigin() == null)
{ {
trajectory = event.GetProjectile().getVelocity(); trajectory = event.GetProjectile().getVelocity();