Error that appears when onPlayerInteract is called.

Discussion in 'Plugin Development' started by n31ln3t, Apr 14, 2013.

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

    n31ln3t

  2. Offline

    Hoolean

    @n31ln3

    Hey there! As Java error reports (stack traces) tell you where the problem is with a line number, it would immensely useful if you posted your whole Listener rather than just the method.

    Thanks :)
     
  3. Offline

    n31ln3t

    Thanks for helping,
    here is my code: http://pastebin.com/b3njX3Jz
     
  4. Offline

    Hoolean

    n31ln3t

    I think the problem you're having is that you need to check that player.getItemInHand() isn't null before attempting to get its type :)
     
  5. Offline

    n31ln3t

    If I do this
    player.getItemInHand()!=null.getType() == Material.MUSHROOM_SOUP

    I get an error in Eclipse saying: Cannot invoke getType of the primitive type null.
     
  6. Offline

    ZeusAllMighty11

    Code:
    if(player.getItemInHand() != null && player.getItemInHand().getType().equals(Material.MUSHROOM_SOUP)){
     
    }
    
     
  7. Offline

    n31ln3t

    Thank you!

    Hey,

    I've fixed the error with the mushroom soup, although, when he is facing a block and eats mushroom stew, it comes up with no error, and when he is facing air and eats mushroom stew it gives an error.
    This also occurs when player is swinging a sword in air.

    My code: http://pastebin.com/XyqhnV3H
    My error: http://pastebin.com/9Vf2zndJ

    I still need help :(

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

    Me4502

    Code:
    if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand()!=null && player.getItemInHand().getType() == Material.MUSHROOM_SOUP && player.getHealth()!=20) {
    That code is the issue. you are checking if the thing isn't null only if it is a block right click. try,

    Code:
    if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && player.getItemInHand()!=null && player.getItemInHand().getType() == Material.MUSHROOM_SOUP && player.getHealth()!=20) {
     
  9. Offline

    n31ln3t

    Thanks, I'm following you!


    I tried to apply the same concept in this code, but I'm still getting an error:

    if (event.getClickedBlock().getState() instanceof Sign){

    if (event.getClickedBlock().getState() instanceof Sign){
    Action action = event.getAction();
    Block block = event.getClickedBlock();
    if(action == Action.RIGHT_CLICK_BLOCK && (block.getType() == Material.SIGN || (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN))) {
    Sign sign = (Sign) event.getClickedBlock().getState();
    if(sign.getLine(0).contains("[Scavenge]")){
    player.sendMessage(ChatColor.GOLD+"[Neilnet]"+ChatColor.WHITE+" Teleporting you to: "+ChatColor.RED+sign.getLine(1));
    int x = getConfig().getInt(sign.getLine(1)+".x");
    int y = getConfig().getInt(sign.getLine(1)+".y");
    int z = getConfig().getInt(sign.getLine(1)+".z");
    //player.teleport(new Location(player.getWorld(),x,y,z));
    player.sendMessage(ChatColor.GOLD+"[Neilnet]"+ChatColor.WHITE+"You're being teled to: x="+x+"y="+y+"z="+z);
    }

    }
    }
    }



    Here is the error:
    http://pastebin.com/JbbwEGMV
     
  10. Offline

    Spikes

    Use this:
    Code:java
    1. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    2. if (event.getClickedBlock().getState() instanceof Sign) {
    3. Sign s = (Sign) event.getClickedBlock().getState();
    4. //Code here
    5. }
    6. }
     
Thread Status:
Not open for further replies.

Share This Page