Solved Pages

Discussion in 'Spigot Plugin Development' started by TheMasteredPanda, Jun 29, 2016.

  1. Uh, yeah. Says it all in the title really. How would I be able to do a page like the function like essentials has with their baltop list. I have viewed the code for the baltop command in essentials but didn't make much sense to me. Anything to give me a better understanding of what I need to do would be helpful <3<3

    Panda! :)
  2. First things first you need your lines so a list/hashmap will be needed. If you're using SQL even easier..

    final int linesPerPage = 5; You want to decide how many lines per page, this won't change.
    int pageNumber = 1; You also need to get the page number, obviously this will change.
    (Make sure to check pageNumber isn't less than 1).

    So now for a little maths.
    int highestEntry = pageNumber * linesPerPage;
    int lowestEntry = highestEntry - linesPerPage;

    These set the boundaries, and define the highest and lowest entries, we want to get them and all in between.

    Using SQL this can be done with the LIMIT keyword, setting the first argument to the lowest, and the second to the highest. Here's an example statement.
    SELECT * FROM `BungeeStaff` ORDER BY `Rank` LIMIT lowestEntry, highestEntry;
    Better safe than sorry, remember to use prepared statements!

    Or I guess you can get them from a list by iteration..
    List<String> myListOfShit = new LinkedList();
    player.sendMessage( "======== Page: " + pageNumber + " ========" );
    for( int i = lowestEntry; i < highestEntry + 1; i++ ) {

    player.sendMessage( myListOfShit.get( i ) );

    I'd rather not use the later, and essentially for SQL you'll be iterating over the results that it returns. Now there's a lot more fancy stuff you can do but that all seems good. :D There are some basic things I've missed out in this tutorial, that you should know.

    Why the *? Because there's 5 items per page, you want to get 5 times the pageNumber in order to get the highest entry of the requested page.
    As for the - 5, we get the highest entry of the page when we multiply it, so we get the lowest by subtracting 5.
    • Like Like x 1
    • Agree Agree x 1
  3. MiniDigger


    • Winner Winner x 3