How to to split Arraylist into a multiple page command

Discussion in 'Plugin Development' started by CodeVyxis, Mar 18, 2018.

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



    I am trying to implement a list command to my Review plugin getting the players and storing those into a list and sending the msg to the player using the command.
    Atm I am succesfully storing the names and the status into the messages.

    Now i do not want to clutter the screen with a ton of lines, I've looked up some code to store them in separate pages but I can't get it to work (i've tried hardcoding it using try/catch with a arrayoutofboundsexception catch.
    but that isn't working for me since i want it automized if the length of the array changes value)

    This is the code i am using to catch all files (seperate yml files for each player) and storing them into strings etc.

    if (args[0].equalsIgnoreCase("list") && p.hasPermission("reviews.default")) {
          File folder = new File(main.getDataFolder(), "/UserReviews");
          File[] files = folder.listFiles();
          for (int i = 0; i < args.length; i++) {
                if (files[i].isFile()) {
                         FileConfiguration cfg = YamlConfiguration.loadConfiguration(files[i]);
                         if (cfg.getInt("reviews." + files[i].getName().replaceAll(".yml", "") + ".complete") >= 0 || cfg.getInt("reviews." + files[i].getName().replaceAll(".yml", "")+ ".complete") < 4) {
                                msg(p, files[i].getName().replaceAll(".yml", "") + ": " + getStatus(cfg.getInt("reviews." + files[i].getName().replaceAll(".yml", "") + ".complete")));
                         } else {
                                msg(p, "no reviews to look at yet");
          msg(p, "&c============================================");
    Hopefully someone can help me out!
    Last edited: Mar 18, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @CodeVyxis Set a start variable, by default 0, if a page is given: start = pagenumber * amountperpage.
    Then loop for the amount of items on the page from start or till the index is above files.length
Thread Status:
Not open for further replies.

Share This Page