Java 类org.bukkit.event.world.WorldEvent 实例源码

项目:Cardinal    文件:CauseFilter.java   
@Override
public Boolean evaluate(Event event) {
  if (!(event instanceof EntityDamageEvent)) {
    switch (cause) {
      /* Actor Type */
      case WORLD:
        return event instanceof WorldEvent;
      case LIVING:
        return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof LivingEntity;
      case MOB:
        return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof Creature;
      case PLAYER:
        return event instanceof PlayerEvent;
      /* Block action */
      case PUNCH:
        return event instanceof BlockDamageEvent;
      case TRAMPLE:
        return event instanceof PlayerMoveEvent;
      case MINE:
        return event instanceof BlockBreakEvent;

      case EXPLOSION:
        return event instanceof EntityExplodeEvent;

      default:
        return null;
    }
  } else {
    /* Damage Type */
    EntityDamageEvent.DamageCause damageCause = ((EntityDamageEvent) event).getCause();
    switch (cause) {
      case MELEE:
        return damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK);
      case PROJECTILE:
        return damageCause.equals(EntityDamageEvent.DamageCause.PROJECTILE);
      case POTION:
        return damageCause.equals(EntityDamageEvent.DamageCause.MAGIC)
            || damageCause.equals(EntityDamageEvent.DamageCause.POISON)
            || damageCause.equals(EntityDamageEvent.DamageCause.WITHER)
            || damageCause.equals(EntityDamageEvent.DamageCause.DRAGON_BREATH);
      case EXPLOSION:
        return damageCause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
            || damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
      case COMBUSTION:
        return damageCause.equals(EntityDamageEvent.DamageCause.FIRE)
            || damageCause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)
            || damageCause.equals(EntityDamageEvent.DamageCause.MELTING)
            || damageCause.equals(EntityDamageEvent.DamageCause.LAVA)
            || damageCause.equals(EntityDamageEvent.DamageCause.HOT_FLOOR);
      case FALL:
        return damageCause.equals(EntityDamageEvent.DamageCause.FALL);
      case GRAVITY:
        return damageCause.equals(EntityDamageEvent.DamageCause.FALL)
            || damageCause.equals(EntityDamageEvent.DamageCause.VOID);
      case VOID:
        return damageCause.equals(EntityDamageEvent.DamageCause.VOID);
      case SQUASH:
        return damageCause.equals(EntityDamageEvent.DamageCause.FALLING_BLOCK);
      case SUFFOCATION:
        return damageCause.equals(EntityDamageEvent.DamageCause.SUFFOCATION);
      case DROWNING:
        return damageCause.equals(EntityDamageEvent.DamageCause.DROWNING);
      case STARVATION:
        return damageCause.equals(EntityDamageEvent.DamageCause.STARVATION);
      case LIGHTNING:
        return damageCause.equals(EntityDamageEvent.DamageCause.LIGHTNING);
      case CACTUS:
        return damageCause.equals(EntityDamageEvent.DamageCause.CONTACT);
      case THORNS:
        return damageCause.equals(EntityDamageEvent.DamageCause.THORNS);

      default:
        return null;
    }
  }
}
项目:CardinalPGM    文件:CauseFilter.java   
private Boolean evaluate(Event event) {
    if (!(event instanceof EntityDamageEvent)) {
        switch (cause) {
            case WORLD:
                return event instanceof WorldEvent;
            case LIVING:
                return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof LivingEntity;
            case MOB:
                return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof Creature;
            case PLAYER:
                return event instanceof PlayerEvent || event instanceof BlockPlaceEvent || event instanceof BlockBreakEvent;

            case PUNCH:
                return event instanceof PlayerInteractEvent
                        && ((PlayerInteractEvent) event).getAction().equals(Action.LEFT_CLICK_BLOCK);
            case TRAMPLE:
                return event instanceof PlayerMoveEvent;
            case MINE:
                return event instanceof BlockBreakEvent;

            case EXPLOSION:
                return event instanceof EntityExplodeEvent;
        }
    } else {
        EntityDamageEvent.DamageCause damageCause = ((EntityDamageEvent) event).getCause();
        switch (cause) {
            case MELEE:
                return damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK);
            case PROJECTILE:
                return damageCause.equals(EntityDamageEvent.DamageCause.PROJECTILE);
            case POTION:
                return damageCause.equals(EntityDamageEvent.DamageCause.MAGIC)
                        || damageCause.equals(EntityDamageEvent.DamageCause.POISON)
                        || damageCause.equals(EntityDamageEvent.DamageCause.WITHER)
                        || damageCause.equals(EntityDamageEvent.DamageCause.DRAGON_BREATH);
            case EXPLOSION:
                return damageCause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
                        || damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            case COMBUSTION:
                return damageCause.equals(EntityDamageEvent.DamageCause.FIRE)
                        || damageCause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)
                        || damageCause.equals(EntityDamageEvent.DamageCause.MELTING)
                        || damageCause.equals(EntityDamageEvent.DamageCause.LAVA)
                        || damageCause.equals(EntityDamageEvent.DamageCause.HOT_FLOOR);
            case FALL:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALL);
            case GRAVITY:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALL)
                        || damageCause.equals(EntityDamageEvent.DamageCause.VOID);
            case VOID:
                return damageCause.equals(EntityDamageEvent.DamageCause.VOID);
            case SQUASH:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALLING_BLOCK);
            case SUFFOCATION:
                return damageCause.equals(EntityDamageEvent.DamageCause.SUFFOCATION);
            case DROWNING:
                return damageCause.equals(EntityDamageEvent.DamageCause.DROWNING);
            case STARVATION:
                return damageCause.equals(EntityDamageEvent.DamageCause.STARVATION);
            case LIGHTNING:
                return damageCause.equals(EntityDamageEvent.DamageCause.LIGHTNING);
            case CACTUS:
                return damageCause.equals(EntityDamageEvent.DamageCause.CONTACT);
            case THORNS:
                return damageCause.equals(EntityDamageEvent.DamageCause.THORNS);
        }
    }
    return null;
}