Solved Could not pass event BlockBreakEvent

Discussion in 'Plugin Development' started by WannabeAProGamer, May 18, 2016.

Thread Status:
Not open for further replies.
  1. I got the following error in my plugin after breaking a block to test it:
    Code:
    [17:05:43 ERROR]: Could not pass event BlockBreakEvent to SpecPick v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[craftbukkit-1.8.jar:git-Bukkit-7019900]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.8.jar:git-Bukkit-7019900]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:285) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.a(PlayerInteractManager.java:121) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:573) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockDig.a(SourceFile:40) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockDig.a(SourceFile:10) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_72]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_72]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:656) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:609) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:517) [craftbukkit-1.8.jar:git-Bukkit-7019900]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
    Caused by: java.lang.NullPointerException
            at me.wannabeaprogamer.MiningListener.veinPickModifier(MiningListener.java:27) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_72]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_72]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_72]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_72]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit-1.8.jar:git-Bukkit-7019900]
            ... 16 more
    I don't know what my mistake is, and no, I didn't forget to do
    Code:
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
     
  2. Offline

    Gonmarte

    You have a NPE on the 27 line of your class MiningListerner.
    If you could give me your class i would apreciate.
    Also, you should learn by your own how to troubleshot your own erros, so you wouldnt need any help on this - https://bukkit.org/threads/how-to-r...ubleshoot-your-own-plugins-by-yourself.32457/
     
  3. This is the MiningListener class:
    Show Spoiler

    Code:
    package me.wannabeaprogamer;
    
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class MiningListener implements Listener
    {
        public MiningListener(VeinMinerPicks plugin)
        {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
        @EventHandler
        public void veinPickModifier(BlockBreakEvent e)
        {
            ItemStack is = e.getPlayer().getItemInHand();
            ItemMeta im = is.getItemMeta();
            List<String> lore = im.getLore();
            Block broken = e.getBlock();
            Location center = broken.getLocation();
            World world = broken.getWorld();
            if(lore.contains(ChatColor.GOLD + "Special pickaxe,"))
            {
                for(String loreString : lore)
                {
                    String ench = loreString.substring(0, loreString.indexOf(" "));
                    int value = Integer.parseInt(loreString.substring(loreString.indexOf(" ") + 1, loreString.length()));
                    switch(ench)
                    {
                    case "§7Veinmining":
                        Location vein1 = center;
                        vein1.setX(vein1.getX() + value);
                        vein1.setY(vein1.getY() + value);
                        vein1.setZ(vein1.getZ() + value);
                       
                        Location vein2 = center;
                        vein2.setX(vein2.getX() - value);
                        vein2.setY(vein2.getY() - value);
                        vein2.setZ(vein2.getZ() - value);
                       
                        Location vein3;
                        for(double x = vein1.getX(); x <= vein2.getX(); x++) {
                            for(double y = vein1.getY(); y <= vein2.getY(); y++) {
                                for(double z = vein1.getZ(); z <= vein2.getZ(); z++) {
                                    vein3 = new Location(world, x, y, z);
                                    vein3.getBlock().breakNaturally();
                            }
                          }
                        }
                        break;
                    case "§7Flatvein":
                        Location flat1 = center;
                        flat1.setX(flat1.getX() + value);
                        flat1.setZ(flat1.getZ() + value);
                       
                        Location flat2 = center;
                        flat2.setX(flat2.getX() - value);
                        flat2.setZ(flat2.getZ() - value);
                       
                        Location flat3;
                        for(double x = flat1.getX(); x <= flat2.getX(); x++) {
                            for(double z = flat1.getZ(); z <= flat2.getZ(); z++) {
                                flat3 = new Location(world, x, center.getY(), z);
                                flat3.getBlock().breakNaturally();
                        }
                    }
                    break;
                    }
                }
            }
        }
    }
    
     
  4. Offline

    I Al Istannen

    @WannabeAProGamer
    1. Find Java file. Check.

    2. Find error line. Check:
    Line 27: "List<String> lore = im.getLore();".​

    3. Look at error:
    Null pointer exception ==> Something is null and a method was called on this null object​

    4. Thinking:
    What do you think can be null here?​

    EDIT: Not meant to be offensive, just want you to go through the troubleshooting steps with me ;)
     
  5. Offline

    Gonmarte

    I think you forgot to set the item meta of the item.
     
  6. I understand that :)
    I fixed it after reading the post @Gonmarte linked...
    THIS error at least... now I'm trying to fix another
    Thank you both for helping!
     
  7. Offline

    I Al Istannen

  8. Fortunately there are not more bugs in the code...

    Just more the code can reach:p

    Oh, and they are not little bugs... they stop the entire plugin from working:mad:
     
Thread Status:
Not open for further replies.

Share This Page