@EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    final Block block = event.getBlock();

    if (player.getWorld() != plugin.getIslandWorld()) return;
    if (player.hasPermission("islandworld.bypass.island")) return;

    if (block != null && !plugin.canBuildOnLocation(player, block.getLocation()))
      event.setCancelled(true);

    plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled());
  }
  @EventHandler
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled() || event.getPlayer() == null) {
      return;
    }

    Player player = event.getPlayer();
    String name = player.getName().toLowerCase();

    if (CitizensCommunicator.isNPC(player)) {
      return;
    }

    if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
      return;
    }

    if (!data.isAuthAvailable(name)) {
      if (!settings.isForcedRegistrationEnabled()) {
        return;
      }
    }

    event.setCancelled(true);
  }
Example #3
0
 @EventHandler
 public void onBlockBreak(BlockBreakEvent event) {
   String playerID = PlayerConverter.getID(event.getPlayer());
   // if the player has this objective, the event isn't canceled,
   // the block is correct and conditions are met
   if (containsPlayer(playerID)
       && !event.isCancelled()
       && event.getBlock().getType().equals(material)
       && (data < 0 || event.getBlock().getData() == data)
       && checkConditions(playerID)) {
     // remove the block from the total amount
     BlockData playerData = (BlockData) dataMap.get(playerID);
     playerData.remove();
     // complete the objective
     if (playerData.getAmount() == neededAmount) {
       completeObjective(playerID);
     } else if (notify) {
       // or maybe display a notification
       if (playerData.getAmount() > neededAmount) {
         Config.sendMessage(
             playerID,
             "blocks_to_break",
             new String[] {String.valueOf(playerData.getAmount() - neededAmount)});
       } else {
         Config.sendMessage(
             playerID,
             "blocks_to_place",
             new String[] {String.valueOf(neededAmount - playerData.getAmount())});
       }
     }
   }
 }
Example #4
0
  /** Removes chests when they're destroyed. */
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBreak(final BlockBreakEvent e) {
    if (e.isCancelled()) return;

    Block b = e.getBlock();
    Player p = e.getPlayer();

    // If the chest was a chest
    if (b.getType() == Material.CHEST) {
      Shop shop = plugin.getShopManager().getShop(b.getLocation());
      // If it was a shop
      if (shop != null) {
        if (plugin.lock) {
          // If they owned it or have bypass perms, they can destroy it
          if (!shop.getOwner().equalsIgnoreCase(p.getName())
              && !p.hasPermission("quickshop.other.destroy")) {
            e.setCancelled(true);
            p.sendMessage(MsgUtil.getMessage("no-permission"));
            return;
          }
        }

        // If they're either survival or the owner, they can break it
        if (p.getGameMode() == GameMode.CREATIVE
            && !p.getName().equalsIgnoreCase(shop.getOwner())) {
          e.setCancelled(true);
          p.sendMessage(MsgUtil.getMessage("no-creative-break"));
          return;
        }

        // Cancel their current menu... Doesnt cancel other's menu's.
        Info action = plugin.getShopManager().getActions().get(p.getName());
        if (action != null) {
          action.setAction(ShopAction.CANCELLED);
        }
        shop.delete();
        p.sendMessage(MsgUtil.getMessage("success-removed-shop"));
      }
    } else if (b.getType() == Material.WALL_SIGN) {
      Shop shop = getShopNextTo(e.getBlock().getLocation());
      if (shop != null) { // It is a shop sign we're dealing with.
        if (plugin.lock) {
          // If they're the shop owner or have bypass perms, they can destroy it.
          if (!shop.getOwner().equalsIgnoreCase(p.getName())
              && !e.getPlayer().hasPermission("quickshop.other.destroy")) {
            e.setCancelled(true);
            p.sendMessage(MsgUtil.getMessage("no-permission"));
            return;
          }
        }
        // If they're in creative and not the owner, don't let them (accidents happen)
        if (p.getGameMode() == GameMode.CREATIVE
            && !p.getName().equalsIgnoreCase(shop.getOwner())) {
          e.setCancelled(true);
          p.sendMessage(MsgUtil.getMessage("no-creative-break"));
          return;
        }
      }
    }
  }
