ygimenez/Pagination-Utils

Paginator showing all results on first page

hexLuci opened this issue · 2 comments

Checklist

Make sure that you've checked all the items below.

  • Bot has the following permissions:
    • MESSAGE_ADD_REACTION
    • MESSAGE_EXT_EMOJI
    • MESSAGE_READ/WRITE
    • VIEW_CHANNEL
  • If using JDABuilder.createLight(), you added the following gateway intents:
    • GUILD_MESSAGES
    • GUILD_MESSAGE_REACTIONS
  • If using .setRemoveOnReact(true), you have the following permission:
    • MESSAGE_MANAGE
  • PaginationUtils is up-to-date.
  • You have activated the library as descripted in the README.

Library info

What libraries versions are you using.

  • JDA version 4.3.0_333
  • PaginationUtils version 3.0.8

I have a list of users (stored in a properties file) that have a level. I sort the users by their level and then send the sorted list back to the guild. I paginate the list, but it's still showing all of the users instead of X per page. I know I've probably just missed something, but for the life of me I can't figure out what.

Map<String, Integer> unsortedMap = new HashMap<String, Integer>();
for (String key : prop.stringPropertyNames()) {
String value = prop.getProperty(key);
unsortedMap.put(key, Integer.valueOf(value));
}

    Map<String, Integer> sortedMap = sortByValue(unsortedMap);

    EmbedBuilder eb = new EmbedBuilder();

    eb.setTitle("aaaaaaaaaaaa");

    ArrayList<Page> pages = new ArrayList<>();

    for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
        String key = entry.getKey();
        int value = entry.getValue();
        if (key.contains(".level")) {
            User users = ctx.getJDA().retrieveUserById(key.replace(".level", ""), true).complete();
            eb.addField(users.getName(), String.valueOf(value), false);
        }


    }

    for (int i = 0; i < 10; i++){
        pages.add(new InteractPage(eb.build()));
}

    channel.sendMessageEmbeds((MessageEmbed) pages.get(0).getContent()).queue(success -> {
        Pages.paginate(success, pages, true);
            });


}

private static Map<String, Integer> sortByValue(Map<String, Integer> unsortedMap) {
    List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(unsortedMap.entrySet());

    Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
        @Override
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return (o2.getValue().compareTo(o1.getValue()));
        }
    });

    Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
    for (Map.Entry<String, Integer> entry : list) {
        sortedMap.put(entry.getKey(), entry.getValue());
    }
    return sortedMap;

Attempted to rewrite the entire leaderboard system and it still displays all users on a single page. Reverted to original (displayed) leaderboard system. No idea what to do, so any help is appreciated.

Partitioned the for loop, was my own fault. Derp.