NPE - Explode

Discussion in 'Plugin Development' started by Pink__Slime, May 25, 2013.

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

    Pink__Slime

    So currently I'm getting an NPE on this event:

    Code:java
    1. @EventHandler
    2. public void wither(PlayerInteractEvent event){
    3. Player p = event.getPlayer();
    4. if(p.getWorld().getName().equalsIgnoreCase("pvp")){
    5. if(p.getItemInHand().getType().equals(Material.SULPHUR)){
    6. if(Main.playCreeper.containsKey(p.getName())){
    7. p.getWorld().createExplosion(p.getLocation(), 9);
    8. //Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    9.  
    10. // @Override
    11. // public void run() {
    12.  
    13. // p.setHealth(0);
    14.  
    15. // }
    16. // },5L);
    17. }
    18. }
    19. }
    20. }


    The error is currently on p.getWorld().createExplosion(p.getLocation(), 9);

    Can someone please help me figure out why it's reporting an NPE
     
  2. Offline

    Seadragon91

    Are your sure that it's this line, don't see here anything that can throw an NPE:
    Code:
    if(p.getWorld().getName().equalsIgnoreCase("pvp")){
    But this line can thow an NPE:
    Code:
    if(p.getItemInHand().getType().equals(Material.SULPHUR)){
    
    If the player have no item in the hand then the itemstack is null. Do a null check:
    Code:
    if(p.getItemInHand() != null && p.getItemInHand().getType().equals(Material.SULPHUR)){
     
  3. Offline

    Pink__Slime

    Seadragon91
    Still getting NPE's. Same line as well.

    If it helps, the explosion happens but there is absolutely no damage. I can't see the explosion but only hear it.

    EDIT: Figured it out... I stupidly had a WorldGuard region set >.< Still get the NPE though, not too worried about it.
     
Thread Status:
Not open for further replies.

Share This Page