Why am i getting an error?

Discussion in 'Spigot Plugin Development' started by Creepermanthe3rd, Apr 19, 2017.

  1. Code (Text):

        @EventHandler
        public void voucherClcik(PlayerInteractEvent e){
            Player p = e.getPlayer();
            int amountI = e.getPlayer().getItemInHand().getAmount();
            if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_AIR) {
                if(p.getInventory().getItemInHand().getItemMeta().getDisplayName().toLowerCase().contains(Main.color("&2&l$"))) {  
                    if (e.getItem().getAmount() == 1) {
                         if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().contains(" ")){
                             p.getInventory().remove(e.getItem());
                               String Name = e.getPlayer().getItemInHand().getItemMeta().getDisplayName().substring(0, e.getPlayer().getItemInHand().getItemMeta().getDisplayName().indexOf(" "));
                               Name = Name.substring(5);
                               double Amount = Double.parseDouble(Name);
                               double dr = (int) ((Amount * 100) + 0.5);
                                double amount2 = dr / 100;
                               
                               Main.eco.depositPlayer(p, amount2);
                               p.sendMessage(Main.color("&a&l+ &2&l$") + amount2);
                    }else {
                        p.getInventory().getItemInHand().setAmount(amountI - 1);
                           String Name = e.getPlayer().getItemInHand().getItemMeta().getDisplayName().substring(0, e.getPlayer().getItemInHand().getItemMeta().getDisplayName().indexOf(" "));
                           Name = Name.substring(5);
                           double Amount = Double.parseDouble(Name);
                           double dr = (int) ((Amount * 100) + 0.5);
                            double amount2 = dr / 100;
                           
                           Main.eco.depositPlayer(p, amount2);
                           p.sendMessage(Main.color("&a&l+ &2&l$") + amount2);
                    }
                }
                }else {
                    return;
                }
            }
        }
    }
     
    Error
    [16:29:17 ERROR]: Could not pass event PlayerInteractEvent to MythicCore v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:193) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:189) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:682) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.jar:git-Spigot-952179b-0cf233d]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:685) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-952179b-0cf233d]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
    at com.dillion.core.mobDrops.dropClcik(mobDrops.java:185) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-952179b-0cf233d]
    ... 17 more
    [16:29:17 ERROR]: Could not pass event PlayerInteractEvent to MythicCore v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:193) [spigot.jar:git-Spigot-952179b-0cf233d]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:189) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:682) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.jar:git-Spigot-952179b-0cf233d]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:685) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-952179b-0cf233d]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-952179b-0cf233d]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
    at com.dillion.core.bankNotes.voucherClcik(bankNotes.java:76) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-952179b-0cf233d]
    ... 17 more
     
  2. What's on line 185 of mob drops?


    Sent from my iPhone using Tapatalk
     
    • Agree Agree x 1
  3. Code (Text):
     if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_AIR)
    Why do you state "e.getAction() == Action.RIGHT_CLICK_AIR" twice?
     
  4. if(p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(Main.color("&aPurified Ghast Tear"))) {
    I
     
  5. Must have been a typo meant block

    EDIT: changed to block, didnt fix the error though.
     
  6. Do you ever check if iteminhand is null?

    If not then if the player has no item in hand and you try to get its meta that's your null pointer.

    You'll also need to check if the item has meta otherwise you'll get a null pointer if it has no display name set.


    Sent from my iPhone using Tapatalk
     
    • Agree Agree x 1
  7. will give it a shot

    EDIT: It worked :} thanks
     
    #7 Creepermanthe3rd, Apr 19, 2017
    Last edited: Apr 19, 2017