/*
   * Called when redstone changes.
   */
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockRedstoneChange(BlockRedstoneEvent event) {
    Block blockTo = event.getBlock();
    World world = blockTo.getWorld();

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.simulateSponge && wcfg.redstoneSponges) {
      int ox = blockTo.getX();
      int oy = blockTo.getY();
      int oz = blockTo.getZ();

      for (int cx = -1; cx <= 1; cx++) {
        for (int cy = -1; cy <= 1; cy++) {
          for (int cz = -1; cz <= 1; cz++) {
            Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
            if (sponge.getTypeId() == 19 && sponge.isBlockIndirectlyPowered()) {
              SpongeUtil.clearSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
            } else if (sponge.getTypeId() == 19 && !sponge.isBlockIndirectlyPowered()) {
              SpongeUtil.addSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
            }
          }
        }
      }

      return;
    }
  }
  /*
   * Called when a player places a block.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockPlace(BlockPlaceEvent event) {
    Block blockPlaced = event.getBlock();
    Player player = event.getPlayer();
    World world = blockPlaced.getWorld();

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.useRegions) {
      final Location location = blockPlaced.getLocation();
      if (!plugin.getGlobalRegionManager().canBuild(player, location)
          || !plugin.getGlobalRegionManager().canConstruct(player, location)) {
        player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockPlaceBlacklistEvent(
                  plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) {
      if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) {
        player.sendMessage(
            ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
      if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
        return;
      }

      int ox = blockPlaced.getX();
      int oy = blockPlaced.getY();
      int oz = blockPlaced.getZ();

      SpongeUtil.clearSpongeWater(plugin, world, ox, oy, oz);
    }
  }