/** Loads all existing chests from the data folder. */
  private void load() {
    dataFolder.mkdirs();

    FilenameFilter filter =
        new FilenameFilter() {
          public boolean accept(File dir, String name) {
            return name.endsWith(YAML_CHEST_EXTENSION);
          }
        };

    for (File chestFile : dataFolder.listFiles(filter)) {
      String chestFileName = chestFile.getName();
      try {
        try {
          UUID playerUUID =
              UUID.fromString(
                  chestFileName.substring(0, chestFileName.length() - YAML_EXTENSION_LENGTH));
          chests.put(playerUUID, InventoryIO.loadFromYaml(chestFile));
        } catch (IllegalArgumentException e) {
          // Assume that the filename isn't a UUID, and is therefore an old player-name chest
          String playerName =
              chestFileName.substring(0, chestFileName.length() - YAML_EXTENSION_LENGTH);
          boolean flagPlayerNotFound = true;

          for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            // Search all the known players, load inventory, flag old file for deletion
            if (player.getName().equalsIgnoreCase(playerName)) {
              flagPlayerNotFound = false;
              chests.put(player.getUniqueId(), InventoryIO.loadFromYaml(chestFile));
              chestFile.deleteOnExit();
            }
          }

          if (flagPlayerNotFound) {
            logger.log(Level.WARNING, "Couldn't load chest file: " + chestFileName);
          }
        }
      } catch (Exception e) {
        logger.log(Level.WARNING, "Couldn't load chest file: " + chestFileName);
      }
    }

    logger.info("Loaded " + chests.size() + " chests");
  }