Example #5
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockBreak(BlockBreakEvent event) {
   Player p = event.getPlayer();
   SFPlayer sfp = SFPlayer.getSFPlayer(p);
   if (!p.isOp()) {
     if (plugin.getConfig().getBoolean("features.spawnprotect", true)) {
       boolean inspawn = SFPlugin.isInSpawnProtect(event.getBlock().getLocation(), plugin);
       if (inspawn) {
         event.setCancelled(true);
         p.sendMessage(ChatColor.RED + sfp.translateString("general.inspawnprotect"));
       }
     }
     if (plugin.getConfig().getBoolean("features.bedrockprotect", true)) {
       if (p.getGameMode().equals(GameMode.CREATIVE)) {
         if (!event.isCancelled()) {
           if (event.getBlock().getY() < Double.valueOf(7)
               && event.getBlock().getType().equals(Material.BEDROCK)) {
             event.setCancelled(true);
             p.sendMessage(ChatColor.RED + sfp.translateString("general.bedrockblocked.removal"));
           }
         }
       }
     }
   }
 }
  @Override
  public void onBlockBreak(BlockBreakEvent inEvent) {
    Player thePlayer = inEvent.getPlayer();
    Block theBlock = inEvent.getBlock();

    if ((theBlock.getType() != Material.MOB_SPAWNER) || (inEvent.isCancelled())) return;

    if (creaturebox.permissions != null) {
      if (creaturebox.permissions.has(thePlayer, "creaturebox.dropspawner") == false) {
        return;
      }
    } else {
      if (thePlayer.isOp() == false) {
        return;
      }
    }

    World theWorld = theBlock.getWorld();
    Location theLocation =
        new Location(theWorld, theBlock.getX(), theBlock.getY(), theBlock.getZ(), 0, 0);
    CreatureSpawner theSpawner = (CreatureSpawner) theBlock.getState();
    int theCreatureIndex = plugin.creatureIndex(theSpawner.getCreatureTypeId());

    MaterialData theMaterial = new MaterialData(Material.MOB_SPAWNER, (byte) theCreatureIndex);
    ItemStack theItem = new ItemStack(Material.MOB_SPAWNER, 1, (short) theCreatureIndex);

    theWorld.dropItemNaturally(theLocation, theItem);

    thePlayer.sendMessage(
        String.format(
            ChatColor.YELLOW + "creaturebox: %s spawner dropped.", theSpawner.getCreatureTypeId()));
  }
 @EventHandler
 public void onBreak(BlockBreakEvent bbe) {
   if (!(bbe.isCancelled())) {
     Block block = bbe.getBlock();
     if (bbe.getPlayer() != null) {
       Player breaker = bbe.getPlayer();
       UUID uuid = breaker.getUniqueId();
       if (block.getState().getType().equals(Material.REDSTONE_ORE)
           || block.getType().equals(Material.REDSTONE_ORE)) {
         boolean notSilkTouch = true;
         if (breaker.getInventory().getItemInHand() != null) {
           ItemStack handItem = breaker.getInventory().getItemInHand();
           if (handItem.containsEnchantment(Enchantment.SILK_TOUCH)) {
             notSilkTouch = false;
           }
         }
         boolean lowLevel = true;
         int level = LevelManager.getLevel(breaker);
         if (level > 30) {
           lowLevel = false;
         }
         if (notSilkTouch && lowLevel) {
           int broke = LevelingXP_Breaking.get(uuid);
           broke += 1;
           if (broke >= (10 * LevelManager.getLevel(breaker))) {
             XPmanager.giveXP(breaker, 80);
           } else {
             LevelingXP_Breaking.set(uuid, broke);
           }
         }
       }
     }
   }
 }
