Set Item names?!?!?

Discussion in 'Plugin Development' started by B3N909, Jul 13, 2014.

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

    B3N909

    I know this is a simple question but how do I set a item name? For example I have something like this:
    Code:
    ItemStack bucket = new ItemStack(Material.LAVA_BUCKET);
    
    How do I name the lava bucket GOLD?
     
  2. Offline

    MrKeals

    Code:java
    1. ItemStack bucket = new ItemStack(Material.LAVA_BUCKET);
    2. ItemMeta im = bucket.getItemMeta();
    3. im.setDisplayName("Gold");
    4. bucket.setItemMeta(im);
    5.  
     
  3. Offline

    B3N909

    This is not right!!! This is what I currently have and it does not name it!!!
    Code:
    ItemStack bucket = new ItemStack(Material.LAVA_BUCKET);
    ItemMeta im = bucket.getItemMeta();
    int goldlevel = getGold(name);
    im.setDisplayName(ChatColor.BOLD + "" + ChatColor.GOLD + "Gold: " + goldlevel);
    p1.getInventory().setItem(8, bucket);
    
    It just gives the player a regular LavaBucket?
     
  4. Offline

    Necrodoom

    B3N909 You never applied the itemmeta on the itemstack.
     
  5. Offline

    TheMcScavenger

    This is wrong indeed, you didn't do as MrKeals said.
     
  6. Offline

    B3N909

    Sorry... I missed the packing part...
     
  7. Offline

    hankered

    give the itemstack its own method so it doesn't look like a pile of crap
     
  8. Offline

    TheMcScavenger

    Says the person that can't type a sentence using capitalisation and punctuation..
     
  9. Offline

    hankered

    TheMcScavenger
    wow, i'm sorry, i never thought you needed to use proper grammar to help someone. my apologies.
     
  10. Offline

    TheMcScavenger

    You don't. You do however need to use capitalisation and punctuation in order for your comment to look good, before you start calling things "crap".
     
  11. Offline

    hankered

    TheMcScavenger
    i didn't call anyone's code crap i was just saying give the custom itemstack its own method so your code doesn't look horrible..
     
  12. Offline

    B3N909

    But you just said they were horrible? :D
     
  13. Offline

    hankered

    B3N909
    no i didn't? i said if you put your code for the itemstack in the same place as your if-statements or whatever then your code will look horrible and unorganized
     
  14. Offline

    TheMcScavenger

    It won't. Don't claim to know things when you clearly don't.
     
  15. Offline

    B3N909

    Lets not be rude on a public forums :D

    TheMcScavenger hankered Can you guys actually help me now? And not try to make yourself look good? How do I remove items with a custom meta?

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

    hankered

    custm meta? i think if you make a for loop and go through all the items with #hasItemMeta and remove them. but I'm sure every item has a itemmeta so.
     
  17. Offline

    TheMcScavenger

    Code:java
    1. for(ItemStack stack : player.getInventory().getContents()){
    2. ItemMeta meta = stack.getItemMeta();
    3. String displayName = meta.getDisplayName();
    4. if(displayName.equals("My name")){
    5. player.getInventory().remove(stack);
    6. }
    7. }
     
  18. Offline

    Gater12

  19. Offline

    TheMcScavenger

    Just a quick draft, not the finished product ;)
     
  20. Offline

    B3N909

    TheMcScavenger Gater12 I just tried and it would not check for my Lava Bucket. I am using PlayerClickEvent to see if the player clicks it. If they do it should cancell it. BUT if you shift and click you can dupe the item. That is what I am trying to fix!
     
  21. Offline

    Gater12

    B3N909
    There is no PlayerClickEvent. Did you mean PlayerInteractEvent?
     
  22. Offline

    B3N909

    Gater12 sorry InventoryClickEvent

    Gater12 is there any way to make the first item in the players inventory to 0 or air. So when they shift click it just sets to zero?

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

    Gater12

    B3N909
    Your current code for your event method?
     
  24. Offline

    B3N909

    Gater12
    Code:
    @EventHandler
    public void onClickSlot(InventoryClickEvent event){
    if(event.getSlot() == 8){
    event.setResult(Result.DENY);
    event.setCancelled(true);
    String p = event.getWhoClicked().getName();
    Player usr = (Player)event.getWhoClicked();
    usr.closeInventory();
    int goldLevel = getGold(usr.getName().toLowerCase());
    usr.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Gold: " + goldLevel);
    UI(p);
    }
    }
    
    UI(p); sets the player so he/she has a bucket with the correct gold level.
     
  25. Offline

    MrKeals

    B3N909 not works because you didn't do what I said... You forgot
    Code:java
    1. bucket.setItemMeta(im);
     
    MCMastery likes this.
Thread Status:
Not open for further replies.

Share This Page