Java Code Examples for org.bukkit.entity.Entity#getFallDistance()

The following examples show how to use org.bukkit.entity.Entity#getFallDistance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FallTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable FallInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    FallState fall = getFall(victim);

    if(fall != null) {
        switch(damageType) {
            case VOID: fall.to = FallInfo.To.VOID; break;
            case FALL: fall.to = FallInfo.To.GROUND; break;
            case LAVA: fall.to = FallInfo.To.LAVA; break;

            case FIRE_TICK:
                if(fall.isInLava) {
                    fall.to = FallInfo.To.LAVA;
                } else {
                    return null;
                }
                break;

            default: return null;
        }

        return fall;
    } else {
        switch(damageType) {
            case FALL:
                return new GenericFallInfo(FallInfo.To.GROUND, victim.getLocation(), victim.getFallDistance());
            case VOID:
                return new GenericFallInfo(FallInfo.To.VOID, victim.getLocation(), victim.getFallDistance());
        }

        return null;
    }
}
 
Example 2
Source File: FallTracker.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public @Nullable FallInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  FallState fall = getFall(victim);

  if (fall != null) {
    switch (damageType) {
      case VOID:
        fall.to = FallInfo.To.VOID;
        break;
      case FALL:
        fall.to = FallInfo.To.GROUND;
        break;
      case LAVA:
        fall.to = FallInfo.To.LAVA;
        break;

      case FIRE_TICK:
        if (fall.isInLava) {
          fall.to = FallInfo.To.LAVA;
        } else {
          return null;
        }
        break;

      default:
        return null;
    }

    return fall;
  } else {
    switch (damageType) {
      case FALL:
        return new GenericFallInfo(
            FallInfo.To.GROUND, victim.getLocation(), victim.getFallDistance());
      case VOID:
        return new GenericFallInfo(
            FallInfo.To.VOID, victim.getLocation(), victim.getFallDistance());
    }

    return null;
  }
}