Example #8
0
 @Override
 public void onBlockBreak(BlockBreakEvent event) {
   if (!event.isCancelled()) {
     if (BlockUtil.isSign(event.getBlock())) {
       SignActionDetector.removeDetector(event.getBlock());
     }
   }
 }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onBlockBreak(BlockBreakEvent e) {
    arbre = new ArrayList<Block>();

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

    final Block initialBloc = e.getBlock();

    if (initialBloc.getTypeId() != 17) {
      return;
    }

    final byte data = initialBloc.getData();
    Player p = e.getPlayer();

    boolean permEntire = Methods.hasPerm(p, "amatree.entiretree");
    boolean permReplant = Methods.hasPerm(p, "amatree.replanting");

    if (!permEntire && !permReplant) {
      return;
    }

    if (permEntire) {
      gessThree(initialBloc);
      for (Block b : arbre) {
        breakFoliage(b);
        b.breakNaturally();
      }
    }

    if (permReplant) {
      int id = initialBloc.getRelative(BlockFace.DOWN).getTypeId();

      if (id != 2 && id != 3) {
        return;
      }

      Core.plugin
          .getServer()
          .getScheduler()
          .scheduleSyncDelayedTask(
              Core.plugin,
              new Runnable() {

                public void run() {
                  if (initialBloc.getTypeId() == 0) {
                    initialBloc.setTypeId(6);
                    initialBloc.setData(data);
                  }
                }
              },
              1 * 20L);
    }
  }
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.isCancelled()) return;
   Block block = event.getBlock();
   if (block.getType() == Material.BOOKSHELF) {
     AdvShelf shelf = new AdvShelf(block.getLocation());
     shelf.delete();
     ItemStack stack = new ItemStack(block.getType(), 1);
     block.getWorld().dropItemNaturally(block.getLocation(), stack);
   }
 }
  @EventHandler
  public void playerBreakBlock(BlockBreakEvent e) {
    if (e.isCancelled()) return;
    if (!Minegusta.getServer().containsWorld(e.getPlayer().getWorld())) return;

    DwarfPower mine = DwarfPower.miningBoost(e);
    if (mine.isPlayer() && mine.isDwarf()) {
      mine.applyMiningBoost();
    }
  }
  /** Called when a block is broken. */
  @Override
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player);

    if (!wcfg.itemDurability) {
      ItemStack held = player.getItemInHand();
      if (held.getTypeId() > 0) {
        held.setDurability((short) -1);
        player.setItemInHand(held);
      }
    }

    if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) {
      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 BlockBreakBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  event.getBlock().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }

      if (!wcfg.getBlacklist()
          .check(
              new DestroyWithBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  player.getItemInHand().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock(), player)) {
      player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
      event.setCancelled(true);
      return;
    }
  }
Example #13
0
 @Override
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.isCancelled()) return;
   /* Call listeners */
   List<Listener> ll = event_handlers.get(event.getType());
   if (ll != null) {
     for (Listener l : ll) {
       ((BlockListener) l).onBlockBreak(event);
     }
   }
 }
 @Override
 public void onBlockBreak(BlockBreakEvent event) {
   if (!event.isCancelled()) {
     Block b = event.getBlock();
     if (b.getWorld().getEnvironment() == Environment.NETHER) {
       if (b.getTypeId() == NetherTrees.LEAF_TYPE
           && Math.random() * 100 < NetherTrees.SAPLING_DROP_CHANCE) {
         b.getWorld()
             .dropItemNaturally(b.getLocation(), new ItemStack(NetherTrees.SAPLING_TYPE, 1));
       }
     }
   }
 }
Example #15
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) return;
    Material material = event.getBlock().getType();
    if (!Conf.dropSelfOverrideMaterials.contains(material)) return;

    event.setCancelled(true);
    event
        .getBlock()
        .getWorld()
        .dropItemNaturally(event.getBlock().getLocation(), new ItemStack(material, 1));
    event.getBlock().setType(Material.AIR);
  }
Example #16
0
  @EventHandler(priority = EventPriority.LOWEST)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) return;

    xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());

    // if (!xAuthSettings.rstrBreak && !xPlayer.isRegistered())
    // return;

    if (xPlayer.isGuest()) {
      if (xPlayer.canNotify()) xPlayer.sendIllegalActionNotice();

      event.setCancelled(true);
    }
  }
