Solved Skulls set to the Inventory

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 11, 2016.

  1. Hello so I'm going to ask how to make a ItemStack skull and too many owners such as List<String>

    if thats a for loop statement how or what to do ?

    Code (Java):
    // config.yml
    List:
      - MadMaxCookie
      - love
      - cookies
    Code (Java):
     // Inventory
    Inventory inv;

    for(int i = 0; i <= 8; i++) {
     inv.setItem(i, skull);
    }
     
  2. MiniDigger

    Supporter

    wat
    could you be a bit more precice on what you are trying to do?
     
  3. oh well so I'm trying to do that the player's in the list has their own skull then put it to the inventory from slot 0 to slot 8
     
  4. If I understand correctly what you're trying to do, here's pseudo-code that should work:
    Code (Text):
    for each player in the configuration's list:
        create an item stack
        use SkullMeta#setOwner(String name)
        for slot 0 to 8:
            set the item in this slot
     
  5. yes

    Code (Java):
    List<String> list = getConfig().getStringList(list);
    for(s : list) {
    SkullMeta#setOwner(s);
    }

    for(int i = 0; i <= 8; i++) {
    inv.setItem(i, skull);
    }

    is it correct ?
     
    #5 MadMaxCookie, May 12, 2016
    Last edited: May 12, 2016
  6. You would set the owner to "s" not "list" as that's the itterating veritable. Add the heads in the same for-each loop of the skull owner list.
     
  7. oh lol thanks for notifying that thing I didn't expected I putted list not the for loop string s :D sorry gotta edit that post
     
  8. Code (Java):
    List<String> list = getConfig().getStringList(list);
    Here, list has to be replaced by something like "List", it shouldn't be the variable but a hardcoded string (not sure if you did that on purpose, so I wanted to point it out just to be sure).

    Code (Java):
    for(s : list) {
    You have to define the type of the "s" variable. So it would look like that: for (String s : list)

    Code (Java):
    SkullMeta#setOwner(s);
    Don't use "#", but a dot (the pound sign is to reference a function, it is used in pseudo-code and anything outside of real code).

    Code (Java):
    for(int i = 0; i <= 8; i++) {
    Here I would have put "i < 9" rather than "i <= 8", both would work it's just question of habit.
    And this for loop should be IN the first one, as @xMrPoi said.
     
  9. this thread is already solved sorry for not marking it
     
    • Like Like x 1