PlayerInteractEvent giving NPE.

Discussion in 'Plugin Development' started by tylerthecreeper1, Nov 12, 2014.

Thread Status:
Not open for further replies.
  1. I'm newer to Java and I'm recoding my first plugin for practice, which is a simple lightning striking when using a stone axe, like Thor. I'm getting a NullPointerException when I click the stone axe that this code spawns, here:
    Code:
    Caused by: java.lang.NullPointerException
            at net.orbitalmc.thor.Events.onInteract(Events.java:19) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298)
    Here's my PlayerInteractEvent.
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e) {
    3. if(!(e.getClickedBlock().getType() == Material.STONE)) { //this is line 19, where the npe is
    4. //do nothing
    5. } else {
    6. if(e.getPlayer().hasPermission("thor.use")) {
    7. e.getClickedBlock().setType(Material.AIR);
    8.  
    9. ItemStack t = new ItemStack(Material.STONE_AXE);
    10. ItemMeta tm = t.getItemMeta();
    11. tm.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Thor's Hammer");
    12. tm.setLore(Arrays.asList(ChatColor.GRAY + "" + ChatColor.ITALIC + "Right Click for Lightning",
    13. ChatColor.GRAY + "" + ChatColor.ITALIC + "Left Click for Smash"));
    14. t.setItemMeta(tm);
    15.  
    16. e.getClickedBlock().getLocation().getWorld().dropItemNaturally(e.getClickedBlock().getLocation(), t);
    17. }
    18. else {
    19. //do nothing
    20. }
    21. }
    22. }


    Any help would be great. Thanks in advance.
     
  2. Offline

    adam753

Thread Status:
Not open for further replies.

Share This Page