Problem with listener

Discussion in 'Spigot Plugin Development' started by robertforyou, May 1, 2015.

  1. I have a problem with listener, it doesn't shows anything. No errors, but don't work.
    That's my listener:
    Code (Text):

    package me.the_all_nighta;



    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerQuitEvent;


    public class ReporterListener implements Listener {
       
        Reporter plugin;
        public ReporterListener(Reporter plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
            this.plugin = plugin;
        }
       
        public void onPlayerLeave(PlayerQuitEvent e)
        {
            Player player = (Player) e.getPlayer();
            plugin.getLogger().info("Player left the game: " + player.getName());
        }

    }
     
    I called this on main class:
    Code (Text):

    public void onEnable() {
            new ReporterListener(this);
            getLogger().info("Plugin activated and ready for use!");
        }
     
     
    • Agree Agree x 1
  2. Also would be better practice to do this in your main class:

    getServer().getPluginManager().registerEvents(new ReporterListener(this), this);

    and then remove that code from your listener class
     
  3. I love how you tagged EventHandler and his profile description is literally

    "I get tagged a lot"
     
    • Funny Funny x 1
    • Winner Winner x 1
  4. Oh, i was thinking i have set it, because i used a project that i already has on the eclipse for some time, and i was thinking it is set so i didn't notice that. Thank you.
     
  5. Depends on what you are aiming for. If you for example want to include core code in your plugin, this is the way to go.
     
  6. I'd say it's the most reasonable way to go anyway. Otherwise you'd just be giving the Listener too much responsibility.
     
    • Agree Agree x 1