Solved BlockBreakEvent Exception

Discussion in 'Plugin Development' started by SeniorCluckers, Jul 19, 2015.

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

    SeniorCluckers

    I don't know what's wrong but everytime I use the config to set the msg it does not work. I get a blockbreakevent exception.

    Code:
          @EventHandler
          public void onBreakBlock(BlockBreakEvent e)
          {
            if (e.getBlock().getType().equals(Material.DIAMOND_ORE))
            {
              if (diamonds.contains(e.getBlock())) {
                return;
              }
              int i = getDiamondsAround(e.getBlock()) - 1;
              Bukkit.broadcastMessage(Main.instance.getConfig().getString("broadcast-message").replace("&", "ยง").replace("%player%", e.getPlayer().getName()).replace("%count%", String.valueOf(i)));
            }
          }
        
          static HashSet<Block> diamonds = new HashSet();
        
          public int getDiamondsAround(Block diamond)
          {
            int count = 1;
            int x1 = diamond.getX() - 1;
            int x2 = diamond.getX() + 1;
            int y1 = diamond.getY() - 1;
            int y2 = diamond.getY() + 1;
            int z1 = diamond.getZ() - 1;
            int z2 = diamond.getZ() + 1;
            for (int x = x1; x <= x2; x++) {
              for (int y = y1; y <= y2; y++) {
                for (int z = z1; z <= z2; z++)
                {
                  Block b = new Location(diamond.getWorld(), x, y, z).getBlock();
                  if ((b.getType().equals(Material.DIAMOND_ORE)) &&
                    (!diamonds.contains(b)))
                  {
                    diamonds.add(b);
                    count += getDiamondsAround(b);
                  }
                }
              }
            }
            return count;
          }
     
  2. Offline

    Hawktasard

    @SeniorCluckers
    You should post the full error, it will help us fix your problem.
    edit: I'm 95% sure I know what your error is though.
     
  3. Offline

    SeniorCluckers

    @Hawktasard
    Code:
    [19:21:18] [Server thread/ERROR]: Could not pass event BlockBreakEvent to HCFUtils v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[Spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:514) [Spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:499) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:264) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.a(PlayerInteractManager.java:192) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:565) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(PacketPlayInBlockDig.java:41) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(PacketPlayInBlockDig.java:65) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1649]
    Caused by: java.lang.NullPointerException
        at me.seniorcluckers.hcfutils.Events.onBreakBlock(Events.java:28) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[Spigot.jar:git-Spigot-1649]
     
  4. Offline

    seanliam2000

Thread Status:
Not open for further replies.

Share This Page