Java List help

Discussion in 'Plugin Development' started by wesleydeman, Nov 28, 2012.

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

    wesleydeman

    This is a function that i use for the command /wesquiz list (page)

    It shows 5 items per page.
    I tested it with 8 items i get the first 5 items if i do /wesquiz list 1
    If i do /wesquiz list 2 I just get the first 3 items from the the first 5 items.

    Also the maxPages does not work as there are 8 items there should be max 2 pages but it says 1?

    If I am not clear enough please ask!

    Code:
    private void listPage(CommandSender sender,int page)
        {
            int toIndex = page * 5;
            int fromIndex = toIndex - 5;
           
            List<String> currentQuizzes = quizzes.getStringList("QuizList");
            int totalQuizSigns = currentQuizzes.size();
            if(toIndex > totalQuizSigns)
            {
                toIndex = totalQuizSigns;
            }
            List<String> pageQuizzes = currentQuizzes.subList(fromIndex, toIndex);
           
            int maxPages = totalQuizSigns / 5;
           
            sender.sendMessage(ChatColor.BLUE + "[WesQuiz] "+ ChatColor.WHITE +"Quiz list (page "+ ChatColor.GOLD + Integer.toString(page) +"/" + Integer.toString(maxPages) + ChatColor.WHITE + ")" );
            for (int i = 0; i <= pageQuizzes.size() - 1; i++) {
              String quizName = (String)currentQuizzes.get(i);
              sender.sendMessage(ChatColor.WHITE + "- " + ChatColor.GOLD + quizName);
            }
        }
     
  2. Offline

    wesleydeman

  3. You always start at zero:
    for (int i = 0; i <= pageQuizzes.size() - 1; i++) {
     
  4. Offline

    wesleydeman

    It is supose to start at zero (because it creates a list from a list with 2 indexes)
    List<String> pageQuizzes = currentQuizzes.subList(fromIndex, toIndex);
     
  5. hmm, try printing out the value of page, toIndex and fromIndex
     
  6. Offline

    nisovin

    When you get the name, you're pulling it from currentQuizzes instead of pageQuizzes.
     
    wesleydeman likes this.
  7. Offline

    wesleydeman

    Ahh, lol I overlooked that :p
     
Thread Status:
Not open for further replies.

Share This Page