Checking Block's Metadata

Discussion in 'Plugin Development' started by leland22, Mar 2, 2014.

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

    leland22

    I'm trying to add to my plugin where when the user right clicks with a web on a block it cancels the block placement (which I have already done), removes the item from the inventory, which happens already but I don't know how WorldGuard will affect this, and gives them a new renamed item. I can't seem to get the meta data of the block however. Any help would be greatly appreciated!


    Code:java
    1. @EventHandler
    2. public void onWebPlacement(BlockPlaceEvent event){
    3. Player p =event.getPlayer();
    4. Block b = event.getBlock();
    5. Inventory inventory = p.getInventory();
    6. if (p.getInventory().contains(Material.WEB)){
    7.  
    8.  
    9.  
    10. }
    11. event.setCancelled(true);
    12. }


    Bump, could anyone help?

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

    NathanWolf

    By metadata, do you mean the chest contents, sign text, etc? If so, check out BlockData and it's subclasses.
     
  3. Offline

    leland22

    Metadata was the wrong word, I mean the Item Meta
    NathanWolf
     
  4. Offline

    NathanWolf

    Oh! I see, to give them the renamed item, you mean? There are tons of posts on that here if you search, but basically it's something like

    Code:text
    1. ItemMeta meta = itemStack.getItemMeta();
    2. meta.setDisplayName("foo bar");
    3. itemStack.setItemMeta(meta);[syntax]
    4.  
    5. ... Typed via mobile, May or may not be 100% correct but should be the right idea, at least :)
     
  5. Offline

    leland22

    NathanWolf
    I know how to rename it and such but I'm trying to detect if the player places a renamed cobweb and it then removes that web from the inventory and adds a new one with different lore and title
     
  6. Offline

    NathanWolf

    I'm not sure how or if you can get the item that was placed in the block place event. Check the java docs, or wait for someone more experienced than me to come and help :)
     
Thread Status:
Not open for further replies.

Share This Page