Solved BlockBreakEvent Help

Discussion in 'Plugin Development' started by jthort, Jan 3, 2014.

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

    jthort

    Hey I need some help with this, when I run it it gives this error:
    Code:
    rver.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    Bukkit-1.7.2-R0.2-b2974jnks]
    rver.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    kkit-1.7.2-R0.2-b2974jnks]
    lArgumentException: File cannot be null
    ns.lang.Validate.notNull(Validate.java:203) ~[craftbu
    0.2-b2974jnks]
    guration.file.YamlConfiguration.loadConfiguration(Yam
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    n.java.JavaPlugin.reloadConfig(JavaPlugin.java:118) ~
    -1.7.2-R0.2-b2974jnks]
    n.java.JavaPlugin.getConfig(JavaPlugin.java:112) ~[cr
    7.2-R0.2-b2974jnks]
    unter.onBlockBreak(StarHunter.java:526) ~[?:?]
    veMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
     
    veMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
     
    gatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
     
    t.Method.invoke(Unknown Source) ~[?:1.7.0_25]
    n.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    it-Bukkit-1.7.2-R0.2-b2974jnks]
    This is my onEnable:

    Code:
    @Override
        public void onEnable(){
     
            list.add("GOLD_BLOCK");
            list.add("IRON_BLOCK");
            list.add("BOOK");
         
            logger.info("StarHunter has been enabled");
            PluginManager pm = getServer().getPluginManager();
            final FileConfiguration config = this.getConfig();
         
              pm.registerEvents(this, this);
            pm.registerEvents(new fallingblocks(this), this);
         
            config.addDefault("Star Size", 4);
            config.addDefault("Cooldown Timer", 72000);
            config.addDefault("TP Delay", 100);
            config.addDefault("Mining Time", 1200);
            config.addDefault("Max X", 1000);
            config.addDefault("Max Z", 1000);
            config.addDefault("Min X", 100);
            config.addDefault("Min Z", 100);
            config.addDefault("Star Drops Random", true);
            config.addDefault("If Random is false, list the items you want dropped from the star", list);
         
            config.options().copyDefaults(true);
            saveConfig();
        }
    This is my Event:

    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void onBlockBreak(BlockBreakEvent event){
    3.  
    4. Player p = event.getPlayer();
    5. final Block a = event.getBlock();
    6. Location world = a.getLocation();
    7.  
    8. if(fallingblocks.blocks.contains(a.getLocation())){
    9.  
    10. if (a.getType() == Material.DIAMOND_BLOCK){
    11.  
    12. world.getBlock().setType(Material.AIR);
    13.  
    14. for(int e = 0; e < 4; e++){
    15. Random rand = new Random();
    16. Material[] materiallists = Material.values();
    17.  
    18.  
    19. int size = materiallists.length;
    20. int index = rand.nextInt(size);
    21.  
    22.  
    23. Material randomMaterial = materiallists[index];
    24. ItemStack item = new ItemStack(randomMaterial);
    25. Material items = item.getType();
    26.  
    27. world.getBlock().setType(items);
    28.  
    29. }
    30.  
    31. int temp = (getConfig().getInt("Mining Time"))/20;
    32. String tim;
    33. if(temp > 59){
    34. temp = temp/60;
    35. tim = "minutes";
    36. }else{
    37. tim = "seconds";
    38. }
    39. String user = p.getName();
    40.  
    41. p.sendMessage(ChatColor.GOLD + "[StarHunter] " + ChatColor.YELLOW + "You have " + ChatColor.RED + temp + " " + tim + ChatColor.YELLOW + " before this star gets removed");
    42. Bukkit.broadcastMessage(ChatColor.GOLD + "[StarHunter] " + ChatColor.RED + user + ChatColor.YELLOW + " has reached the stars core! There is " + ChatColor.RED + temp + " " + tim + ChatColor.YELLOW + " until the next hunt begins.");
    43.  
    44. messages = 0;
    45.  
    46. timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    47. public void run(){
    48. int msg1 = (getConfig().getInt("Cooldown Timer"))/20;
    49. int msg2 = (getConfig().getInt("Cooldown Timer")* 2/3)/20;
    50. int msg3 = (getConfig().getInt("Cooldown Timer")* 1/3)/20;
    51. String time;
    52. switch(messages){
    53.  
    54. case 0:
    55. fallingblocks.removal();
    56. if(msg1 < 60){
    57. time = "Seconds";
    58. }else{
    59. msg1 = msg1/60;
    60. time = "Minutes";
    61. }
    62. Bukkit.broadcastMessage(ChatColor.GOLD + "[StarHunter] " + ChatColor.YELLOW + "The Star Hunt starts in " + msg1 + " " + time);
    63. messages++;
    64. break;
    65. case 1:
    66. if(msg2 < 60){
    67. time = "Seconds";
    68.  
    69. }else{
    70. msg2 = msg2/60;
    71. time = "Minutes";
    72. }
    73. Bukkit.broadcastMessage(ChatColor.GOLD + "[StarHunter] " + ChatColor.YELLOW + "The Star Hunt starts in " + msg2 + " " + time);
    74. messages++;
    75. break;
    76. case 2:
    77. if(msg3 < 60){
    78. time = "Seconds";
    79. }else{
    80. msg3 = msg3/60;
    81. time = "Minutes";
    82. }
    83. Bukkit.broadcastMessage(ChatColor.GOLD + "[StarHunter] " + ChatColor.YELLOW + "The Star Hunt starts in " + msg3 + " " + time);
    84. messages++;
    85. break;
    86. case 3:
    87. Bukkit.getScheduler().cancelTask(timer);
    88.  
    89. messages = 0;
    90.  
    91. fallingblocks.loc();
    92. break;
    93.  
    94. }
    95.  
    96. }
    97.  
    98. }, getConfig().getInt("Mining Time"), getConfig().getInt("Cooldown Timer")/3);
    99.  
    100.  
    101. }else if(getConfig().getBoolean("Star Drops Random") == true){
    102. p.sendMessage("true");
    103.  
    104. }else{
    105. p.sendMessage("false");
    106. }
    107.  
    108.  
    109.  
    110.  
    111. }
    112. }

    It has something to do with the elseif statement at the end
     
  2. Offline

    16davidjm6

    jthort It has to do with line 526 in your code. Could you please point out which line line number 526 is for us?

    It seems to be something with a null file. The only file I'm seeing is your config file. Make sure that when you compile your jar, that the config is included
     
  3. Offline

    jthort

    16davidjm6
    Sorry for the later response, here is line 526:
    Code:
    }else if(getConfig().getBoolean("Star Drops Random") == true){
    Here is my config file:
    Code:
    Star Size: 4
    Star Material: GOLD_BLOCK
    Cooldown Timer: 72000
    TP Delay: 100
    Mining Time: 1200
    Max X: 1000
    Max Z: 1000
    Min X: 100
    Min Z: 100
    Star Drops Random: false
    If Random is false, list the items you want dropped from the star:
    - GOLD_BLOCK
    - IRON_BLOCK
    - BONE
    And yes you are correct, because if I remove the else if, it works as I said before. I really don't know what's wrong with that line, am I grabbing the boolean wrong?
     
  4. Offline

    werter318

    jthort I don't think you can use spaces, can you?
     
  5. Offline

    jthort

    werter318 I tried it without spaces, doesn't change anything. I'm also having some trouble where if I put a message such as "test" it says it multiple times on the block break event. Even if it's only in the code once, it repeats itself.

    Edit: For example I put
    Code:
    p.sendMessage("test");
    at the top of the event, in game it says "test" "false" "test" when I break one block
     
  6. Offline

    16davidjm6

    jthort

    Is that your ENTIRE error log? (also there appears to be a few characters missing at the beginning of each line)

    Getting the entire error log will better help us figure out where or why the config went null, because that definitely appears to be where the problem is. (Note that you might have a second error message in the loading of the plugin. Might be best to put your entire console into pastebin for us to see)
     
  7. Offline

    Nateb1121

    Just so you know, with the getConfig().get("SJSJSH") thing if the entry doesn't exist in your config it just returns NULL it won't tell you it doesn't exist, but it will just return null. So make sure that path really exists in your config.yml
     
  8. Offline

    jthort

    Nateb1121 Yeah but as you see on my onEnable, it's default is not null, so there is now way it could return null

    16davidjm6 I just noticed that, let me get a full log:

    Code:
    [15:36:30 ERROR]: Could not pass event BlockBreakEvent to StarHunt v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.
    va:427) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.j
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager
    ava:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager
    ava:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PlayerInteractManager.breakBlock(Playe
    nteractManager.java:263) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PlayerInteractManager.a(PlayerInteract
    nager.java:191) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.ja
    :548) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInBlockDig.a(SourceFile:53)
    raftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInBlockDig.handle(SourceFile
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:1
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [cr
    tbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.ja
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.IllegalArgumentException: File cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craft
    kkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Y
    lConfiguration.java:171) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:118)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:112) ~[
    aftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at StarHunter.StarHunter.onBlockBreak(StarHunter.java:529) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7
    _25]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7
    _25]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?
    .7.0_25]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.
    va:425) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            ... 15 more
     
  9. Offline

    Nateb1121

    Those two error messages are different...
     
  10. Offline

    jthort

    I just ran the plugin again and broke the block and this happened
     
  11. Offline

    16davidjm6

    Nateb1121

    even though the error is different, it still has these things:

    Caused by: java.lang.IllegalArgumentException: File cannot be null

    and

    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Y
    lConfiguration.java:171) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]

    jthort

    Scroll up in your console. This error that you are giving us is happening when you attempt to break the block. What about on server startup, before anyone even logs in to your server. Are you getting any errors there?

    The error appears to be the config being null. This typically happens if something is wrong on start up. Check to see if there is any error up in the startup of your server.
     
  12. Offline

    jthort

    16davidjm6 No there is not, the plugin works perfectly, but every time you break a block it displays that error. It still shows the messages, so it's working.
     
  13. Offline

    jthort

  14. Offline

    xTigerRebornx

    jthort Is the Listener in your main class? And can we see the entire class?
     
  15. Offline

    Jazed

    I don't think your variable names in your config can contain any spaces, try changing those to dashes (-).
     
  16. Offline

    jthort

    xTigerRebornx Yeah it's in the main class, the class is over 700 lines, plus I would rather not share it.

    Jazed I'll try that when I get the chance

    I figured out the issue, I imported it in both of my classes, and my other class is an extension of the first one. So it's running it twice. Thanks to 16davidjm6 werter318 Nateb1121 Jazed for all your help, Solved!

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

Share This Page