Solved Player Join Event

Discussion in 'Plugin Development' started by FreeMotion45, Sep 28, 2015.

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

    FreeMotion45

    Hey, I am pretty new to coding, but I believe I've done everything right.

    Inside the game, the new join message won't appear.

    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event)
        {
            if(event.getPlayer().hasPermission("al.joinvip"))
            {
                Player p = event.getPlayer();
            event.setJoinMessage(p.getDisplayName() + ChatColor.YELLOW + " has joined !");
            }
        }
       
    }
    And in my Main class :

    Code:
    public void onEnable()
        {
            logger.info("Enabled");
            registerEvents(this, new JoinEvent());
        }
       
       
        private void registerEvents(Server Server, JoinEvent JoinEvent)
        {   
        }
    Yes I know this may be some really newbie mistake.
     
  2. Offline

    FisheyLP

    You didn't registerd the events
     
  3. Offline

    RoboticPlayer

    Instead of doing your registerEvents method like you have it, do this:
    Code:
    public void registerEvents() {
        //This first line is optional, makes it faster with lots of classes
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(new [listener class], this);
    }
     
  4. Offline

    FisheyLP

    Oooooor just this in onEnable:
    Bukkit.getPluginManager().registerEvents(new ListenerClass(), this);
     
  5. Offline

    RoboticPlayer

    Well if you want to have a separate method (especially if you have lots of listener classes), it is cleaner to do it my way. However, they both work.
     
  6. Offline

    FreeMotion45

    Well now I have this :

    Code:
    public void registerEvents() {
            PluginManager pm = Bukkit.getServer().getPluginManager();
            pm.registerEvents(new JoinEvent(), this);
        }
    But it still won't show me any messages when I login.

    And again the other class :

    Code:
    public class JoinEvent implements Listener
    {
        public static Server plugin;
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event)
        {
            if(event.getPlayer().hasPermission("al.joinvip"))
            {
                Player p = event.getPlayer();
            event.setJoinMessage(p.getDisplayName() + ChatColor.YELLOW + " has joined !");
            }
        }
       
    }
    Thanks for posting and helping
     
  7. Offline

    FisheyLP

    1. Does the plugin load? 2. Try adding debug messages
     
  8. Offline

    FreeMotion45

    The plugin is loading, no errors in console.
     
  9. Offline

    FreeMotion45

    Fixed, I forgot to add @Override on-top of public void onEnable().

    Thanks for those who tried to help :)
     
Thread Status:
Not open for further replies.

Share This Page