public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity attacker = event.getDamager();
    Entity defender = event.getEntity();

    if (defender instanceof Player) {
      Player player = (Player) defender;

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());

      if (cfg.isInvinciblePlayer(player.getName())) {
        event.setCancelled(true);
        return;
      }

      if (attacker != null && attacker instanceof Player) {
        if (wcfg.useRegions) {
          Vector pt = toVector(defender.getLocation());
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.PVP)) {
            ((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
            event.setCancelled(true);
            return;
          }
        }
      }

      if (attacker != null && attacker instanceof Monster) {
        if (attacker instanceof Creeper && wcfg.blockCreeperExplosions) {
          event.setCancelled(true);
          return;
        }

        if (wcfg.useRegions) {
          Vector pt = toVector(defender.getLocation());
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
          ApplicableRegionSet set = mgr.getApplicableRegions(pt);

          if (!set.isStateFlagAllowed(Flags.MOB_DAMAGE)) {
            event.setCancelled(true);
            return;
          }

          if (attacker instanceof Creeper) {
            if (!set.isStateFlagAllowed(Flags.CREEPER_EXPLOSION)) {
              event.setCancelled(true);
              return;
            }
          }
        }
      }
    }
  }
  @Override
  public void onEntityExplode(EntityExplodeEvent event) {

    if (event.isCancelled()) {
      return;
    }

    GlobalConfiguration cfg = plugin.getGlobalConfiguration();
    Location l = event.getLocation();
    WorldConfiguration wcfg = cfg.getWorldConfig(l.getWorld().getName());

    if (event.getEntity() instanceof LivingEntity) {

      if (wcfg.blockCreeperBlockDamage) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.blockCreeperExplosions) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.useRegions) {
        Vector pt = toVector(l);
        RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());

        if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.CREEPER_EXPLOSION)) {
          event.setCancelled(true);
          return;
        }
      }
    } else { // Shall assume that this is TNT
      if (wcfg.blockTNT) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.useRegions) {
        Vector pt = toVector(l);
        RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());

        if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.TNT)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
  @Override
  public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled()) {
      return;
    }

    GlobalConfiguration cfg = plugin.getGlobalConfiguration();
    WorldConfiguration wcfg = cfg.getWorldConfig(event.getEntity().getWorld().getName());

    // CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString());
    CreatureType creaType = event.getCreatureType();
    String creaName = "";
    Boolean cancelEvent = false;

    if (wcfg.blockCreatureSpawn.contains(creaType)) {
      cancelEvent = true;
    }

    if (wcfg.useRegions) {
      Vector pt = toVector(event.getEntity().getLocation());
      RegionManager mgr =
          plugin.getGlobalRegionManager().getRegionManager(event.getEntity().getWorld().getName());

      Boolean flagValue =
          mgr.getApplicableRegions(pt)
              .getStringFlag(Flags.DENY_SPAWN, true)
              .getValue("")
              .contains(creaType.getName());
      if (flagValue != null) {
        if (flagValue) {
          cancelEvent = true;
        } else {
          cancelEvent = false;
        }
      }
    }

    if (cancelEvent) {
      event.setCancelled(true);
      return;
    }
  }