Paginated GUI

Discussion in 'Plugin Development' started by stijnb1234, May 19, 2018.

Thread Status:
Not open for further replies.
  1. Hello,

    I'm trying to make a paginated GUI with https://bukkit.org/threads/inventory-gui-pages.367576/.
    I've added the code, but when I try to run it, it gives an error: https://hastebin.com/tikizefune.bash

    When the player runs the command, they get added to the StoringMenuPageMap with the integer (page) 1. The plugin adds the items in the StoringMenuItems arraylist on startup.

    I'm using this code:
    Code:
    public static ArrayList<ItemStack> StoringMenuItems = new ArrayList<>();
    public static HashMap<Player, Integer> StoringMenuPageMap = new HashMap<>();
    
    int page = StoringMenuPageMap.get(p);
    int pagemin1 = page - 1;
    int pageplus1 = page + 1;
    int index = page * 45 - 45;
    int endIndex = index >= StoringMenuItems.size() ? StoringMenuItems.size() - 1 : index + 45;
    for (; index < endIndex; index++) {
        gui.setItem(index, StoringMenuItems.get(index));
    }
    How do I fix this error?

    Kind regards,

    Stijn
     
  2. Offline

    timtower Administrator Administrator Moderator

    @stijnb1234 Please use UUID's instead of player objects.
    Print the endIndex
     
  3. I will indeed arrange the UUID support.
    int page = 1, int index = 0, int endindex = 45; -> When I've 1 item in the
    StoringMenuItems arraylist.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @stijnb1234 You are trying to get an iten from StoringMenuItems at index 1, endIndex should always be snaller or the same as StoringMenuItems.size()
     
  5. Offline

    MightyOne

    @timtower Why is it so much better again to use UUIDs instead of Players? I dont see anything bad about it if you carefully remove references on specific events.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @MightyOne If they do it, most don't and use it out of convenience, just like public static.
     
  7. It's not fixed yet. There is a problem with
    Code:
    int endIndex = index >= StoringMenuItems.size() ? StoringMenuItems.size() - 1 : index + 45;
     
Thread Status:
Not open for further replies.

Share This Page