Custom Player Inventory

Discussion in 'Plugin Development' started by camji555, Aug 13, 2013.

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

    camji555

    Hello, I have been trying for hours to figure out how to give players a custom inventory. For example when they join the server it clears their inventory, and gives them a compass with a custom name, and a book with writing inside. Any help? Thanks in advance.
     
  2. Offline

    Staartvin

    Code:java
    1. event.getPlayer().getInventory().clear();


    Code:java
    1. ItemStack item = new ItemStack(345, 1);
    2.  
    3. item.getItemMeta().setDisplayName("Compass Name");
    4.  
    5. player.getInventory().addItem(item);
    6.  
    7. ItemStack book = new ItemStack(387, 1);
    8.  
    9. List<String> pages = Arrays.asList("Page 1 content", "Page 2 content", "Page 3 content");
    10.  
    11. BookMeta bm = (BookMeta) book.getItemMeta();
    12. bm.setPages(pages);
    13.  
    14. book.setItemMeta(bm);
    15.  
    16. player.getInventory().addItem(book);
     
  3. Offline

    camji555

    I get quite a few errors in eclipse with the second part of the code you gave me.
     
  4. Offline

    Staartvin

    It shouldn't. I haven't tested this, but it looks good to me.
     
  5. Offline

    camji555

    Ill take a screenshot for you.

    [​IMG]

    Everything is imported as well.

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

    DxWeennaaaa

  7. Offline

    Staartvin

    What does it say when you hover over it?
     
  8. Offline

    MrGermanrain

    You need to import ItemStack if I am correct...
     
  9. Offline

    camji555

    Itemstack is already imported.
     
  10. Offline

    MrGermanrain

    Let me look into it
     
  11. Offline

    camji555

    "The constructor ItemStack(int, int) is undefined" For the first and fourth error in the picture above.
    "The method getItemMeta() is undefined for the type ItemStack" For the Second, Sixth, and Seventh error.
    "The method addItem(ItemStack...) in the type Inventory is not applicable for the arguments (ItemStack)" For the Third and Eight error. "Type mismatch: cannot convert from java.util.List<java.lang.String> to com.sun.tools.javac.util.List<java.lang.String>" For the Fifth.

    I fixed all but one of the problems, But now when I get the items, the compass doesn't change names. Any help?

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

    Staartvin

    You have to do the same for the item as for the book.

    Get item meta -> set display name -> set item meta to changed item meta.
     
  13. Offline

    camji555

    Thanks I got it.
     
  14. Offline

    Staartvin

Thread Status:
Not open for further replies.

Share This Page