Example #1
0
  public static void smartLogBlockBreak(Consumer consumer, String playerName, Block origin) {

    WorldConfig wcfg = getWorldConfig(origin.getWorld());
    if (wcfg == null) return;

    Block checkBlock = origin.getRelative(BlockFace.UP);
    if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getType())) {
      if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
        consumer.queueSignBreak(playerName, (Sign) checkBlock.getState());
      } else if (checkBlock.getType() == Material.IRON_DOOR
          || checkBlock.getType() == Material.WOOD_DOOR) {
        Block doorBlock = checkBlock;
        // If the doorBlock is the top half a door the player simply punched a door
        // this will be handled later.
        if (doorBlock.getData() != 8 && doorBlock.getData() != 9) {
          doorBlock = doorBlock.getRelative(BlockFace.UP);
          // Fall back check just in case the top half wasn't a door
          if (doorBlock.getType() == Material.IRON_DOOR
              || doorBlock.getType() == Material.WOOD_DOOR) {
            consumer.queueBlockBreak(playerName, doorBlock.getState());
          }
          consumer.queueBlockBreak(playerName, checkBlock.getState());
        }
      } else {
        consumer.queueBlockBreak(playerName, checkBlock.getState());
      }
    }

    List<Location> relativeBreakables =
        BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
    if (relativeBreakables.size() != 0) {
      for (Location location : relativeBreakables) {
        final Material blockType = location.getBlock().getType();
        final BlockState blockState = location.getBlock().getState();
        final MaterialData data = blockState.getData();
        switch (blockType) {
          case REDSTONE_TORCH_ON:
          case REDSTONE_TORCH_OFF:
            if (blockState
                .getBlock()
                .getRelative(((RedstoneTorch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TORCH:
            if (blockState
                .getBlock()
                .getRelative(((Torch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case COCOA:
            if (blockState
                .getBlock()
                .getRelative(((CocoaPlant) data).getAttachedFace().getOppositeFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LADDER:
            if (blockState
                .getBlock()
                .getRelative(((Ladder) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LEVER:
            if (blockState
                .getBlock()
                .getRelative(((Lever) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TRIPWIRE_HOOK:
            if (blockState
                .getBlock()
                .getRelative(((TripwireHook) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WOOD_BUTTON:
          case STONE_BUTTON:
            if (blockState
                .getBlock()
                .getRelative(((Button) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WALL_SIGN:
            if (blockState
                .getBlock()
                .getRelative(((org.bukkit.material.Sign) data).getAttachedFace())
                .equals(origin)) {
              if (wcfg.isLogging(Logging.SIGNTEXT)) {
                consumer.queueSignBreak(playerName, (Sign) blockState);
              } else {
                consumer.queueBlockBreak(playerName, blockState);
              }
            }
            break;
          case TRAP_DOOR:
            if (blockState
                .getBlock()
                .getRelative(((TrapDoor) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          default:
            consumer.queueBlockBreak(playerName, blockState);
            break;
        }
      }
    }

    // Special door check
    if (origin.getType() == Material.IRON_DOOR || origin.getType() == Material.WOOD_DOOR) {
      Block doorBlock = origin;

      // Up or down?
      if (origin.getData() != 8 && origin.getData() != 9) {
        doorBlock = doorBlock.getRelative(BlockFace.UP);
      } else {
        doorBlock = doorBlock.getRelative(BlockFace.DOWN);
      }

      if (doorBlock.getType() == Material.IRON_DOOR || doorBlock.getType() == Material.WOOD_DOOR) {
        consumer.queueBlockBreak(playerName, doorBlock.getState());
      }
    }

    // Do this down here so that the block is added after blocks sitting on it
    consumer.queueBlockBreak(playerName, origin.getState());
  }
Example #2
0
  public static void smartLogBlockBreak(Consumer consumer, String playerName, Block origin) {

    WorldConfig wcfg = getWorldConfig(origin.getWorld());
    if (wcfg == null) return;

    Block checkBlock = origin.getRelative(BlockFace.UP);
    if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getTypeId())) {
      if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
        consumer.queueSignBreak(playerName, (Sign) checkBlock.getState());
      } else {
        consumer.queueBlockBreak(playerName, checkBlock.getState());
      }
    }

    List<Location> relativeBreakables =
        BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
    if (relativeBreakables.size() != 0) {
      for (Location location : relativeBreakables) {
        final Material blockType = location.getBlock().getType();
        final BlockState blockState = location.getBlock().getState();
        final MaterialData data = blockState.getData();
        switch (blockType) {
          case REDSTONE_TORCH_ON:
          case REDSTONE_TORCH_OFF:
            if (blockState
                .getBlock()
                .getRelative(((RedstoneTorch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TORCH:
            if (blockState
                .getBlock()
                .getRelative(((Torch) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case COCOA:
            if (blockState
                .getBlock()
                .getRelative(((CocoaPlant) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LADDER:
            if (blockState
                .getBlock()
                .getRelative(((Ladder) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case LEVER:
            if (blockState
                .getBlock()
                .getRelative(((Lever) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case TRIPWIRE_HOOK:
            if (blockState
                .getBlock()
                .getRelative(((TripwireHook) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WOOD_BUTTON:
          case STONE_BUTTON:
            if (blockState
                .getBlock()
                .getRelative(((Button) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          case WALL_SIGN:
            if (blockState
                .getBlock()
                .getRelative(((org.bukkit.material.Sign) data).getAttachedFace())
                .equals(origin)) {
              if (wcfg.isLogging(Logging.SIGNTEXT)) {
                consumer.queueSignBreak(playerName, (Sign) blockState);
              } else {
                consumer.queueBlockBreak(playerName, blockState);
              }
            }
            break;
          case TRAP_DOOR:
            if (blockState
                .getBlock()
                .getRelative(((TrapDoor) data).getAttachedFace())
                .equals(origin)) {
              consumer.queueBlockBreak(playerName, blockState);
            }
            break;
          default:
            consumer.queueBlockBreak(playerName, blockState);
            break;
        }
      }
    }
    // Do this down here so that the block is added after blocks sitting on it
    consumer.queueBlockBreak(playerName, origin.getState());
  }