Beispiel #1
0
  /**
   * Construct a new DeleteQueue and add all entries into the queue Uses first List DataEntry's
   * DataId as a key
   *
   * @param entries The list of entries to be removed from the database
   */
  public DeleteQueue(List<DataEntry> entries) {

    this.entries = new LinkedBlockingQueue<Integer>(entries.size());

    for (DataEntry entry : entries) {
      this.entries.add(entry.getDataId());
    }

    this.key = entries.get(0).getDataId();
  }
  /**
   * Displays a page of data from the specified {@link PlayerSession} search results. Contains
   * appropriate methods for detecing errors e.g. no results
   *
   * @param session {@link PlayerSession}
   * @param page page number to display
   */
  public static void displayPage(PlayerSession session, int page) {
    // Check if any results are found
    List<DataEntry> results = session.getSearchResults();

    if (results == null || results.size() == 0) {
      Util.sendMessage(session.getSender(), "&cNo results found");
      return;
    }

    // Work out max pages. Return if page is higher than max pages
    int maxLines = 6;
    int maxPages = (int) Math.ceil((double) results.size() / 6);

    if (page > maxPages || page < 1) {
      return;
    }

    // Fix the line to properly fit the screen
    int len = String.valueOf(maxPages).length();

    if (len > 3) {
      len = (len - (len / 2)) + 1;
    }

    String l = "----------------------".substring(len);

    // Begin displaying page
    Util.sendMessage(
        session.getSender(),
        "&8" + l + " &7Page (&c" + page + "&7/&c" + maxPages + "&7) &8" + l + (len > 1 ? "-" : ""));

    for (int i = (page - 1) * maxLines; i < ((page - 1) * maxLines) + maxLines; i++) {
      if (i == results.size()) {
        break;
      }

      DataEntry entry = results.get(i);

      String time = Util.getTime(entry.getTimestamp());

      DisplayManager.sendLine(
          session.getSender(),
          "&cID:"
              + entry.getDataId()
              + " &7"
              + time
              + "&c"
              + entry.getPlayerName()
              + " &7"
              + entry.getType().getConfigName());
      DisplayManager.sendLine(
          session.getSender(),
          "&cLoc: &7"
              + entry.getWorld()
              + "-"
              + entry.getX()
              + ","
              + entry.getY()
              + ","
              + entry.getZ()
              + " &cData: &7"
              + entry.getStringData());
    }

    Util.sendMessage(
        session.getSender(), "&8-----------------------------------------------------");
    return;
  }