mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 16:19:53 +01:00
Cleaning up more combat checks.
This commit is contained in:
parent
1fc3c8fab2
commit
1b461ac96a
@ -96,6 +96,10 @@ public class EntityListener implements Listener {
|
|||||||
Entity attacker = event.getDamager();
|
Entity attacker = event.getDamager();
|
||||||
LivingEntity target = (LivingEntity) defender;
|
LivingEntity target = (LivingEntity) defender;
|
||||||
|
|
||||||
|
if (CombatUtils.isInvincible(target, event.getDamage())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (attacker instanceof Projectile) {
|
if (attacker instanceof Projectile) {
|
||||||
attacker = ((Projectile) attacker).getShooter();
|
attacker = ((Projectile) attacker).getShooter();
|
||||||
}
|
}
|
||||||
@ -107,10 +111,6 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CombatUtils.isInvincible(target, event.getDamage())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defender instanceof Player && attacker instanceof Player) {
|
if (defender instanceof Player && attacker instanceof Player) {
|
||||||
Player defendingPlayer = (Player) defender;
|
Player defendingPlayer = (Player) defender;
|
||||||
Player attackingPlayer = (Player) attacker;
|
Player attackingPlayer = (Player) attacker;
|
||||||
|
@ -51,8 +51,6 @@ public final class CombatUtils {
|
|||||||
* @param event The event to run the combat checks on.
|
* @param event The event to run the combat checks on.
|
||||||
*/
|
*/
|
||||||
public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
||||||
boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
|
|
||||||
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
|
|
||||||
Entity damager = event.getDamager();
|
Entity damager = event.getDamager();
|
||||||
|
|
||||||
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
|
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
|
||||||
@ -77,7 +75,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ItemUtils.isSword(heldItem)) {
|
if (ItemUtils.isSword(heldItem)) {
|
||||||
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.SWORDS.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.SWORDS.getPVEEnabled())) {
|
if (!shouldProcessSkill(target, SkillType.SWORDS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +98,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ItemUtils.isAxe(heldItem)) {
|
else if (ItemUtils.isAxe(heldItem)) {
|
||||||
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.AXES.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.AXES.getPVEEnabled())) {
|
if (!shouldProcessSkill(target, SkillType.AXES)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +132,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (heldItem.getType() == Material.AIR) {
|
else if (heldItem.getType() == Material.AIR) {
|
||||||
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.UNARMED.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.UNARMED.getPVEEnabled())) {
|
if (!shouldProcessSkill(target, SkillType.UNARMED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,12 +178,7 @@ public final class CombatUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetIsPlayer || targetIsTamedPet) {
|
if (!shouldProcessSkill(target, SkillType.TAMING)) {
|
||||||
if (!SkillType.TAMING.getPVPEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!SkillType.TAMING.getPVEEnabled()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,12 +213,7 @@ public final class CombatUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetIsPlayer || targetIsTamedPet) {
|
if (!shouldProcessSkill(target, SkillType.ARCHERY)) {
|
||||||
if (!SkillType.ARCHERY.getPVPEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!SkillType.ARCHERY.getPVEEnabled()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +224,7 @@ public final class CombatUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetIsPlayer) {
|
if (target instanceof Player) {
|
||||||
Player player = (Player) target;
|
Player player = (Player) target;
|
||||||
|
|
||||||
if (Misc.isNPCEntity(player)) {
|
if (Misc.isNPCEntity(player)) {
|
||||||
@ -593,4 +581,17 @@ public final class CombatUtils {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean shouldProcessSkill(LivingEntity target, SkillType skill) {
|
||||||
|
boolean process;
|
||||||
|
|
||||||
|
if (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) {
|
||||||
|
process = skill.getPVPEnabled();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
process = skill.getPVEEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
return process;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user