[Severe] Could not pass event BlockBreakEvent

Discussion in 'Plugin Development' started by Metamist, Jul 6, 2012.

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

    Metamist

    I'm trying to detect when a user breaks a block but it's just returning an error. I am using the new event system.

    Error:
    Code:java
    1. 16:24:29 [ALLVARLIG] Could not pass event BlockBreakEvent to BlockBanner
    2. org.bukkit.event.EventException
    3. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    4. va:304)
    5. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    6. a:62)
    7. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    8. ava:460)
    9. at net.minecraft.server.ItemInWorldManager.breakBlock(ItemInWorldManager
    10. .java:220)
    11. at net.minecraft.server.ItemInWorldManager.dig(ItemInWorldManager.java:1
    12. 05)
    13. at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:537)
    14. at net.minecraft.server.Packet14BlockDig.handle(SourceFile:43)
    15. at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    16. at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    17. at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    18. 8)
    19. at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
    20. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
    21. at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    22. Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    23. at com.iougaming.BlockBanner.BlockBannerListener.onBlockBreak(BlockBanne
    24. rListener.java:46)
    25. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    26. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    27. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    28. at java.lang.reflect.Method.invoke(Unknown Source)
    29. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    30. va:302)
    31. ... 12 more


    BlockListener:
    Code:java
    1. @EventHandler
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. Player player = event.getPlayer();
    4. Block b = event.getBlock();
    5. List<String> bannedIDs = plugin.getConfig().getStringList("BannedIDs");
    6.  
    7. for(String string : bannedIDs)
    8. {
    9. String testID = "0";
    10. String[] args = string.split("=");
    11. String[] args2 = string.split(";");
    12.  
    13. if(string.contains("=") && !string.contains(";")) testID = args[0];
    14. else if(!string.contains("=") && string.contains(";")) testID = args2[0];
    15. else if(string.contains("=") && string.contains(";")) testID = args[0];
    16. else if(!string.contains("=") && !string.contains(";")) testID = string;
    17.  
    18. if(string.contains(";"))
    19. {
    20. player.sendMessage(testID + " , " + args2[0] + " , " + args2[1]);
    21. }
    22.  
    23. if(b.getTypeId() == Integer.parseInt(testID))
    24. {
    25. if(args2[1].contains("place") || args2[1].contains("craft") || !player.hasPermission(args[1].split(";")[0]) || args[1].equals("op") && !player.isOp())
    26. {
    27. String placeMessage = plugin.getConfig().getString("Config.MessagePlace").replace("%BLOCK%", Material.getMaterial(b.getTypeId()).toString());
    28. player.sendMessage(placeMessage.replaceAll("&([a-f0-9])", ChatColor.COLOR_CHAR + "$1"));
    29. event.setCancelled(true);
    30. }
    31. if (!string.contains("=") && !string.contains(";"))
    32. {
    33. String placeMessage = plugin.getConfig().getString("Config.MessagePlace").replace("%BLOCK%", Material.getMaterial(b.getTypeId()).toString());
    34. player.sendMessage(placeMessage.replaceAll("&([a-f0-9])", ChatColor.COLOR_CHAR + "$1"));
    35. event.setCancelled(true);
    36. }
    37. }
    38. }
    39. }
     
  2. Offline

    Firefly

    The first or second index of your array doesn't xist and you are trying to access it.
     
  3. Offline

    Metamist

    I'm using the exact same code on BlockPlaceEvent and it's not returning any errors?
     
  4. Offline

    Firefly

    What's on line 46 of your listener?
     
  5. Offline

    Metamist

    Oops, the error message was from before i tried to remove the BlockPlaceEvent, but it seems i am actually getting the same error from BlockPlaceEvent. This is the line:
    Code:java
    1. if(args2[1].contains("place") || args2[1].contains("craft") || !player.hasPermission(args[1].split(";")[0]) || args[1].equals("op") && !player.isOp())

    It worked perfectly like an hour ago
     
  6. Offline

    Firefly

    As far as the stack trace is concerned, you're trying to access an index that is not currently in your Array. I don't quite see what you put in the array: block id's? Maybe retrieving it from config and splitting the ";" is not actually putting anything in your array.
     
  7. Offline

    Metamist

    The list that it's getting the IDs from looks like this:
    Code:
    BannedIDs:
    - 46=permission.to.allow;place
    - 47=op;break
    - 48;place
    I am debugging "testID" and "args2" which is getting it fine, i'll debug "args" and see what it says.
    Edit: Yup, the "args" is correct. It is working fine even though the error occur. Should i just use try/catch and ignore it completely?

    I seem to have fixed the error. In my permissions, i had "- 48;place,break" to allow placing and breaking, but because it only found break, it cancelled the event. All i did was to add "!args2[1].contains("place")" and that fixed it.

    Thanks for your help :D

    Code:java
    1. if((args2[1].contains("break") && !args2[1].contains("place")) || args2[1].contains("craft") || !player.hasPermission(args[1].split(";")[0]) || args[1].equals("op") && !player.isOp())


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page