Solved Getting online player heads in a GUI

Discussion in 'Plugin Development' started by Konkz, Mar 22, 2014.

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

    Konkz

    Hey,

    When you click an apple as an example it opens up a GUI which contains every
    persons head that is in the arraylist 'Playing'.
    Once they are clicked it will teleport you to them

    I'm not sure how to go about this, tried to google it but nothing too useful come out.

    Thanks for help in advance.
     
  2. Offline

    Phyla

    Konkz
    Sounds very interesting! Do you have skype? I'm trying to resolve myself around coders so i can become a better one myself! Would like to help! :D
     
  3. Offline

    acecheesecr14

    Use a for loop and loop through all the players, adding a new item with the appropriate data/damage values and such, to the custom inventory.
     
  4. Offline

    Konkz

    How do I add a new item to the GUI without it stacking though?

    What sounds intresting? :p It's part of my plugin, aha. And if you want then sure - odi_konkz
     
  5. Offline

    acecheesecr14

    Code:java
    1. //Put this in the event class
    2. public ItemStack setOwner(String owner) {
    3. ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
    4. SkullMeta meta = (SkullMeta) item.getItemMeta();
    5. meta.setOwner(owner);
    6. item.setItemMeta(meta);
    7. return item;
    8. }
    9.  
    10.  
    11. //Put this in an event somewhere?
    12. for(int i =0; i < prices.length; i++) {
    13. i++;
    14. myInventory.setItem(i, setOwner(player.getName()))
    15. }


    If you are having trouble with it stacking, I think you can do myInv.setMaxStackSize(1) or something like that. :p

    And you're like the 3rd person he's said that to, maybe you'll be added to one off those massive spam chats..

    Acctually Konkz instead of adding it to an event, probably best to add it to a repeating task triggered in onEnable, that way it can't be spammed by players and "cause lag". Maybe have it run every 30 seconds or minute.

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

    Konkz


    The way that they would be added is when they join and taken away when they die, as the menu shows people in the array 'playing' - this is as I want spectators to teleport to participating players.
     
  7. Offline

    acecheesecr14

    Look through an array then, you only have to change 1 part of it to match an array. I edited it above to assist. Konkz
     
  8. Offline

    Konkz


    Code:java
    1. for([COLOR=#00008b][SIZE=14px][FONT=Consolas]int[/FONT][/SIZE][/COLOR][SIZE=14px][COLOR=#000000][FONT=Consolas] i [/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas]= [/FONT][/COLOR][/SIZE][COLOR=#800000][SIZE=14px][FONT=Consolas]0[/FONT][/SIZE][/COLOR][SIZE=14px][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas] i [/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas]<[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas] YOUR_ARRAY[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas].[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas]length[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas] i[/FONT][/COLOR][/SIZE][SIZE=14px][COLOR=#000000][FONT=Consolas]++[/FONT][/COLOR][/SIZE]) {


    Fix that, if possible, please? <3
     
  9. Offline

    acecheesecr14

    My bad ;P
     
  10. Offline

    Konkz

    acecheesecr14

    As I am doing it a little different way as I could not work out how to use yours. This is how I'm doing it:

    PHP:
    public static ItemStack i1 = new ItemStack(Material.SKULL_ITEM1,
                (
    short3);
    PHP:
    static {
            
    OnlinePlayers Bukkit.createInventory(null54"Online Players");
            for (
    Player p Bukkit.getOnlinePlayers()) {
                    
    SkullMeta meta = (SkullMetai1.getItemMeta();
                    
    meta.setDisplayName(p.getName());
                    
    i1.setItemMeta(meta);
                    
    OnlinePlayers.addItem(new ItemStack[] { i1 });
            }
        }
    How would I go about only adding the skull if they are in the array? I store them as Strings therefore I can't do for(Player p : getPlaying()) {//code}
     
  11. Offline

    acecheesecr14

    use bukkit's api and get the player from the playername...
     
  12. Offline

    Konkz

    Nvm, forget it.

    PHP:
    static {
            
    OnlinePlayers Bukkit.createInventory(null54"Online Players");
            for (
    String name : Global.getInstance().getPlaying()) {
                
    Player p Bukkit.getPlayer(name);
                    
    SkullMeta meta = (SkullMetai1.getItemMeta();
                    
    meta.setDisplayName(p.getName());
                    
    i1.setItemMeta(meta);
                    
    OnlinePlayers.addItem(new ItemStack[] { i1 });
            }
        }
    Can't get it to work, keeps calling the head "Head" and not my name.
     
Thread Status:
Not open for further replies.

Share This Page