Check cancellation before continuing Takedown. Fixes PC-277

This commit is contained in:
samczsun 2016-05-19 17:33:20 -04:00 committed by Sam Sun
parent 72a2aa926f
commit 516ad5a640
2 changed files with 60 additions and 47 deletions

View File

@ -2,6 +2,7 @@ package mineplex.minecraft.game.classcombat.Skill.Brute;
import java.util.HashMap;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -34,21 +35,21 @@ public class Takedown extends SkillActive
{
private HashMap<LivingEntity, Long> _live = new HashMap<LivingEntity, Long>();
public Takedown(SkillFactory skills, String name, ClassType classType, SkillType skillType,
int cost, int levels,
int energy, int energyMod,
long recharge, long rechargeMod, boolean rechargeInform,
Material[] itemArray,
Action[] actionArray)
public Takedown(SkillFactory skills, String name, ClassType classType, SkillType skillType,
int cost, int levels,
int energy, int energyMod,
long recharge, long rechargeMod, boolean rechargeInform,
Material[] itemArray,
Action[] actionArray)
{
super(skills, name, classType, skillType,
cost, levels,
energy, energyMod,
recharge, rechargeMod, rechargeInform,
energy, energyMod,
recharge, rechargeMod, rechargeInform,
itemArray,
actionArray);
SetDesc(new String[]
SetDesc(new String[]
{
"Hurl yourself towards an opponent.",
"If you collide with them, you deal",
@ -58,7 +59,7 @@ public class Takedown extends SkillActive
}
@Override
public boolean CustomCheck(Player player, int level)
public boolean CustomCheck(Player player, int level)
{
if (player.getLocation().getBlock().getTypeId() == 8 || player.getLocation().getBlock().getTypeId() == 9)
{
@ -76,7 +77,7 @@ public class Takedown extends SkillActive
}
@Override
public void Skill(Player player, int level)
public void Skill(Player player, int level)
{
//Action
Vector vec = player.getLocation().getDirection();
@ -108,11 +109,11 @@ public class Takedown extends SkillActive
int level = getLevel(player);
if (level == 0) continue;
if (!UtilTime.elapsed(_live.get(player), 1000))
if (!UtilTime.elapsed(_live.get(player), 1000))
continue;
_live.remove(player);
}
_live.remove(player);
}
//Collide
for (Player player : GetUsers())
@ -167,25 +168,28 @@ public class Takedown extends SkillActive
int damage = 3 + (level);
//Damage Event
Factory.Damage().NewDamageEvent(damagee, damager, null,
CustomDamageEvent customDamageEvent = Factory.Damage().NewDamageEvent(damagee, damager, null,
DamageCause.CUSTOM, damage, false, true, false,
damager.getName(), GetName());
damager.getName(), GetName());
//Damage Event
Factory.Damage().NewDamageEvent(damager, damagee, null,
DamageCause.CUSTOM, damage/2, false, true, false,
damager.getName(), GetName() + " Recoil");
if (!customDamageEvent.IsCancelled())
{
//Damage Event
Factory.Damage().NewDamageEvent(damager, damagee, null,
DamageCause.CUSTOM, damage / 2, false, true, false,
damager.getName(), GetName() + " Recoil");
//Conditions
Factory.Condition().Factory().Slow(GetName(), damagee, damager, 2.5 + 0.5*level, 3, false, true, true, true);
Factory.Condition().Factory().Slow(GetName(), damager, damager, 2.5 + 0.5*level, 3, false, true, true, true);
//Conditions
Factory.Condition().Factory().Slow(GetName(), damagee, damager, 2.5 + 0.5 * level, 3, false, true, true, true);
Factory.Condition().Factory().Slow(GetName(), damager, damager, 2.5 + 0.5 * level, 3, false, true, true, true);
//Inform
UtilPlayer.message(damager, F.main(GetClassType().name(), "You hit " + F.name(UtilEnt.getName(damagee)) + " with " + F.skill(GetName(level)) + "."));
UtilPlayer.message(damagee, F.main(GetClassType().name(), F.name(damager.getName()) + " hit you with " + F.skill(GetName(level)) + "."));
//Inform
UtilPlayer.message(damager, F.main(GetClassType().name(), "You hit " + F.name(UtilEnt.getName(damagee)) + " with " + F.skill(GetName(level)) + "."));
UtilPlayer.message(damagee, F.main(GetClassType().name(), F.name(damager.getName()) + " hit you with " + F.skill(GetName(level)) + "."));
//Sound
damager.getWorld().playSound(damager.getLocation(), Sound.ZOMBIE_WOOD, 1f, 0.5f);
//Sound
damager.getWorld().playSound(damager.getLocation(), Sound.ZOMBIE_WOOD, 1f, 0.5f);
}
}
@EventHandler

View File

@ -171,37 +171,39 @@ public class DamageManager extends MiniPlugin
}
*/
public void NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj,
public CustomDamageEvent NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String source, String reason)
{
NewDamageEvent(damagee, damager, proj,
return NewDamageEvent(damagee, damager, proj,
cause, damage, knockback, ignoreRate, ignoreArmor,
source, reason, false);
}
public void NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj,
public CustomDamageEvent NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String source, String reason, boolean cancelled)
{
NewDamageEvent(damagee, damager, proj, null, cause, damage, knockback, ignoreRate, ignoreArmor, source, reason, cancelled);
return NewDamageEvent(damagee, damager, proj, null, cause, damage, knockback, ignoreRate, ignoreArmor, source, reason, cancelled);
}
public void NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj, Location knockbackOrigin,
public CustomDamageEvent NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj, Location knockbackOrigin,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String source, String reason)
{
NewDamageEvent(damagee, damager, proj, knockbackOrigin, cause, damage, knockback, ignoreRate, ignoreArmor, source,
return NewDamageEvent(damagee, damager, proj, knockbackOrigin, cause, damage, knockback, ignoreRate, ignoreArmor, source,
reason, false);
}
public void NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj, Location knockbackOrigin,
public CustomDamageEvent NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj, Location knockbackOrigin,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String source, String reason, boolean cancelled)
{
_plugin.getServer().getPluginManager().callEvent(new CustomDamageEvent(damagee, damager, proj, knockbackOrigin, cause,
damage, knockback, ignoreRate, ignoreArmor, source, reason, cancelled));
}
{
CustomDamageEvent customDamageEvent = new CustomDamageEvent(damagee, damager, proj, knockbackOrigin, cause,
damage, knockback, ignoreRate, ignoreArmor, source, reason, cancelled);
_plugin.getServer().getPluginManager().callEvent(customDamageEvent);
return customDamageEvent;
}
@EventHandler(priority = EventPriority.LOW)
public void CancelDamageEvent(CustomDamageEvent event)
@ -282,21 +284,21 @@ public class DamageManager extends MiniPlugin
if (e.equals(Enchantment.PROTECTION_ENVIRONMENTAL))
event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false);
else if (e.equals(Enchantment.PROTECTION_FIRE) &&
else if (e.equals(Enchantment.PROTECTION_FIRE) &&
event.GetCause() == DamageCause.FIRE &&
event.GetCause() == DamageCause.FIRE_TICK &&
event.GetCause() == DamageCause.LAVA)
event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false);
else if (e.equals(Enchantment.PROTECTION_FALL) &&
else if (e.equals(Enchantment.PROTECTION_FALL) &&
event.GetCause() == DamageCause.FALL)
event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false);
else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS) &&
else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS) &&
event.GetCause() == DamageCause.ENTITY_EXPLOSION)
event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false);
else if (e.equals(Enchantment.PROTECTION_PROJECTILE) &&
else if (e.equals(Enchantment.PROTECTION_PROJECTILE) &&
event.GetCause() == DamageCause.PROJECTILE)
event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false);
}
@ -322,7 +324,7 @@ public class DamageManager extends MiniPlugin
else if (e.equals(Enchantment.FIRE_ASPECT))
if (_conditionManager != null)
_conditionManager.Factory().Ignite("Ench Fire", event.GetDamageeEntity(), damager,
_conditionManager.Factory().Ignite("Ench Fire", event.GetDamageeEntity(), damager,
4 * (double)enchants.get(e), false, false);
}
}
@ -351,8 +353,15 @@ public class DamageManager extends MiniPlugin
}
}
}
//Debug
}
/*
* Should only be used to debug the damage event
* No modification of the event should take place
*/
@EventHandler (priority = EventPriority.MONITOR)
public void debugDamageEvent(CustomDamageEvent event)
{
DisplayDamage(event);
}