Solved Help with my plugin

Discussion in 'Plugin Development' started by Garnetty, Dec 15, 2014.

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

    Garnetty

    Right now I'm just screwing around with Java and making absolutely random and custom things on a plugin, when I ran into a slight issue.

    This Event isn't working and the console is bringing something up about it being a NPE.

    (You're supposed to be able to click a stone block with a diamond in your hand and it will play an anvil landing sound)
    Here's the code:

    [​IMG]

    Here's the error:


    http://pastebin.com/0Y2VakYC
     
    Last edited: Dec 15, 2014
  2. Offline

    Skionz

    @Garnetty Give us the entire class, and for future reference you are writing Java, not JavaScript. You are probably getting an NPE because you are checking for the items display name before checking if the item actually has a display name.
     
  3. Offline

    Garnetty

    Give me one second
     
  4. Offline

    drpk

  5. Offline

    Unica

    @Garnetty

    • This is not called Javascript although it's scripting in Java
    • What if the clicked block is null? What if the item doesn't have any itemmeta?
    • Code:
      ItemStack item = theItemInHand();
      if(item.hasItemMeta() && item.getItemMeta().hasDisplayName()){  
          //Item has a name
          String itemName = item.getItemMeta().getDisplayName();
      }
    • Code:
      Block clicked = blockThatShouldHaveBeenClicked;
      if(clicked != null && clicked.getType() != Material.AIR){
             //Item is not air, continue code :D
      }
    • Last but not least, if you only want it to happen on rightclick check the action
      Code:
      if(e.getAction() == Action.RIGHT_CLICK_BLOCK){ }
      // Voila
    • I believe you have to teleport the player in order to move him one block up (Not sure)
    • You're getting values and not doing something with it.
      Code:
      player.getNearbyEntities(3, 3, 3);
      //Great you retrieved information. What now?
      

    EDIT:
    Don't forget to check if the player has actually an item in his hand using
    Code:
    ItemStack hand = iteminhishand;
    if(hand != null && hand.getType() != material.AIR){
         //He has an item in his hand
    }
     
  6. Offline

    Garnetty

    http://pygments.org/demo/1050181/

    Fixed it, with this as the outcome code

    [​IMG]
    I used some of the code that @Unica gave me and incorporated those if (code here != &&) statements throughout to fix it, and all of the console errors are also gone.


    Thank you guys for helping me out with this, I get better at coding with every little step and help that I get, and I couldn't thank you enough as this wouldn't be possible for me without you.

    And Unica, do you mind if I message you from time to time if I ever get stuck? I'm like 3/4 done with this Kitpvp plugin for the server that I will launch sooner or later.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
Thread Status:
Not open for further replies.

Share This Page