Could not pass event

Discussion in 'Plugin Development' started by jakeyray18, Jul 24, 2013.

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

    jakeyray18

    Ok so I am very very very new at java like literally started like this morning and I am have a bit of trouble with setting up a config for a plugin I am making just for personal use. To put it simply I am trying to make a plugin to cancel damage types to horses if it is set to be disabled in the config.yml. The plug works perfectly fine if I just cancel the events and totally forget about the config but I wanted to make it a bit more configurable then that. So this is the stacktrace that I get whenever the horse takes fire or fire_tick damage:

    Code:
    [SEVERE] Could not pass event EntityDamageEvent to Invinciblehorses v1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:463)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callEvent(CraftEventFactory.java:96)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:400)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:456)
        at net.minecraft.server.v1_6_R2.EntityLiving.damageEntity(EntityLiving.java:621)
        at net.minecraft.server.v1_6_R2.EntityAnimal.damageEntity(SourceFile:128)
        at net.minecraft.server.v1_6_R2.EntityHorse.damageEntity(EntityHorse.java:251)
        at net.minecraft.server.v1_6_R2.Entity.x(Entity.java:325)
        at net.minecraft.server.v1_6_R2.EntityLiving.x(EntityLiving.java:151)
        at net.minecraft.server.v1_6_R2.EntityInsentient.x(EntityInsentient.java:108)
        at net.minecraft.server.v1_6_R2.Entity.l_(Entity.java:245)
        at net.minecraft.server.v1_6_R2.EntityLiving.l_(EntityLiving.java:1227)
        at net.minecraft.server.v1_6_R2.EntityInsentient.l_(EntityInsentient.java:147)
        at net.minecraft.server.v1_6_R2.EntityHorse.l_(EntityHorse.java:740)
        at net.minecraft.server.v1_6_R2.World.entityJoinedWorld(World.java:1469)
        at net.minecraft.server.v1_6_R2.World.playerJoinedWorld(World.java:1444)
        at net.minecraft.server.v1_6_R2.World.tickEntities(World.java:1316)
        at net.minecraft.server.v1_6_R2.WorldServer.tickEntities(WorldServer.java:517)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:571)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:239)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:481)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:413)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at com.hotmail.jakeyray18.invinciblehorses.onEntityDamage(invinciblehorses.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 26 more

    Here is my code, remember as I said I literally started this today like 6 hours ago, I have read over a lot of the tutorials and still cannot seem to figure it out:

    Code:java
    1. package com.hotmail.jakeyray18;
    2.  
    3. import org.bukkit.entity.*;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.EventPriority;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.EntityDamageEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class invinciblehorses extends JavaPlugin implements Listener {
    11.  
    12. @Override
    13. public void onEnable() {
    14. this.saveDefaultConfig();
    15. this.getConfig();
    16. this.getServer().getPluginManager().registerEvents(new invinciblehorses(), this);
    17. this.getLogger().info("--Horses Config Loaded!--");
    18. }
    19.  
    20. @EventHandler(priority = EventPriority.HIGHEST)
    21. public void onEntityDamage(final EntityDamageEvent event) {
    22. if (event.isCancelled()) {
    23. return;
    24. }
    25.  
    26. if (event.getEntityType() == EntityType.HORSE) {
    27.  
    28. final EntityDamageEvent.DamageCause cause = event.getCause();
    29.  
    30. if (cause == EntityDamageEvent.DamageCause.FIRE || cause == EntityDamageEvent.DamageCause.FIRE_TICK) {
    31. if(this.getConfig().getBoolean("Disable.Fire-Damage")) {
    32. event.setCancelled(true);
    33. }
    34. }
    35. }
    36. }
    37. }


    I wrote this config.yml just for testing purposes, its literally:
    Code:
    Disable:
      Fire-Damage: true
    If anyone can see the epic screw up I made then could you point it out please? :)

    As I said, I have next to no idea what I am doing with this so just bare with me please.
     
  2. Offline

    emericask8ur

    Your config.
    If you are looking for a boolean do getConfig().getBoolean(String);
     
  3. Offline

    jakeyray18

    Added the config I am using at the moment.

    Sorry that was my bad it was something I was screwing around with earlier. It still gives the same error when I try to use if(this.getConfig.getBoolean("Disable.Fire-Damage")) {
     
  4. Offline

    emericask8ur

    Use getConfig.getBoolean("WhatEver") == true
     
  5. Offline

    jakeyray18

    tried that too, it still give me the same error whenever a horse takes fire or fire_tick damage :/ Thanks for helping though, I am so stuck.
     
  6. Offline

    Rocoty

    Is the config.yml located in the default package or outside packages? If not, that's your problem
     
  7. Offline

    jakeyray18


    My config.yml is located in the same package as my plugin.yml.
     
  8. Offline

    emericask8ur

    1. final EntityDamageEvent.DamageCause cause = event.getCause();

      Could this be it?

    DamageCause e = event.getCause();
    if(e == DamageCause.BLOCK_EXPLOSION){
    Example

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. Offline

    Rocoty

    emericask8ur Err....why would it be that? It has nothing to do with files...
     
  10. Offline

    jakeyray18

    I don't think I understand what you mean.

    Ok let me give that a shot.

    ok so I just tried your suggestion and this is what my code now looks like:

    Code:java
    1. package com.hotmail.jakeyray18;
    2.  
    3. import org.bukkit.entity.*;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.EventPriority;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.EntityDamageEvent;
    8. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class invinciblehorses extends JavaPlugin implements Listener {
    12.  
    13. @Override
    14. public void onEnable() {
    15. this.getConfig();
    16. this.saveDefaultConfig();
    17. this.getServer().getPluginManager().registerEvents(new invinciblehorses(), this);
    18. this.saveConfig();
    19. this.getLogger().info("--Horses Config Loaded!--");
    20. }
    21.  
    22. @EventHandler(priority = EventPriority.HIGHEST)
    23. public void onEntityDamage(final EntityDamageEvent event) {
    24. if (event.isCancelled()) {
    25. return;
    26. }
    27.  
    28. if (event.getEntityType() == EntityType.HORSE) {
    29.  
    30. DamageCause e = event.getCause();
    31.  
    32. if (e == DamageCause.FIRE || e == DamageCause.FIRE_TICK) {
    33. if(this.getConfig().getBoolean("Disable.Fire-Damage")) {
    34. event.setCancelled(true);
    35. }
    36. }
    37. }
    38. }
    39. }


    and the stacktrace I now get is caused by:
    Code:
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at com.hotmail.jakeyray18.invinciblehorses.onEntityDamage(invinciblehorses.java:33)
        at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 26 more
    ^^ Reading that does this not mean my error is on line 33?:
    at com.hotmail.jakeyray18.invinciblehorses.onEntityDamage(invinciblehorses.java:33)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    collielimabean

    The exception says that your file could not be found. Does it exist within the project workspace?
     
  12. Offline

    jakeyray18


    I am not sure what you mean, I created it manually in the same package as my plugin.yml, is that wrong?
     
  13. Offline

    collielimabean

    Hmm, that sounds right to me.
     
  14. Offline

    emericask8ur

    I was just pointing things out. It is obviously a yml problem. Maybe the format is wrong?
     
  15. Offline

    Ar7ific1al

    Let me see if I can help out more so than the other posters are. :/


    This stack trace points to line 33:
    Code:
    if(this.getConfig().getBoolean("Disable.Fire-Damage"))
    Your config is null - the file is likely nonexistant. Check back at your onEnable() method. Ensure your plugin is actually creating the config.yml file at your server's plugins/plugin_name folder. If the config.yml exists in the proper location on your server, remove it, and restart the server. If it comes back after server startup, then it's being created correctly. If it is being created correctly, open the file - ensure it is not empty.
     
  16. Offline

    jakeyray18



    I have tried this a few times, the config.yml is created each time I start the server after deleting the plugin_name folder and it is not empty it has this inside of it:
    Code:
    Disable:
      Fire-Damage: true

    I am really stumped on this and thanks for the help guys.
     
  17. Offline

    Rocoty

    Heh, alright. I just noticed the problem. It's staring us right in the face really.

    When you are registering the events, you are creating a new instance of your class, your main class. Doing so would result in many things failing, like the config. Because you are trying to access the config from within the new instance, which hasn't been correctly initialized from the plugin manager and blablabla, on and on. It's lots of behind the scene stuff that you don't need to worry about.

    What you do need to worry about, though, is not creating a new instance of your main class...ever. You already have an instance of your main class to pass when registering the events. The current instance:
    Code:java
    1. this.getServer().getPluginManager().registerEvents(this, this);
     
  18. Offline

    Ar7ific1al

    Rocoty I noticed this, as well. Forgot to mention it in my post, though. :/ It was late and I was meaning to go to bed long before I looked at this thread. Hopefully this will solve the OP's problem. :3
     
  19. Offline

    Chiller

    jakeyray18 Try refreshing your project then build it and try that
     
  20. Offline

    jakeyray18


    I am not sure I quite understand what you mean, as I said I am very new to this. Thanks for the help :)
     
  21. Offline

    emericask8ur

    Just create a new class for the events.
     
Thread Status:
Not open for further replies.

Share This Page