Esempio n. 1
0
 /**
  * @param mat
  * @return count of how many tile entities of type mat are on the island at last count. Counts are
  *     done when a player places a tile entity.
  */
 public int getTileEntityCount(Material material) {
   int result = 0;
   for (int x = getMinProtectedX() / 16;
       x <= (getMinProtectedX() + getProtectionSize() - 1) / 16;
       x++) {
     for (int z = getMinProtectedZ() / 16;
         z <= (getMinProtectedZ() + getProtectionSize() - 1) / 16;
         z++) {
       for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) {
         // plugin.getLogger().info("DEBUG: tile entity: " + holder.getType());
         if (holder.getType() == material) {
           result++;
         } else if (material.equals(Material.REDSTONE_COMPARATOR_OFF)) {
           if (holder.getType().equals(Material.REDSTONE_COMPARATOR_ON)) {
             result++;
           }
         } else if (material.equals(Material.FURNACE)) {
           if (holder.getType().equals(Material.BURNING_FURNACE)) {
             result++;
           }
         } else if (material.toString().endsWith("BANNER")) {
           if (holder.getType().toString().endsWith("BANNER")) {
             result++;
           }
         } else if (material.equals(Material.WALL_SIGN) || material.equals(Material.SIGN_POST)) {
           if (holder.getType().equals(Material.WALL_SIGN)
               || holder.getType().equals(Material.SIGN_POST)) {
             result++;
           }
         }
       }
       for (Entity holder : world.getChunkAt(x, z).getEntities()) {
         // plugin.getLogger().info("DEBUG: entity: " + holder.getType());
         if (holder.getType().toString().equals(material.toString())) {
           result++;
         }
       }
     }
   }
   // Version 1.7.x counts differently to 1.8 (ugh)
   // In 1.7, the entity is present before it is cancelled and so gets counted.
   // Remove 1 from count if it is 1.7.x
   if (!plugin.isOnePointEight()) {
     result--;
   }
   return result;
 }