How to use ChatPaginator class?

Discussion in 'Plugin Development' started by Ar7ific1al, Jan 22, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Ar7ific1al

  2. Offline

    DREAM_MACHINE

    I haven't tested this but it doesn't seem to give me any errors:
    Code:
    ChatPaginator.paginate("String", 1)
    1 is the page number.
     
  3. Offline

    RawCode

    what about performing original research if unable to find any article?

    reading source code also helps.
     
  4. Offline

    CubieX

    I'm using this for my plugins:
    Code:
    private final int contentLinesPerPage = 10;
     
    /**
        * Sends the HELP as a paginated list of strings in chat to a player
        *
        * @param sender The sender to send the list to
        * @param list The list to paginate
        * @param page The page number to display.
        * @param countAll The count of all available entries 
        */
      public void paginateHelpList(CommandSender sender, ArrayList<String> list, int page, int countAll)
      {
          int totalPageCount = 1;
     
          if((list.size() % contentLinesPerPage) == 0)
          {
            if(list.size() > 0)
            {
                totalPageCount = list.size() / contentLinesPerPage;
            }     
          }
          else
          {
            totalPageCount = (list.size() / contentLinesPerPage) + 1;
          }
     
          if(page <= totalPageCount)
          {
            sender.sendMessage(ChatColor.WHITE + "----------------------------------------");
            sender.sendMessage(ChatColor.GREEN + getDescription().getName() + " Help - Page (" + String.valueOf(page) + " of " + totalPageCount + ")");     
            sender.sendMessage(ChatColor.WHITE + "----------------------------------------");
     
            if(list.isEmpty())
            {
                sender.sendMessage(ChatColor.WHITE + "No entries.");
            }
            else
            {
                int i = 0, k = 0;
                page--;
     
                for (String entry : list)
                {
                  k++;
                  if ((((page * contentLinesPerPage) + i + 1) == k) && (k != ((page * contentLinesPerPage) + contentLinesPerPage + 1)))
                  {
                      i++;
                      sender.sendMessage(entry);
                  }
                }
            }
     
            sender.sendMessage(ChatColor.WHITE + "----------------------------------------");
          }
          else
          {
            sender.sendMessage(ChatColor.YELLOW + "There are only " + ChatColor.WHITE + totalPageCount + ChatColor.YELLOW + " pages!");
          }
      }
    Found somewhere in the resource section of this forum, I believe.
    I modified it to fit my needs.

    All you have to do is creating a string list and add strings to it as much as you like.
    Then call this method to display "contentLinesPerPage" entries per page.
     
  5. Offline

    Ar7ific1al

    There's always someone to post a response like this. While I appreciate your time in coming to respond, it's pretty uncalled for. I've done plenty of looking into it myself. Please, if you don't have anything useful to contribute, keep it to yourself. :/


    I tried this, but it didn't seem to work. I don't remember in what way it didn't work, just remember something similar and Eclipse complaining about it. I stopped trying to figure it out so I could get on with the rest of what I was working on. But thanks for the suggestion, I'll try it again later and make sure I wasn't just doing it wrong. :p

    CubieX Thanks, I'll see what I can get out of this code snippet later. I don't need any of this right this moment, but I will later once I flesh out the majority of my plugin to a usable, presentable state. :)
     
  6. Offline

    fireblast709

    Ar7ific1al say the width and height of the page (which is based on the chat's width and height) are 10 x 5, then paginate would divide your text in so called pages, and display the nth page.

    Assume the String "This is a very very very long String which would wrap among pages". Then the pages would be
    Code:
    // Page 1
    This is a
    very very
    very long
    String
    which
     
    // Page 2
    would
    wrap
    with the additional assumption that it would wrap around full words. As you can see, no more than 10 characters horizontally and no more than 5 lines per page. Then you can either ask for page 1 or 2, which will return a ChatPage object containing the lines specified above
     
    Ar7ific1al likes this.
  7. Offline

    Ar7ific1al

    fireblast709
    Wonderful response, thanks a lot. :D
    I've been plagued so long with messages sent to players being horrendously long, and even more horrendously organized. I'll certainly be making use of this from now on in my plugins for help, command info, etc... I can't imagine why I couldn't find any information on how to use it via Google. :confused: Seems to me like everyone would want to be using this, and thus many newbies would be floating about asking about it. Thanks again for explaining that.
     
Thread Status:
Not open for further replies.

Share This Page