Inventory pages

Discussion in 'Plugin Development' started by thebmanswan541, Nov 18, 2014.

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

    thebmanswan541

    Hello, again
    I am trying to create multiple pages for all of the players online. I know how to list all of the players through items in a single inventory, but i do not know how to continue the list of online players In different pages. And, also navigating these pages through a next/back page item. Code examples would be nice, and thanks for the help as always!
     
  2. Offline

    Skionz

    Navigation would basically be checking when you press the forward item, closing the current inventory and opening another.
     
  3. Offline

    thebmanswan541

    Navigation wasn't a really big issue, I could have probably figured it out on my own. I just need help with pages
     
  4. Offline

    Skionz

    thebmanswan541 Get the amount of players online and divide it by however big an inventory can be to calculate how many inventories you should create. Then create a for loop for creating the inventory and putting the players inside of an inventory. Its going to require some math but it shouldn't be that hard to figure out.
     
  5. Offline

    thebmanswan541

    So something like this?
    Code:java
    1.  
    2. Player pl = e.getPlayer();
    3. ArrayList<String> players = new ArrayList<String>();
    4. for (Player p : Bukkt.getServer().getOnlinePlayers()) {
    5. if(p == pl) return;
    6. players.add(p.getName());
    7. }
    8. int page = 1;
    9. for (String s : players) {
    10. if (s.length() % 27 == 0) {
    11. Inventory inv = Bukkit.getServer().createInventory(null, 27, "Online Players - Page "+page);
    12. p.openInventory(inv);
    13. }
    14. //create items and stuff
    15. }
    16.  


    Probably not right, but need correction.
     
  6. Offline

    Skionz

    Bukkit.getOnlinePlayers().length returns how many players are online
     
  7. Offline

    thebmanswan541

    Oh alright, but is that right?
     
Thread Status:
Not open for further replies.

Share This Page