Can't get events to fire

Discussion in 'Plugin Development' started by _bryan, Feb 7, 2016.

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

    _bryan

    I've come across a hundred different pages but I haven't found any that have helped me solve my problem.

    I'm creating a class that's acting as the plugin and event handler.

    Code:
    public class SapPlayerReporter extends JavaPlugin implements Listener {
        ...
    }
    
    The plugin is being loaded fine, I can see in the output that it's being enabled:

    [​IMG]

    In my code, I've implemented the methods and added the proper annotation:

    Code:
    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        this.getLogger().log(Level.INFO, "Player " + event.getPlayer().getDisplayName() + " joined. Creating client.");
        ...
    }
    
    And when enabling the plugin, I've registered the listener and plugin:

    Code:
    @Override
    public void onEnable() {
        this.getLogger().log(Level.INFO, "SapPlayerReporter has been enabled.");
        this.getServer().getPluginManager().registerEvents(this, this);
    }
    
    I'm using 1.8.8 and I can't really figure out why none of my events are firing. Everything is done as it should be but none of my events are firing. I'm not sure where else to look at this point.
     
  2. Offline

    teej107

    @_bryan So to make sure I'm getting this right.
    This isn't getting logged? May we see the whole class?
     
  3. Offline

    _bryan

    No I don't see this message in the log. Here is the entire class:

    Code:
    package nl.dimensys.minecraft.spigot;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.util.*;
    import java.util.logging.Level;
    
    /**
     * Created by abramsbn on 7-2-2016.
     */
    public class SapPlayerReporter extends JavaPlugin implements Listener {
    
        public SapPlayerReporter() {
        }
    
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            this.getLogger().log(Level.INFO, "Player " + event.getPlayer().getDisplayName() + " joined. Creating client.");
        }
    
        @EventHandler
        public void onQuit(PlayerQuitEvent event) {
            this.getLogger().log(Level.INFO, "Player " + event.getPlayer().getDisplayName() + " quit. Closing client.");
        }
    
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
            this.getLogger().log(Level.INFO, "Player " + event.getPlayer().getDisplayName() + " moved.");
        }
    
        @Override
        public void onEnable() {
            this.getLogger().log(Level.INFO, "SapPlayerReporter has been enabled.");
            this.getServer().getPluginManager().registerEvents(this, this);
        }
    
        @Override
        public void onDisable() {
            this.getLogger().log(Level.INFO, "SapPlayerReporter has been disabled.");
        }
    
    }
    
    
     
  4. Offline

    Xerox262

    @_bryan Try removing the constructor, constructors in the JavaPlugin class sometimes cause errors, however they're normally before the plugin enables, but it doesn't hurt to try.

    Also, instead of having to do Logger#log(Level, String); you can do Logger#info(String); along with the other levels.
     
  5. Offline

    teej107

    I'm surprised it didn't. You shouldn't have constructors in the JavaPlugin extended class.
     
  6. Offline

    _bryan

    Durp, the constructor has been removed and now it's working fine. That's a rather odd one but thanks for the solution.
     
  7. Offline

    Xerox262

    @_bryan Glad it helped. Don't forget to set the thread to solved :)
     
Thread Status:
Not open for further replies.

Share This Page