// when a painting is broken
  @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
  public void onPaintingBreak(PaintingBreakEvent event) {
    // FEATURE: claimed paintings are protected from breakage

    // only allow players to break paintings, not anything else (like water and explosions)
    if (!(event instanceof PaintingBreakByEntityEvent)) {
      event.setCancelled(true);
      return;
    }

    PaintingBreakByEntityEvent entityEvent = (PaintingBreakByEntityEvent) event;

    // who is removing it?
    Entity remover = entityEvent.getRemover();

    // again, making sure the breaker is a player
    if (!(remover instanceof Player)) {
      event.setCancelled(true);
      return;
    }

    // if the player doesn't have build permission, don't allow the breakage
    Player playerRemover = (Player) entityEvent.getRemover();
    String noBuildReason =
        GriefPrevention.instance.allowBuild(playerRemover, event.getPainting().getLocation());
    if (noBuildReason != null) {
      event.setCancelled(true);
      GriefPrevention.sendMessage(playerRemover, TextMode.Err, noBuildReason);
    }
  }
 @EventHandler(priority = EventPriority.NORMAL)
 public void onPaintingBreak(PaintingBreakEvent event) {
   if (event instanceof PaintingBreakByEntityEvent) {
     PaintingBreakByEntityEvent evt = (PaintingBreakByEntityEvent) event;
     if (evt.getRemover() instanceof Player) {
       Player player = (Player) evt.getRemover();
       if (Residence.isResAdminOn(player)) {
         return;
       }
       String pname = player.getName();
       FlagPermissions perms = Residence.getPermsByLoc(event.getPainting().getLocation());
       String world = event.getPainting().getWorld().getName();
       boolean hasplace =
           perms.playerHas(pname, world, "place", perms.playerHas(pname, world, "build", true));
       if (!hasplace) {
         event.setCancelled(true);
         player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission"));
       }
     }
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPaintingBreak(PaintingBreakEvent evt) {

    Player cause;

    if (!(evt instanceof PaintingBreakByEntityEvent)) {
      return;
    }

    PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) evt;
    if (!(event.getRemover() instanceof Player)) {
      return;
    }

    cause = (Player) event.getRemover();

    Location l = evt.getPainting().getLocation();
    World w = l.getWorld();
    Chunk c = w.getChunkAt(l);

    GlobalWorldSetting gws = GlobalRegionManager.getGlobalWorldSetting(w);

    Region r;

    ArrayList<Region> regionSet = new ArrayList<Region>();

    for (Region region : GlobalRegionManager.getRegions()) {
      for (Chunk chunk : region.getChunkGrid().getChunks()) {
        if (chunk.getWorld() == w) {
          if (areChunksEqual(chunk, c)) {
            if (!regionSet.contains(region)) {
              regionSet.add(region);
            }
          }
        }
      }
    }

    if (regionSet.isEmpty()) {
      if (gws != null) {
        if (gws.invert_protection) {
          evt.setCancelled(true);
          return;
        }
      }
      return;
    }

    ArrayList<Region> currentRegionSet = new ArrayList<Region>();

    for (Region reg : regionSet) {
      if (extReg.isInsideCuboid(
          l, reg.getL1().toBukkitLocation(), reg.getL2().toBukkitLocation())) {
        currentRegionSet.add(reg);
      }
    }

    if (currentRegionSet.isEmpty()) { // If player is in chunk range but not
      // inside region then cancel the
      // check.
      if (gws != null) {
        if (gws.invert_protection) {
          evt.setCancelled(true);
          return;
        }
      }
      return;
    }

    if (currentRegionSet.size() > 1) {
      r = srm.getCurrentRegion(null, currentRegionSet);
    } else {
      r = currentRegionSet.get(0);
    }

    if (r.is_protectionBreak()) {
      if (!r.canBuild(cause)) {
        LogRunner.addLogMessage(r, LogRunner.getPrefix(r) + (" Painting break was prevented."));
        r.sendBuildMessage(cause);
        evt.setCancelled(true);
        return;
      }
    }
  }