Get Item Meta

Discussion in 'Plugin Development' started by ProMCKingz, Aug 19, 2014.

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

    ProMCKingz

    Hey!
    I have the following code, however what method do I employ to make it so that if the name of the chest is "Wardrobe", then you do the code I have said.
    Code:java
    1. public class InteractListener implements Listener {
    2. @EventHandler
    3. public void onClick(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. Action action = event.getAction();
    6. if (action == Action.RIGHT_CLICK_BLOCK
    7. || action == Action.RIGHT_CLICK_AIR) {
    8. ItemStack hand = player.getItemInHand();
    9. if (hand != null && hand.getType() == Material.CHEST) {
    10. player.sendMessage(ChatColor.GOLD
    11. + "Opening Wardrobe selector...");
    12. player.openInventory(CompassPort.getCompassInventory());
    13. event.setCancelled(true);
    14. }
    15. }
    16. }
    17.  
    18. }
    19.  

    Thanks,
    ProMCkingz
     
  2. Offline

    Gerov

  3. Offline

    ProMCKingz

    Gerov
    Lol sorry,
    Code:java
    1. public class InteractListener implements Listener {
    2. @EventHandler
    3. public void onClick(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. Action action = event.getAction();
    6. if (action == Action.RIGHT_CLICK_BLOCK
    7. || action == Action.RIGHT_CLICK_AIR) {
    8. ItemStack hand = player.getItemInHand();
    9. if (hand != null && hand.getType() == Material.CHEST) {
    10. player.sendMessage(ChatColor.GOLD
    11. + "Opening Wardrobe selector...");
    12. player.openInventory(CompassPort.getCompassInventory());
    13. event.setCancelled(true);
    14. }
    15. }
    16. }
    17.  
    18. }
    19.  
     
  4. Offline

    Gerov

    ProMCKingz Well, if you are wondering how to get ItemMeta, you first check if:


    Code:java
    1. ITEMSTACK_OBJECT.getItemMeta.getDisplayName() != null;



    And then you do what you want with the displayName of the object.
     
  5. Offline

    ProMCKingz

    Gerov
    How Do I get it from other classes?
     
  6. Offline

    Dragonphase

    ProMCKingz

    Reference the object that owns the ItemStack using a getter.
     
Thread Status:
Not open for further replies.

Share This Page