Example #17
0
 @EventHandler
 public void onBlockBreak(BlockChangeEvent event) {
   if (event.isCancelled()) {
     return;
   }
   if (!(event.getCause() instanceof PlayerBreakCause)) {
     return;
   }
   PlayerCause pcause = (PlayerCause) event.getCause();
   BlockBreakEvent breakEvent =
       new BlockBreakEvent(
           BukkitUtil.fromBlock(event.getBlock()), new BridgePlayer(pcause.getSource()));
   Bukkit.getPluginManager().callEvent(breakEvent);
   event.setCancelled(breakEvent.isCancelled());
   // TODO finish onBlockBreak, exp drops and such!
 }
 @EventHandler(priority = EventPriority.NORMAL)
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.isCancelled()) return;
   PlayerEvent playerEvent;
   if (SignUtil.isSign(event.getBlock())) {
     playerEvent =
         new PlayerEvent(
             SignUtil.getSign(event.getBlock()),
             PlayerEvent.Action.BREAK,
             event.getPlayer(),
             event);
   } else {
     playerEvent =
         new PlayerEvent(event.getBlock(), PlayerEvent.Action.BREAK, event.getPlayer(), event);
   }
   mechanicsHandler.callPlayerEvent(playerEvent);
   event.setCancelled(playerEvent.isCancelled());
 }
 @EventHandler(priority = EventPriority.HIGH)
 public void playerBreakBlock(BlockBreakEvent event) {
   if (event.isCancelled()) {
     return;
   }
   Player player = event.getPlayer();
   if (vanishNoPacket.isPlayerInvisible(player)) {
     return;
   }
   Block block = event.getBlock();
   Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
   for (Snitch snitch : snitches) {
     if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
       if (checkProximity(snitch, player.getName())) {
         plugin.getJaLogger().logSnitchBlockBreak(snitch, player, block);
       }
     }
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!War.isWarTime()) {
      return;
    }

    coord.setFromLocation(event.getBlock().getLocation());
    CultureChunk cc = CivGlobal.getCultureChunk(coord);

    if (cc == null) {
      return;
    }

    if (!cc.getCiv().getDiplomacyManager().isAtWar()) {
      return;
    }

    if (event.getBlock().getType().equals(Material.DIRT)
        || event.getBlock().getType().equals(Material.GRASS)
        || event.getBlock().getType().equals(Material.SAND)
        || event.getBlock().getType().equals(Material.GRAVEL)
        || event.getBlock().getType().equals(Material.TORCH)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)
        || event.getBlock().getType().equals(Material.REDSTONE)
        || event.getBlock().getType().equals(Material.TNT)
        || event.getBlock().getType().equals(Material.LADDER)
        || event.getBlock().getType().equals(Material.VINE)
        || event.getBlock().getType().equals(Material.IRON_BLOCK)
        || event.getBlock().getType().equals(Material.GOLD_BLOCK)
        || event.getBlock().getType().equals(Material.DIAMOND_BLOCK)
        || event.getBlock().getType().equals(Material.EMERALD_BLOCK)
        || !event.getBlock().getType().isSolid()) {
      return;
    }

    CivMessage.sendError(event.getPlayer(), CivSettings.localize.localizedString("war_mustUseTNT"));
    event.setCancelled(true);
  }
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockBreakEvent(BlockBreakEvent event) {
   if (event.isCancelled()) {
     return;
   }
   if (event.getPlayer() == null) {
     return;
   }
   if (event.getPlayer().getEquipment().getItemInMainHand() == null) {
     return;
   }
   ItemStack iimh = event.getPlayer().getEquipment().getItemInMainHand();
   Tier t = iimh != null ? TierUtil.getTierFromItemStack(iimh) : null;
   if (t == null) {
     return;
   }
   if (t.isInfiniteDurability()) {
     iimh.setDurability((short) 0);
   }
 }
Example #22
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void breakSnitchBlock(BlockBreakEvent event) {
   if (event.isCancelled()) {
     return;
   }
   Block block = event.getBlock();
   if (!block.getType().equals(Material.JUKEBOX)) {
     return;
   }
   if (vanishNoPacket.isPlayerInvisible(event.getPlayer())) {
     return;
   }
   Location loc = block.getLocation();
   if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
     snitchManager.removeSnitch(snitchManager.getSnitch(loc.getWorld(), loc));
     plugin
         .getJaLogger()
         .logSnitchBreak(
             loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
   }
 }
