Пример #1
0
 /**
  * Detects if a Player can use a protectable Block or not
  *
  * @param player the Player involved
  * @param b the Block to be used
  * @return true if the Player can use the Block, false otherwise
  */
 public boolean canUse(final Player player, final Block b) {
   if (Perms.hasProtectionSignBypass(player)) {
     return true;
   }
   final Material blockType = b.getType();
   final String userId = PlayerIdsUtil.getId(player.getName());
   final List<Sign> signLines;
   if (blockType == Material.CHEST || blockType == Material.TRAPPED_CHEST) {
     signLines = SignUtil.getSignsForChest(b);
   } else if (getProtectedMaterials().contains(blockType)) {
     signLines = SignUtil.getSignsForBlock(b);
   } else {
     return true;
   }
   boolean protectedBySign = false;
   boolean explicitlyAllowed = false;
   for (final Sign sign : signLines) {
     if (sign.getLine(0).equals(PROTECTION)) {
       protectedBySign = true;
       if (ColorUtil.stripColorCodes(sign.getLine(1)).equals(userId)
           || ColorUtil.stripColorCodes(sign.getLine(2)).equals(userId)
           || ColorUtil.stripColorCodes(sign.getLine(3)).equals(userId)) {
         explicitlyAllowed = true;
         break;
       }
     }
   }
   return !protectedBySign || explicitlyAllowed;
 }