Null Pointer Exception.. but only sometimes

Discussion in 'Bukkit Help' started by Randoro, Jun 27, 2013.

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

    Randoro

    Hey
    I'm having a very strange problem at the moment. So I have some code in which i use the PlayerInteractEvent in my listener class. Code is working, as in the plugin completes the tasks its suppose to do. However the server that tries my plugin gets null pointer exceptions. We tried making a server in Dropbox, when I run it, no errors. When he runs it, many many null pointer exceptions, using the SAME files as I did. We have the same Java version (1.7.0_25). We both run 64-bit, we even tried with a 32-bits bat script to start the server with 32bits java. Same result.
    This is the deal. One server, one stationary computer and one laptop, all belonging to my friend, shows lots of null pointer exceptions.
    My computer shows none.
    Is there anyone with similar problems/who knows what i'm talking about?
    Some of the code:
    Code:java
    1. ItemStack air = new ItemStack (Material.AIR, 0);
    2.  
    3.  
    4. @EventHandler
    5. public void onPlayerClick(PlayerInteractEvent event)
    6. {
    7. Player player = event.getPlayer();
    8. final Player player2 = player;
    9.  
    10.  
    11.  
    12.  
    13.  
    14. int hp = player.getHealth();
    15. if((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_AIR))
    16. {
    17.  
    18.  
    19.  
    20.  
    21. if(hp < 20) {
    22.  
    23. Player rand2 = Bukkit.getServer().getPlayer("Randoro");
    24.  
    25.  
    26.  
    27.  
    28. if(player.getTargetBlock(null, 4).getType() == Material.CAKE_BLOCK) {
    29. Location block = player.getTargetBlock(null, 4).getLocation();
    30. if (getWorldGuard().canBuild(player, block)) {
    31.  
    32. Block cake = player.getTargetBlock(null, 4);
    33. byte data = cake.getData();
    34.  
    35. if(data == 5) {
    36. cake.setType(Material.AIR);
    37. player.setHealth(20);
    38. } else {
    39. cake.setData((byte) (data + 1));
    40. player.setHealth(20);
    41. }
    42. }
    43.  
    44. }
    45.  
    46.  
    47.  
    48. if(player.getItemInHand().getType() == Material.APPLE)
    49. {
    50. event.setUseItemInHand(Result.DENY);
    51. hp += apple;
    52. if (hp <= 20) {
    53. player.setHealth(hp);
    54. } else if (hp > 20) {
    55. player.setHealth(20);
    56. }
    57. int amount = player.getItemInHand().getAmount();
    58. if (amount > 1) {
    59. amount -= 1;
    60. player.getItemInHand().setAmount(amount);
    61. } else if (amount == 1) {
    62. ItemStack hurr = new ItemStack(Material.AIR, 0);
    63. player.setItemInHand(hurr);
    64. }
    65.  
    66. if(rand2.isOnline()) {
    67. Random random2 = new Random();
    68. int derp2 = random2.nextInt(3000);
    69. if (derp2 == 0) {
    70. player.sendMessage("Bazinga!");
    71. rand2.sendMessage("Bazinga!");
    72. player.teleport(rand2);
    73. }
    74. }
    75. }
    76. }
    77. }
    78. }


    error picture:
    [​IMG]
     
  2. try taking the folder out of dropbox? it could be because dropbox is locking the file to upload it every time a change is made.
     
  3. Offline

    Necrodoom

    paste the full class first off. its pointing at a line but we cant know which.
     
  4. Offline

    Randoro

    We tried this already.

    http://pastebin.com/zcr6Krtk

    Sorry for the bad spacing..

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

    coldandtired

    You call Block methods even if it could be air.
     
  6. Offline

    Randoro

    Could you be more specific? Where do I do this?
     
  7. Offline

    coldandtired

    From what I remember, with things like this (if(player.getTargetBlock(null, 4).getType()) the target block can be null.

    So can player.getItemInHand().
     
Thread Status:
Not open for further replies.

Share This Page