Check for clicked item

Discussion in 'Plugin Development' started by creppii, Feb 11, 2014.

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

    creppii

    hey... how can i check if the clicked item in a inventor is a enchanted! golden apple?
    or maybe can i check the name of the enchanted golden apple? (e.getName("Enchanted Golden Apple).. or something like this)?

    ty and greez
     
  2. Offline

    Timbals

    creppii

    You have to use an InventoryClickEvent and check for the data of the golden apple

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onInventoryClick(InventoryClickEvent e) {
    4. if(e.getCurrentItem() == null || !(e.getWhoClicked() instanceof Player))
    5. return;
    6.  
    7. ItemStack item = e.getCurrentItem();
    8. Player p = (Player) e.getWhoClicked();
    9.  
    10. if(item.getType() == Material.GOLDEN_APPLE) {
    11. if(item.getData().getData() == (short) 1) {
    12. //Do something with the enchanted golden apple
    13. }
    14. }
    15.  
    16. }
     
Thread Status:
Not open for further replies.

Share This Page