Reworking our invincibility checks to accomodate for vanilla mc behaviour

This commit is contained in:
nossr50 2012-03-02 10:18:23 -08:00
parent 2f5edb6329
commit 1c866a52e5
2 changed files with 19 additions and 3 deletions

View File

@ -40,6 +40,7 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
@ -79,7 +80,7 @@ public class mcEntityListener implements Listener
if(defender instanceof LivingEntity)
{
LivingEntity livingDefender = (LivingEntity)defender;
if(livingDefender.getNoDamageTicks() < livingDefender.getMaximumNoDamageTicks()/2.0F)
if(!m.isInvincible(livingDefender, event))
Combat.combatChecks(event, plugin);
}
}
@ -102,7 +103,7 @@ public class mcEntityListener implements Listener
if(PP.getGodMode())
event.setCancelled(true);
if(player.getNoDamageTicks() < player.getMaximumNoDamageTicks()/2.0F)
if(!m.isInvincible(player, event))
{
if(cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player))
Acrobatics.acrobaticsCheck(player, event);
@ -114,7 +115,7 @@ public class mcEntityListener implements Listener
break;
case WOLF:
Wolf wolf = (Wolf) entity;
if((wolf.getNoDamageTicks() < wolf.getMaximumNoDamageTicks()/2.0F) && wolf.isTamed() && wolf.getOwner() != null)
if((!m.isInvincible(wolf, event)) && wolf.isTamed() && wolf.getOwner() != null)
Taming.preventDamage(event, plugin);
break;
}

View File

@ -26,6 +26,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.*;
@ -60,6 +61,20 @@ public class m
return 0;
}
public static boolean isInvincible(LivingEntity le, EntityDamageEvent event)
{
//So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility
//So yeah, this is for that
if(le.getNoDamageTicks() < le.getMaximumNoDamageTicks()/2.0F)
{
if(event.getDamage() <= le.getLastDamage())
return true;
else
return false;
}
return true;
}
public static boolean isDouble(String string)
{
try