Error using BreakBlockEvent

Discussion in 'Spigot Plugin Development' started by Xuho, May 1, 2017.

  1. I get this error when a player break a block

    Code (Text):
    [22:21:19 ERROR]: Could not pass event BlockBreakEvent to HowhitSurvival v1.0
    va:310) ~[spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at net.minecraft.server.v1_8_R3.PlayerInteractManager.breakBlock(PlayerI [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractMa [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(
    :614) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40) [s
            at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10) [s
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$
    3) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at java.util.concurrent.Executors$ Source) [
            at Source) [?:1.8.0_131]
            at net.minecraft.server.v1_8_R3.SystemUtils.a( [spig
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(
    18) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(
    67) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(
    57) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
    :560) [spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            at Source) [?:1.8.0_131]
    Caused by: java.lang.NullPointerException
            at ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    va:306) ~[spigot-1.8.7.jar:git-Spigot-f928e7a-994b2aa]
            ... 17 more
    Error code:
    Code (Text):
            if (e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore().contains("asd")) {
    Thanks in advance.
  2. You need to check to see if itemInHand is null before you check to see if it has meta. Then if it also has meta you can get the lore.

    Items with no lore or a null item will cause this error

    Sent from my iPhone using Tapatalk
  3. #getItemInHand returned null, or it doesn't have a lore.
  4. thanks, I'll try it.
  5. I still get the error.
    I do this:
    Code (Text):
    if (!e.getPlayer().getInventory().getItemInHand().equals(null) || e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore().equals(null)) {
        if (e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore().contains("asd")) {
    } else if (e.getPlayer().getInventory().getItemInHand().equals(null) || e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore().equals(null)) {
  6. Don't check with .equals if something is null. Use the compare operator (==).
    Code (Text):
    if (e.getPlayer().getInventory().getItemInHand() != null && e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore() == null) {
    /*do something*/
    Is it correct that you do a null check for the lore and calling the contains method if the check is sucessful?
  7. You should do if itemstack == null && ItemStack.hasMeta()

    Before checking the lore / display name
    Sent from my iPhone using Tapatalk
  8. ty, It's working but I have a doubt Why does not it work using .equals? In theory it does the same thing as the ==
  9. Equals is for string comparisons when you're using enum or objects use ==

    Sent from my iPhone using Tapatalk
  10. thanks for the explanation
    Ups, I did not realize this, when i break with the empty iteminhand it still gives error

    Code (Text):
            if (e.getPlayer().getInventory().getItemInHand() != null && e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore() != null) {
  11. BananaPuncher714


    You don't check if it's null. You have to check if the type is equal to Material.AIR. Then you can check the lore.
    Code (Text):
    if ( item.getType() != Material.AIR && item.hasItemMeta() && item.getItemMeta().hasLore() ) {
        // Do stuff
  12. Haaaa, no.

    Any retrieval from an inventory will return null for an empty itemstack. InventoryClickEvent#getCursor returns AIR.
    • Agree Agree x 1
  13. Make sure to check if the item meta data exist ( != null) and if the lore exists ( != null)
  14. I Tried but still no working