Example #23
0
 @SuppressWarnings("unused")
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.isCancelled()) return;
   String worldName = event.getPlayer().getWorld().getName().toLowerCase();
   if ((worlds.contains("ALL") || worlds.contains(worldName))
       && (!worlds.contains("-" + worldName))) {
     Block dropBlock = event.getBlock();
     Location dropLoc = dropBlock.getLocation();
     Location loc = dropLoc.clone();
     LinkedList<ItemStack> drops = new LinkedList<ItemStack>();
     while (loc.getBlock().getType() == Material.LOG) {
       drops.addAll(loc.getBlock().getDrops());
       loc.getBlock().setType(Material.AIR);
       loc.setY(loc.getY() + 1);
     }
     if (drops.size() > 0) {
       for (ItemStack drop : drops) {
         dropBlock.getWorld().dropItemNaturally(dropLoc, drop);
       }
     }
   }
 }
 @EventHandler(priority = EventPriority.LOWEST)
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.getBlock().getType() == Material.MOB_SPAWNER && SpawnerAdjuster.useBlockListener) {
     if (event.getPlayer() != null) {
       if (!SpawnerAdjuster.permCheck(event.getPlayer(), "SpawnerAdjuster.BreakSpawners")) {
         event.setCancelled(true);
         return;
       }
     }
     if (SpawnerAdjuster.permCheck(event.getPlayer(), "SpawnerAdjuster.DropSpawners")
         && SpawnerAdjuster.allowDroppedSpawners) {
       if (!event.isCancelled()) {
         short asdf = 1;
         ItemStack spawnerstack =
             new ItemStack(event.getBlock().getType(), 1, asdf, event.getBlock().getData());
         event
             .getBlock()
             .getLocation()
             .getWorld()
             .dropItemNaturally(event.getBlock().getLocation(), spawnerstack);
       }
     }
   }
 }
  @Override
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) return;

    final Block block = event.getBlock();

    if (!stones.getSettingsManager().isFieldType(event.getBlock()) && !BlockUtil.isSign(block))
      return;

    // SignCheck
    if (BlockUtil.isSign(block)) {
      final Player player = event.getPlayer();
      final Block fieldBlock = BlockUtil.getFieldStone(block, false);
      // Check if fieldBlock has a known field
      if (fieldBlock == null) {
        return;
      }
      // Get ExpensiveField and dormant it.
      final ExpensiveField field = fieldManager.getExpensiveField(fieldBlock);
      fieldManager.setDormantField(field);
      player.sendMessage(ChatColor.YELLOW + "ExpensiveStones: Field is succesfully dormanted.");
      return;
    }
    // Check if block is known to ExpensiveField
    if (fieldManager.isKnown(block)) {
      final ExpensiveField field = fieldManager.getExpensiveField(block);

      field.setFieldON();
      if (!fieldManager.isInDormant(field.getField().getLocation())) field.setError();
      fieldManager.removeField(field);

      event
          .getPlayer()
          .sendMessage(ChatColor.YELLOW + "ExpensiveStones: Field is ready to be deleted.");
    }
  }
  @Override
  public void handle(GlowSession session, DiggingMessage message) {
    // Todo: Implement SHOOT_ARROW_FINISH_EATING
    // Todo: Implement SWAP_ITEM_IN_HAND
    GlowPlayer player = session.getPlayer();
    GlowWorld world = player.getWorld();
    GlowBlock block = world.getBlockAt(message.getX(), message.getY(), message.getZ());
    BlockFace face = BlockPlacementHandler.convertFace(message.getFace());
    ItemStack holding = player.getItemInHand();

    if (block.getRelative(face).getType() == Material.FIRE) {
      block.getRelative(face).breakNaturally();
      return; // returns to avoid breaking block in creative
    }

    boolean blockBroken = false;
    boolean revert = false;
    if (message.getState() == DiggingMessage.START_DIGGING || player.getDigging() == null) {
      // call interact event
      Action action = Action.LEFT_CLICK_BLOCK;
      Block eventBlock = block;
      if (player.getLocation().distanceSquared(block.getLocation()) > 36
          || block.getTypeId() == 0) {
        action = Action.LEFT_CLICK_AIR;
        eventBlock = null;
      }
      PlayerInteractEvent interactEvent =
          EventFactory.onPlayerInteract(player, action, eventBlock, face);

      // blocks don't get interacted with on left click, so ignore that
      // attempt to use item in hand, that is, dig up the block
      if (!BlockPlacementHandler.selectResult(interactEvent.useItemInHand(), true)) {
        // the event was cancelled, get out of here
        revert = true;
      } else if (player.getGameMode() != GameMode.SPECTATOR) {
        player.setDigging(null);
        // emit damage event - cancel by default if holding a sword
        boolean instaBreak =
            player.getGameMode() == GameMode.CREATIVE
                || block.getMaterialValues().getHardness() == 0;
        BlockDamageEvent damageEvent =
            new BlockDamageEvent(player, block, player.getItemInHand(), instaBreak);
        if (player.getGameMode() == GameMode.CREATIVE
            && holding != null
            && EnchantmentTarget.WEAPON.includes(holding.getType())) {
          damageEvent.setCancelled(true);
        }
        EventFactory.callEvent(damageEvent);

        // follow orders
        if (damageEvent.isCancelled()) {
          revert = true;
        } else {
          // in creative, break even if denied in the event, or the block
          // can never be broken (client does not send DONE_DIGGING).
          blockBroken = damageEvent.getInstaBreak();
          if (!blockBroken) {
            /// TODO: add a delay here based on hardness
            player.setDigging(block);
          }
        }
      }
    } else if (message.getState() == DiggingMessage.FINISH_DIGGING) {
      // shouldn't happen in creative mode

      // todo: verification against malicious clients
      blockBroken = block.equals(player.getDigging());

      if (blockBroken
          && holding.getType() != Material.AIR
          && holding.getDurability() != holding.getType().getMaxDurability()) {
        switch (block.getType()) {
          case GRASS:
          case DIRT:
          case SAND:
          case GRAVEL:
          case MYCEL:
          case SOUL_SAND:
            switch (holding.getType()) {
              case WOOD_SPADE:
              case STONE_SPADE:
              case IRON_SPADE:
              case GOLD_SPADE:
              case DIAMOND_SPADE:
                holding.setDurability((short) (holding.getDurability() + 1));
                break;
              default:
                holding.setDurability((short) (holding.getDurability() + 2));
                break;
            }
            break;
          case LOG:
          case LOG_2:
          case WOOD:
          case CHEST:
            switch (holding.getType()) {
              case WOOD_AXE:
              case STONE_AXE:
              case IRON_AXE:
              case GOLD_AXE:
              case DIAMOND_AXE:
                holding.setDurability((short) (holding.getDurability() + 1));
                break;
              default:
                holding.setDurability((short) (holding.getDurability() + 2));
                break;
            }
            break;
          case STONE:
          case COBBLESTONE:
            break;
          default:
            holding.setDurability((short) (holding.getDurability() + 2));
            break;
        }
        if (holding.getDurability() >= holding.getType().getMaxDurability()) {
          player.getInventory().remove(holding);
          // player.getItemInHand().setType(Material.AIR);
        }
      }
      player.setDigging(null);
    } else if (message.getState() == DiggingMessage.STATE_DROP_ITEM) {
      player.dropItemInHand(false);
      return;
    } else if (message.getState() == DiggingMessage.STATE_DROP_ITEMSTACK) {
      player.dropItemInHand(true);
      return;
    } else if (message.getState() == DiggingMessage.STATE_SHOT_ARROW_FINISH_EATING
        && player.getUsageItem() != null) {
      if (player.getUsageItem().equals(holding)) {
        ItemType type = ItemTable.instance().getItem(player.getUsageItem().getType());
        ((ItemTimedUsage) type).endUse(player, player.getUsageItem());
      } else {
        // todo: verification against malicious clients
        // todo: inform player their item is wrong
      }
      return;
    } else {
      return;
    }

    if (blockBroken && !revert) {
      // fire the block break event
      BlockBreakEvent breakEvent = EventFactory.callEvent(new BlockBreakEvent(block, player));
      if (breakEvent.isCancelled()) {
        BlockPlacementHandler.revert(player, block);
        return;
      }

      BlockType blockType = ItemTable.instance().getBlock(block.getType());
      if (blockType != null) {
        blockType.blockDestroy(player, block, face);
      }

      // destroy the block
      if (!block.isEmpty()
          && !block.isLiquid()
          && player.getGameMode() != GameMode.CREATIVE
          && world.getGameRuleMap().getBoolean("doTileDrops")) {
        for (ItemStack drop : block.getDrops(holding)) {
          GlowItem item = world.dropItemNaturally(block.getLocation(), drop);
          item.setPickupDelay(30);
          item.setBias(player);
        }
      }

      player.addExhaustion(0.025f);

      // STEP_SOUND actually is the block break particles
      world.playEffectExceptTo(
          block.getLocation(), Effect.STEP_SOUND, block.getTypeId(), 64, player);
      GlowBlockState state = block.getState();
      block.setType(Material.AIR);
      if (blockType != null) {
        blockType.afterDestroy(player, block, face, state);
      }
    } else if (revert) {
      // replace the block that wasn't really dug
      BlockPlacementHandler.revert(player, block);
    } else if (block.getType() != Material.AIR) {
      BlockType blockType = ItemTable.instance().getBlock(block.getType());
      blockType.leftClickBlock(player, block, holding);
    }
  }
 static boolean canBreak(Block block, Player player) {
   BlockBreakEvent bbe = new BlockBreakEvent(block, player);
   BetterChunkLoader.instance().getServer().getPluginManager().callEvent(bbe);
   return !bbe.isCancelled();
 }
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockBreak(BlockBreakEvent event) {
   if (!event.isCancelled()) {
     if (getBlocks().contains(event.getBlock())) {
       if (TeamUtils.getTeamByPlayer(event.getPlayer()) != team) {
         boolean touchMessage = false;
         if (!playersTouched.contains(event.getPlayer().getUniqueId())) {
           playersTouched.add(event.getPlayer().getUniqueId());
           TeamModule teamModule = TeamUtils.getTeamByPlayer(event.getPlayer());
           if (this.show && !this.completed) {
             TeamUtils.getTeamChannel(teamModule)
                 .sendLocalizedMessage(
                     new LocalizedChatMessage(
                         ChatConstant.UI_OBJECTIVE_DAMAGED_FOR,
                         teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE,
                         ChatColor.AQUA + name + ChatColor.WHITE,
                         teamModule.getCompleteName() + ChatColor.WHITE));
             for (Player player : Bukkit.getOnlinePlayers()) {
               if (TeamUtils.getTeamByPlayer(player) != null
                   && TeamUtils.getTeamByPlayer(player).isObserver()) {
                 player.sendMessage(
                     new LocalizedChatMessage(
                             ChatConstant.UI_OBJECTIVE_DAMAGED_FOR,
                             teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE,
                             ChatColor.AQUA + name + ChatColor.WHITE,
                             teamModule.getCompleteName() + ChatColor.WHITE)
                         .getMessage(player.getLocale()));
               }
               if (Settings.getSettingByName("Sounds") != null
                   && Settings.getSettingByName("Sounds")
                       .getValueByPlayer(player)
                       .getValue()
                       .equalsIgnoreCase("on")) {
                 player.playSound(player.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1);
               }
             }
           }
         }
         boolean oldState = this.isTouched();
         this.complete++;
         this.playersCompleted.put(
             event.getPlayer().getUniqueId(),
             (playersCompleted.containsKey(event.getPlayer().getUniqueId())
                 ? playersCompleted.get(event.getPlayer().getUniqueId()) + 1
                 : 1));
         if ((this.complete / size) >= this.required && !this.completed) {
           this.completed = true;
           event.setCancelled(false);
           if (this.show) {
             for (Player player : Bukkit.getOnlinePlayers())
               player.sendMessage(
                   ChatColor.GRAY
                       + new UnlocalizedChatMessage(
                               "{0}",
                               new LocalizedChatMessage(
                                   ChatConstant.UI_OBJECTIVE_DESTROYED,
                                   team.getCompleteName() + ChatColor.GRAY,
                                   ChatColor.AQUA + name + ChatColor.GRAY,
                                   getWhoDestroyed(player.getLocale())))
                           .getMessage(player.getLocale()));
           }
           FireworkUtil.spawnFirework(
               event.getPlayer().getLocation(),
               event.getPlayer().getWorld(),
               MiscUtils.convertChatColorToColor(team.getColor()));
           ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer());
           Bukkit.getServer().getPluginManager().callEvent(compEvent);
         } else if (!this.completed) {
           ObjectiveTouchEvent touchEvent =
               new ObjectiveTouchEvent(
                   this, event.getPlayer(), !oldState || showPercent, touchMessage);
           Bukkit.getServer().getPluginManager().callEvent(touchEvent);
         }
       } else {
         event.setCancelled(true);
         if (this.show)
           ChatUtils.sendWarningMessage(
               event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_OWN_OBJECTIVE));
       }
     }
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();

    // We just want the mob spawner events
    if (block.getType() != Material.MOB_SPAWNER) {
      return;
    }

    // We can't build here? Return then
    if (!su.canBuildHere(player, block.getLocation())) {
      return;
    }

    // Get the entityID from the spawner
    short entityID = su.getSpawnerEntityID(block);

    // Message the player about the broken spawner
    plugin.informPlayer(
        player,
        ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("spawnerBroken"))
            .replace("%creature%", su.getCreatureName(entityID)));

    // If using silk touch, drop spawner itself
    ItemStack tool = player.getItemInHand();
    // Check for SilkTocuh level
    boolean validToolAndSilkTouch = su.isValidItemAndHasSilkTouch(tool);

    // Get the world to drop in
    World world = player.getWorld();

    // Mob
    String mobName = su.getCreatureName(entityID).toLowerCase().replace(" ", "");

    // No drops in creative
    if (plugin.config.getBoolean("noDropsCreative", true)
        && player.getGameMode() == GameMode.CREATIVE) {
      return;
    }

    // Prevent XP farming/duping
    event.setExpToDrop(0);
    // assume not mined
    boolean mined = false;
    // drop XP only when destroyed and not silk picked
    boolean dropXPOnlyOnDestroy = plugin.config.getBoolean("dropXPOnlyOnDestroy", false);

    if (plugin.config.getBoolean("preventXPFarming", true) && block.hasMetadata("mined")) {
      mined = block.getMetadata("mined").get(0).asBoolean();
    }

    // Drop maybe some XP
    if (player.hasPermission("silkspawners.silkdrop." + mobName)
        || player.hasPermission("silkspawners.destroydrop." + mobName)) {
      int addXP = plugin.config.getInt("destroyDropXP");
      // If we have more than 0 XP, drop them
      // either we drop XP for destroy and silktouch or only when
      // destroyed and we have no silktouch
      if (!mined
          && addXP != 0
          && (!dropXPOnlyOnDestroy || !validToolAndSilkTouch && dropXPOnlyOnDestroy)) {
        event.setExpToDrop(addXP);
        // check if we should flag spawners
        if (plugin.config.getBoolean("preventXPFarming", true)) {
          block.setMetadata("mined", new FixedMetadataValue(plugin, true));
        }
      }
    }

    // random drop chance
    String mobID = su.eid2MobID.get(entityID);
    int randomNumber = rnd.nextInt(100);
    int dropChance = 0;

    // silk touch
    if (validToolAndSilkTouch && player.hasPermission("silkspawners.silkdrop." + mobName)) {
      // Calculate drop chance
      if (plugin.mobs.contains("creatures." + mobID + ".silkDropChance")) {
        dropChance = plugin.mobs.getInt("creatures." + mobID + ".silkDropChance", 100);
      } else {
        dropChance = plugin.config.getInt("silkDropChance", 100);
      }
      if (randomNumber < dropChance) {
        // Drop spawner
        world.dropItemNaturally(
            block.getLocation(),
            su.newSpawnerItem(
                entityID, su.getCustomSpawnerName(su.eid2MobID.get(entityID)), 1, false));
      }
      return;
    }

    // no silk touch
    if (player.hasPermission("silkspawners.destroydrop." + mobName)) {
      if (plugin.config.getBoolean("destroyDropEgg", false)) {
        // Calculate drop chance
        randomNumber = rnd.nextInt(100);
        if (plugin.mobs.contains("creatures." + mobID + ".eggDropChance")) {
          dropChance = plugin.mobs.getInt("creatures." + mobID + ".eggDropChance", 100);
        } else {
          dropChance = plugin.config.getInt("eggDropChance", 100);
        }
        if (randomNumber < dropChance) {
          // Drop egg
          world.dropItemNaturally(block.getLocation(), su.newEggItem(entityID));
        }
      }
      // Drop iron bars (or not)
      int dropBars = plugin.config.getInt("destroyDropBars", 0);
      if (dropBars != 0) {
        // Calculate drop chance
        randomNumber = rnd.nextInt(100);
        if (plugin.mobs.contains("creatures." + mobID + ".destroyDropChance")) {
          dropChance = plugin.mobs.getInt("creatures." + mobID + ".destroyDropChance", 100);
        } else {
          dropChance = plugin.config.getInt("destroyDropChance", 100);
        }
        if (randomNumber < dropChance) {
          world.dropItem(block.getLocation(), new ItemStack(Material.IRON_FENCE, dropBars));
        }
      }
    }
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled() || !OrebfuscatorConfig.getUpdateOnBreak()) return;

    OrebfuscatorThreadUpdate.Queue(event.getBlock());
  }