[SOLVED]NullPointer on removing an item

Discussion in 'Spigot Plugin Development' started by DaanSander, May 24, 2015.

  1. Hello i was trying to remove the item from the players their inventory when they have picked up an item but when i try my code it gives me a nullpointer can someone help me to solve this problem?

    StackTrace
    Code (Text):
    [10:02:01] [Server thread/ERROR]: Could not pass event PlayerPickupItemEvent to FarmMaddness v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.EntityItem.d(EntityItem.java:314) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.EntityHuman.d(EntityHuman.java:448) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.EntityHuman.m(EntityHuman.java:439) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.EntityLiving.t_(EntityLiving.java:1482) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.EntityHuman.t_(EntityHuman.java:173) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.EntityPlayer.l(EntityPlayer.java:285) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:376) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.PacketPlayInFlying.a(SourceFile:126) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.PacketPlayInFlying$PacketPlayInPositionLook.a(SourceFile:18) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_31]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.NullPointerException
        at me.daansander.farm.listener.PlayerPickUp.eggWavePickUp(PlayerPickUp.java:30) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[craftbukkit-1.8.4-R0.1-SNAPSHOT.jar:git-Spigot-26dfd01-5cb9b70]
        ... 21 more
    [10:02:02] [Server thread/INFO]: 0[m
    [10:02:02] [Server thread/INFO]: 543245345[m

    Code:
    Code (Text):
    @EventHandler
        public void eggWavePickUp(PlayerPickupItemEvent e) {
            Player player =  e.getPlayer();
            if(!Arena.isIngame(player)) return;
                Arena arena = Arena.getArena(player);
                if(!arena.getWave().equals(WaveType.EGG)) return;
            if(!e.getItem().getItemStack().getItemMeta().getDisplayName().contains("EGG")) return;
            Bukkit.broadcastMessage("543245345");
            for(int i = 0; i < 36; i++) {
                if(player.getInventory().getItem(i).hasItemMeta()) {
                    if (!(player.getInventory().getItem(i) == null)) {
                        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + e.getItem().getItemStack().getItemMeta().getDisplayName());
                        if (player.getInventory().getItem(i).getItemMeta().getDisplayName().contains("EGG")) {
                            player.getInventory().remove(i);
                        }
                    }
                }
            }
    }
    Sorry for bad english

    EDIT:
    It has been solved