public PrisonPearlStorage(PrisonPearlPlugin plugin) {
   isNameLayer = Bukkit.getPluginManager().isPluginEnabled("NameLayer");
   isMysql = plugin.getPPConfig().getMysqlEnabled();
   PrisonPearlMysqlStorage = plugin.getMysqlStorage();
   transferedPlayers = new ArrayList<UUID>();
   this.plugin = plugin;
   pearls_byimprisoned = new HashMap<UUID, PrisonPearl>();
 }
  public String feedPearls(PrisonPearlManager pearlman) {
    String message = "";
    String log = "";
    ConcurrentHashMap<UUID, PrisonPearl> map =
        new ConcurrentHashMap<UUID, PrisonPearl>(pearls_byimprisoned);

    long inactive_seconds = this.getConfig().getLong("ignore_feed.seconds", 0);
    long inactive_hours = this.getConfig().getLong("ignore_feed.hours", 0);
    long inactive_days = this.getConfig().getLong("ignore_feed.days", 0);

    long feedDelay =
        getConfig()
            .getLong(
                "feed_delay",
                72000000); // if pearls have been fed in the last x millis it wont feed, defaults to
                           // 20 hours
    if (lastFeed >= System.currentTimeMillis() - feedDelay) {
      return "Pearls have already been fed, not gonna do it again just yet";
    } else {
      log += "\nSetting last feed time";
      lastFeed = System.currentTimeMillis();
    }

    int pearlsfed = 0;
    int coalfed = 0;
    int freedpearls = 0;
    for (PrisonPearl pp : map.values()) {

      final UUID prisonerId = pp.getImprisonedId();
      // final String prisoner = Bukkit.getPlayer(prisonerId).getName();
      Inventory inv[] = new Inventory[2];
      int retval = HolderStateToInventory(pp, inv);
      Location loc = pp.getLocation();
      if (loc instanceof FakeLocation) { // Not on server
        continue; // Other server will handle feeding
      }
      if (!upgradePearl(inv[0], pp) && inv[1] != null) {
        upgradePearl(inv[1], pp);
      }
      if (retval == HolderStateToInventory_BADCONTAINER) {
        String reason =
            prisonerId + " is being freed. Reason: Freed during coal feed, container was corrupt.";
        pearlman.freePearl(pp, reason);
        log += "\n freed:" + prisonerId + ",reason:" + "badcontainer";
        freedpearls++;
        continue;
      } else if (retval != HolderStateToInventory_SUCCESS) {
        continue;
      } else if (plugin.getWBManager().isMaxFeed(loc)) {
        String reason =
            prisonerId
                + " is being freed. Reason: Freed during coal feed, was outside max distance.";
        pearlman.freePearl(pp, reason);
        log += "\n freed:" + prisonerId + ",reason:" + "maxDistance";
        freedpearls++;
        continue;
      }
      if (inactive_seconds != 0 || inactive_hours != 0 || inactive_days != 0) {
        long inactive_time = pp.getImprisonedOfflinePlayer().getLastPlayed();
        long inactive_millis =
            inactive_seconds * 1000 + inactive_hours * 3600000 + inactive_days * 86400000;
        inactive_time += inactive_millis;
        if (inactive_time <= System.currentTimeMillis()) {
          // if player has not logged on in the set amount of time than ignore feeding
          log += "\nnot fed inactive: " + prisonerId;
          continue;
        }
      }
      message = message + "Pearl Id: " + prisonerId + " in a " + pp.getHolderBlockState().getType();
      ItemStack requirement = plugin.getPPConfig().getUpkeepResource();
      int requirementSize = requirement.getAmount();

      if (inv[0].containsAtLeast(requirement, requirementSize)) {
        int pearlnum;
        pearlnum = inv.length;
        message = message + "\n Chest contains enough purestrain coal.";
        inv[0].removeItem(requirement);
        pearlsfed++;
        coalfed += requirementSize;
        log += "\n fed:" + prisonerId + ",location:" + pp.describeLocation();
      } else if (inv[1] != null && inv[1].containsAtLeast(requirement, requirementSize)) {
        message = message + "\n Chest contains enough purestrain coal.";
        inv[1].removeItem(requirement);
        pearlsfed++;
        coalfed += requirementSize;
        log += "\n fed:" + prisonerId + ",location:" + pp.describeLocation();
      } else {
        message = message + "\n Chest does not contain enough purestrain coal.";
        String reason =
            prisonerId
                + " is being freed. Reason: Freed during coal feed, container did not have enough coal.";
        pearlman.freePearl(pp, reason);
        log +=
            "\n freed:" + prisonerId + ",reason:" + "nocoal" + ",location:" + pp.describeLocation();
        freedpearls++;
      }
    }
    message =
        message
            + "\n Feeding Complete. "
            + pearlsfed
            + " were fed "
            + coalfed
            + " coal. "
            + freedpearls
            + " players were freed.";
    return message;
  }
  public String feedPearls(PrisonPearlManager pearlman) {
    String message = "";
    String log = "";
    ConcurrentHashMap<Short, PrisonPearl> map =
        new ConcurrentHashMap<Short, PrisonPearl>(pearls_byid);

    long inactive_seconds = this.getConfig().getLong("ignore_feed.seconds", 0);
    long inactive_hours = this.getConfig().getLong("ignore_feed.hours", 0);
    long inactive_days = this.getConfig().getLong("ignore_feed.days", 0);

    int pearlsfed = 0;
    int coalfed = 0;
    int freedpearls = 0;
    for (PrisonPearl pp : map.values()) {
      Inventory inv[] = new Inventory[2];
      int retval = HolderStateToInventory(pp, inv);
      if (retval == HolderStateToInventory_BADCONTAINER) {
        pearlman.freePearl(pp);
        plugin
            .getLogger()
            .info(
                pp.getImprisonedName()
                    + " is being freed. Reason: Freed during coal feed, container was corrupt.");
        log += "\n freed:" + pp.getImprisonedName() + ",reason:" + "badcontainer";
        freedpearls++;
        continue;
      } else if (retval != HolderStateToInventory_SUCCESS) {
        continue;
      }
      if (!upgradePearl(inv[0], pp) && inv[1] != null) {
        upgradePearl(inv[1], pp);
      }
      if (inactive_seconds != 0 || inactive_hours != 0 || inactive_days != 0) {
        long inactive_time = pp.getImprisonedOfflinePlayer().getLastPlayed();
        long inactive_millis =
            inactive_seconds * 1000 + inactive_hours * 3600000 + inactive_days * 86400000;
        inactive_time += inactive_millis;
        if (inactive_time <= System.currentTimeMillis()) {
          // if player has not logged on in the set amount of time than ignore feeding
          log += "\nnot fed inactive: " + pp.getImprisonedName();
          continue;
        }
      }
      message =
          message
              + "Pearl #"
              + pp.getID()
              + ",Name: "
              + pp.getImprisonedName()
              + " in a "
              + pp.getHolderBlockState().getType();
      ItemStack requirement = plugin.getPPConfig().getUpkeepResource();
      int requirementSize = requirement.getAmount();

      if (inv[0].containsAtLeast(requirement, requirementSize)) {
        int pearlnum;
        pearlnum = inv.length;
        message = message + "\n Chest contains enough purestrain coal.";
        inv[0].removeItem(requirement);
        pearlsfed++;
        coalfed += requirementSize;
        log += "\n fed:" + pp.getImprisonedName() + ",location:" + pp.describeLocation();
      } else if (inv[1] != null && inv[1].containsAtLeast(requirement, requirementSize)) {
        message = message + "\n Chest contains enough purestrain coal.";
        inv[1].removeItem(requirement);
        pearlsfed++;
        coalfed += requirementSize;
        log += "\n fed:" + pp.getImprisonedName() + ",location:" + pp.describeLocation();
      } else {
        message = message + "\n Chest does not contain enough purestrain coal.";
        plugin
            .getLogger()
            .info(
                pp.getImprisonedName()
                    + " is being freed. Reason: Freed during coal feed, container did not have enough coal.");
        pearlman.freePearl(pp);
        log +=
            "\n freed:"
                + pp.getImprisonedName()
                + ",reason:"
                + "nocoal"
                + ",location:"
                + pp.describeLocation();
        freedpearls++;
      }
    }
    message =
        message
            + "\n Feeding Complete. "
            + pearlsfed
            + " were fed "
            + coalfed
            + " coal. "
            + freedpearls
            + " players were freed.";
    return message;
  }