Solved Skull GUI

Discussion in 'Plugin Development' started by The Fancy Whale, Jul 13, 2014.

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

    The Fancy Whale

    I am trying to make a GUI for people to see all of the heads of people that are still alive. Here is the current code:
    Code:java
    1. public static Inventory heads = Bukkit.createInventory(null, 27, ChatColor.GREEN + "Teleport");
    2. static {
    3.  
    4. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
    5. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    6. int i = 0;
    7. for (Player p : Main.alive){ // Main.alive is not the issue as it works fine in other parts of the code
    8.  
    9.  
    10. meta.setOwner(p.getName());
    11. meta.setDisplayName(ChatColor.LIGHT_PURPLE + p.getName());
    12. skull.setItemMeta(meta);
    13. heads.setItem(i, skull);
    14. i++;
    15. }
    16.  
    17.  
    18. }

    For some reason the inventory is always empty. It has the title "Teleport" though and the correct number of slots. Also, there are no errors. Any help is greatly appreciated thanks!!
     
  2. Offline

    TheMcScavenger

    It's not the issue, just thought I'd point it out: you're first adding one to int i, then using i - 1. Why don't you just add one to i at the end... Seems a bit odd to do it like this, as you're modifying i twice..
     
    The Fancy Whale likes this.
  3. Offline

    The Fancy Whale

    Yeah I could do that.
    EDIT: fixed that.... if only that would fix the real issue xD
     
  4. Offline

    TheMcScavenger

    Works fine for me:

    Code:java
    1. public void onEnable() {
    2. Inventory heads = Bukkit.createInventory(null, 27, ChatColor.GREEN + "Teleport");
    3.  
    4. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
    5. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    6. int i = 0;
    7.  
    8. for (Player p : Bukkit.getOnlinePlayers()){
    9. meta.setOwner(p.getName());
    10. meta.setDisplayName(ChatColor.LIGHT_PURPLE + p.getName());
    11. skull.setItemMeta(meta);
    12. heads.setItem(i, skull);
    13. i++;
    14. }
    15.  
    16. for(Player p : Bukkit.getOnlinePlayers()){
    17. p.openInventory(heads);
    18. }
    19. }
     
  5. Offline

    The Fancy Whale

    hmm thats really strange... let me try with not using Main.alive. That might be the issue I guess.

    TheMcScavenger Yeah worked fine for me with all online players... That's really weird because the scoreboard works fine with using Main.alive but the inventory doesn't...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    TheMcScavenger

    Is it a player list?

    Code:java
    1. public static List<Player> players = new ArrayList<Player>();
     
  7. Offline

    The Fancy Whale

    Yep
     
  8. Offline

    TheMcScavenger

    Is it empty? XD

    Code:java
    1. Bukkit.broadcastMessage(Main.alive.toString());
     
    The Fancy Whale likes this.
  9. Offline

    The Fancy Whale

    Okay I did that, and now there are 2 players in the list, but only one skull in the GUI.
     
  10. Offline

    TheMcScavenger

    Is it the first or the second name in the list? Maybe it's overriding the first..?
     
  11. Offline

    The Fancy Whale

    Second name isn't showing up.
    "[Server] INFO [CraftPlayer{name=TheFancyWhale}, CraftPlayer{name=kierdo1000}]"
    but only TheFancyWhale head shows up
     
  12. Offline

    Vorqe

    Just edit my code:) my shows all online players just change it to check a world or something.

    Code:
        public void Online(Player player){
            Player[] players = Bukkit.getServer().getOnlinePlayers();
                   
                      ItemStack i = new ItemStack(Material.SKULL_ITEM);
                      ItemMeta m = i.getItemMeta();
                      i.setDurability((short) 3);
                      Inventory spectate = Bukkit.createInventory(player, 54, "Current Players " + "[" + players.length + "]");
                      for(int z = 0; z < players.length; z++)
                      {
                          m.setDisplayName(ChatColor.GREEN +players[z].getName());
                          ArrayList<String> nlore = new ArrayList<String>();
                          nlore.add(ChatColor.WHITE + "Current Level : " + ChatColor.GREEN + players[z].getLevel());
                          nlore.add("" + ChatColor.WHITE + "Health : " + ChatColor.GREEN + players[z].getHealth());
                          nlore.add(ChatColor.WHITE + "Food Level : " + ChatColor.GREEN + players[z].getFoodLevel());
                          m.setLore(nlore);
                          i.setItemMeta(m);
                          spectate.setItem(z, i);
                      }
                      player.openInventory(spectate);
                  }
     
    The Fancy Whale likes this.
  13. Offline

    The Fancy Whale

    Tried something similar to that and got it working. Thanks for the help. Still not sure what's wrong with my original code though :/
     
  14. Offline

    Vorqe

    Ill take a look when im free and sort it out ;)

    EDIT;

    You need to get the first empty slot and add the head for each player... Also use this to get one player

    Code:
    Player[] players = Bukkit.getServer().getOnlinePlayers();
    then to get a player fro that use this

    Code:
    players[z].getName()
    there...
     
  15. Offline

    TheMcScavenger

    Vorqe He already got it working...
     
  16. Offline

    Vorqe

    TheMcScavenger I was showing him what he needed to do to fix his code <removed>, he did it totally wrong so I helped him by giving him my code and the fix for his.


    [edit by JaguarJo: removed insult. Please keep this discussion civil. Thanks.]
     
  17. Offline

    TheMcScavenger

    Do you even know what "working" means? It means he doesn't need you to edit code anymore, because his version already does the job without errors. All you're doing is bumping a thread that has already been resolved, as can be seen by the [Solved] tag.


    [edit by JaguarJo: removed improper content in quoted comment.]
     
  18. Offline

    Vorqe

    Tried something similar to that and got it working. Thanks for the help. Still not sure what's wrong with my original code though :/ <-- What he said so I fixed it.
     
Thread Status:
Not open for further replies.

Share This Page