Solved Quick Question

Discussion in 'Plugin Development' started by FuZioN720, May 27, 2013.

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

    FuZioN720

    How can check if the item in hand is a book and get the title of that book?
    This is what my code is:
    Code:java
    1.  
    2. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) &&
    3. (player.getItemInHand().getItemMeta().hasDisplayName()) &&
    4. (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.stripColor("Your Stats Journal")))) {
    5. //Do Stuff
    6. }
    7.  

    But this did not work, Then i tried this.
    Code:java
    1.  
    2. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) &&
    3. (player.getItemInHand().equals(Material.WRITTEN_BOOK)) &&
    4. (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.stripColor("Your Stats Journal")))) {
    5. //Do Stuff
    6. }
    7.  

    This also did work, I know there is code like this,
    Code:java
    1.  
    2. if(ChatColor.stripColor(book.getTilte()).equals("Your Stats Journal")) {
    3.  

    But I don't know how to add this with the get item inHand
     
  2. Offline

    Jogy34

    Cast the ItemMeta to BookMeta and call getTitle()
     
    FuZioN720 likes this.
  3. Offline

    FuZioN720

Thread Status:
Not open for further replies.

Share This Page