"NullPointerException" in Event

Discussion in 'Plugin Development' started by iAmReprisal, Apr 25, 2017.

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

    iAmReprisal

    Hello,

    I quickly coded this plugin for an enchant that will be added to a pickaxe.
    The pickaxe works as should, but I randomly get this error message in console. [Stack Trace]

    Stack Trace Error (open)
    Code:
    25.04 21:48:01 [Server] ERROR Could not pass event BlockBreakEvent to CEParadox v1.0
    25.04 21:48:01 [Server] INFO org.bukkit.event.EventException
    25.04 21:48:01 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerInteractManager.breakBlock(PlayerInteractManager.java:286) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:215) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:637) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_121]
    25.04 21:48:01 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_121]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
    25.04 21:48:01 [Server] INFO Caused by: java.lang.NullPointerException
    25.04 21:48:01 [Server] INFO at me.reprisal.CEParadox.blockBreak(CEParadox.java:48) ~[?:?]
    25.04 21:48:01 [Server] INFO at sun.reflect.GeneratedMethodAccessor588.invoke(Unknown Source) ~[?:?]
    25.04 21:48:01 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    25.04 21:48:01 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    25.04 21:48:01 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-e4d4710-e1ebe52]
    25.04 21:48:01 [Server] INFO ... 17 more



    Here is my code. The error says it's occurring on the line of the if statement.

    Code (open)
    Code:
        public void blockBreak(BlockBreakEvent e) {
    
            Player player = e.getPlayer();
            Block b = e.getBlock();
           
            if (player.getItemInHand().getType() == Material.DIAMOND_PICKAXE && player.getItemInHand().getItemMeta().getLore().contains(ChatColor.GRAY + "Aleph I")) {
                Block block;
                for (int xOff = -1; xOff <= 1; ++xOff) {
                    for (int yOff = -1; yOff <= 1; ++yOff) {
                        for (int zOff = -1; zOff <= 1; ++zOff) {
                            block = b.getRelative(xOff, yOff, zOff);
                            WorldGuardPlugin worldGuard = getWorldGuard();
                            Vector pt = toVector(block);
                            RegionManager regionManager = worldGuard.getRegionManager(player.getWorld());
                            ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
                            if (set.allows(DefaultFlag.BLOCK_BREAK)) {
                                block.breakNaturally();
                            }
                        }
                    }
                }
            }
        }



    Thanks in advance to anyone that can help! :D
     
  2. Offline

    Zombie_Striker

    @iAmReprisal
    1. Why are you still on 1.8? Please read this.
    2. The item in the player's hand can be null. Make sure it is not null before checking the type.
    3. The item may not have an item meta. Check if it hasItemMeta before getting it.
    4. Instead of continually getting the world gaurd instance and the region manager, get it once outside of the for loop.
     
  3. Offline

    iAmReprisal

    @Zombie_Striker

    I checked if it was bot null, and if it hasItemMeta, but I'm still getting the error.
     
  4. Offline

    Zombie_Striker

    @iAmReprisal
    Is it the same error? If so, that means there is something on line 48 that has to be null.
     
Thread Status:
Not open for further replies.

Share This Page