Solved Setting top players in confing into GUI

Discussion in 'Spigot Plugin Development' started by Joshuak52, Feb 29, 2020.

Thread Status:
Not open for further replies.
  1. So I know how to get the top 3 players out of the config and broadcast them and do stuff with them but...
    How would I set these players into a GUI? Here is the code below:

    Code (Java):
    HashMap<String, Integer> votes = new HashMap<String, Integer>();

    for (String name : conf.getKeys(false)) {
                        if (conf.getString(name + ".Votes") != null) {
                            votes.put(name, conf.getInt(name + ".Votes"));
                        }
                    }

    List<String> topVotes = highToLow(votes);

    for (int x = 0; x < 3; x++) { //Getting the top 3 results
                        String votesName = topVotes.get(x);
                        int voteTop = votes.get(votesName);
                        Bukkit.broadcastMessage(ChatColor.YELLOW + votesName + ": " + ChatColor.GOLD + voteTop + " Votes");
                    }

    Also, I know how to create a GUI for other things.. I just don't know how to separate the names of my top 3 players to set them in the GUI
     
  2. Well you are already sorting them,assuming you have 3 entrys(so some checks should be done) assign the topvalues to an array and get by first entrys(0-1-2)
     
  3. Right... I've figured out how to set them in the GUI but now I am having a hard time getting the player skins as the head. Because they're just showing as regular player heads in the GUI

    Code (Text):
    for (int x = 0; x < 3; x++) { //Getting the top 3 results
                String blocksName = topBlocks.get(x);
             
                ItemStack head = new ItemStack(Material.PLAYER_HEAD);
                SkullMeta skull = (SkullMeta) head.getItemMeta();
                skull.setOwner(blocksName);
                skull.setDisplayName(blocksName);
                ItemMeta headMeta = head.getItemMeta();
                headMeta.setDisplayName(blocksName);
                head.setItemMeta(headMeta);
             
                inv.setItem(x, head);
            }
     
  4. Try head.setItemMeta(skull) to assign the SkullMeta to the Head ItemStack :)

    You created the SkullMeta but never actually used it, that’s why it won’t show the actual skins.
     
  5. Thanks but did not work :/
     
  6. Code please ?
     
  7. Actually I was wrong.. sorry!
    I was setting item meta to skull but I forgot to remove the old item meta!
    Thanks a lot!
     
  8. No problem :)

    If the problem is solved please mark the thread as solved.
     
Thread Status:
Not open for further replies.