Solved onBlockPlaceEvent never being called?

Discussion in 'Plugin Development' started by emikodo, Mar 1, 2013.

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

    emikodo

    I've been struggling to figure out what's wrong with this for a while now. At first I was trying to use it as part of a larger plugin, but right now I'll be happy if I can just get my debug statement to show up.

    What happens is I place a block and... nothing happens. No debug statement shows up. No errors are reported. The plugin loads, but for some reason that one event doesn't seem to trigger. In the original code, I had other events that worked perfectly fine. It seems to just be this one that's giving me a problem. Any help would be much appreciated!

    Code:
    package emikodo.test;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Test extends JavaPlugin{
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(new TestListener(this), this);
        getLogger().info("Test has been enabled.");
      }
     
      public void onDisable()
      {
        getLogger().info("Test has been disabled.");
      }
    }
    
    Code:
    package emikodo.test;
     
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.EventHandler;
     
    public class TestListener implements Listener{
      public Test plugin;
     
      public TestListener(Test instance)
      {
        plugin = instance;
      }
     
    (@)EventHandler
      public void onBlockPlaceEvent(BlockPlaceEvent event)
      {
        System.out.println(">>> onBlockPlaceEvent called");
      }
    }
    Note the (@)EventHandler is actually the correct syntax in my code.. I just couldn't stop it from replacing the @ with [USER=90796525] in my post..
     
  2. Offline

    Netizen

    Do you see "getLogger().info("Test has been enabled.");" ? show up?
     
  3. Offline

    Lolmewn Retired Staff

    Should work. Plugin.yml?
     
  4. Offline

    iTechRemix

    Did you import EventHandler? (I'm pretty sure you need to, but I am unable to look atm)
     
  5. Offline

    emikodo

    Yes it does show up.

    Code:
    name: Test
    main: emikodo.test.Test
    version: 1.0 
    Yes I did. I just forgot to put it in the code here.
    -EDIT- Updated original post with the correct imports.
     
  6. Offline

    Lolmewn Retired Staff

    So eeh, you do see 'Test has been enabled' then? Because I really can't think of why this wouldn't work.
     
  7. Offline

    Digi

    If you just can't figure it out, post your jar and I'll see if I can find what's wrong :p
     
  8. Offline

    emikodo

    Solved! But I have no idea why this would have caused a problem..

    Did not work:
    Code:
    package emikodo.test;
     
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.EventHandler;
     
    public class TestListener implements Listener
    Worked:
    Code:
    package emikodo.test;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class TestListener implements Listener
     
  9. Offline

    Digi

    That has zero effect, the most likely scenario is that you didn't update your plugin in /plugins and you were testing a previous version which had no listener.
     
  10. Offline

    emikodo

    Except I never had a previous version without a listener. The very first version had a listener (see the first post).
     
  11. Offline

    Digi

    I challange you to swap the imports back to the way you said they don't work, you'll see that it will still work just fine, import order does not matter at all.
     
  12. Offline

    emikodo

    I know that import order doesn't matter. That's why I said I don't know why the working version actually worked. I'm not saying that the version with the original import order does not work. I was saying it did not work. I still don't know why it didn't work.

    The import order was the only thing I changed between the two, and even then I only did it as a joke/last ditch effort. I do a lot of C++ programming and recently ran into the problem where I needed to have my include statements in a specific order, so in exasperation I decided to try switching the order of my imports for my Java program. I realize that Java should never have this problem, and I have never had this problem with any of my other plugins.

    My original thought was that maybe I had been testing a previous version and switching the imports caused Eclipse to recompile. However that doesn't explain why the first version didn't work.
     
  13. Offline

    Digi

    IDEs always compile, that's how they get the actual syntax errors in your code :p Also when you export it should also recompile as well.

    Anyway, I don't know how it could've failed but if you wanted to see what caused it you should've opened your jar with a decompiler :p
     
Thread Status:
Not open for further replies.

Share This Page