GUI Selecting Players

Discussion in 'Plugin Development' started by girardcome, Jul 20, 2014.

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

    girardcome

    Hey there! I'm here because i'm looking for someone who can help me to do some stuff on my code, let me show you my code :

    Code:java
    1. private Inventory spectate;
    2.  
    3. public Main plugin;
    4.  
    5. public void openSpectateGUI(Player p, Player[] players, int rows, ItemStack item) {
    6. ItemStack i = item;
    7. ItemMeta m = i.getItemMeta();
    8. spectate = Bukkit.createInventory(p, rows*9, "§cChoisissez un joueur !");
    9. for(int z = 0; z < players.length; z++) {
    10. if(Bukkit.getOnlinePlayers().length >= 53) {
    11. spectate.setItem(53, Main.next);
    12. }
    13. m.setDisplayName(players[z].getName());
    14. i.setItemMeta(m);
    15. spectate.setItem(z, i);
    16. }
    17. p.openInventory(spectate);
    18. }


    So what i want to do is if there are more than 53 players on line, then i want to set a glowstone dust at the end of the inventory like this :
    [​IMG]
    And when the player clicked on the green disc, it will open a new inventory with the rest of players connected ^^

    I will appreciate it alot if someone can help me to do this stuff! Thanks for reading my post :D
     
  2. Offline

    Flegyas

    Hi girardcome, I think you should do something like:

    Code:java
    1. int pages = 1;
    2. Player[] playersOnline = Bukkit.getOnlinePlayers();
    3. if (playersOnline.length >= 53) {
    4. pages = playersOnline.length / 52;
    5. if (playersOnline.length % 52 != 0) pages++;
    6. }


    Then, create an Inventory for each page, taking 52 player at a time and add a proper "switch" on the glowstone dust/green disc.
    You can read this tutorial for the switch https://forums.bukkit.org/threads/tutorial-create-a-inventory-menu.173571/
     
  3. Offline

    girardcome

    Oh Thanks Flegyas! :D i'll try it soon ;)
     
Thread Status:
Not open for further replies.

Share This Page