Plugin won't send message to player when he/she logs in

Discussion in 'Plugin Development' started by ryanshah, Jan 4, 2014.

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

    ryanshah

    Hey everyone, In my PlayerLoginEvent (Yes... it is registered as EVERYTHING else works) I'm trying to send a message to the player like so:

    Code:java
    1. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "[AutoKits]" + ChatColor.WHITE + " - " + "You do not have access to AutoKits and therefore it was cancelled.");


    and here is how i start the event:

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onPlayerLoginCheck(final PlayerLoginEvent e) {
    3. }


    And well, it doesn't send the message to the player :(

    Does anyone think they know why?

    P.s. im testing on a server with essentials, could that be why?
     
  2. Offline

    Dako

    remove the final modifier
     
  3. Offline

    sgavster

    Use PlayerJoinEvent.
     
  4. Offline

    PolarCraft

    And also instead of doing e.getPlayer().sendMessage. . . you should do Player p = e.getPlayer() . . . so that you do not have to keep doing e.getPlayer.
     
  5. Offline

    sgavster

    PolarCraft No..

    Wrong.. You should do it however you want.. There is no need to make a player variable..
     
    thomasb454 likes this.
  6. Offline

    ryanshah

    I have to use the final modifier, or my other code won't work... I'm instantiating something:

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onPlayerLoginCheck(final PlayerLoginEvent e) {
    3. if(e.getPlayer().hasPermission("autokits.recieve")) {
    4. Interval countdown = new Interval(this.pluginInstance, 0, 1200 * pluginInstance.getConfig().getInt("interval")) {
    5. //some methods inside here
    6. };
    7. countdown.run();
    8. this.pluginInstance.getLogger().info("Counter started for player - " + e.getPlayer().getDisplayName());
    9. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "[AutoKits]" + ChatColor.WHITE + " - " + "You will start receiving kits every " + pluginInstance.getConfig().getInt("interval") + " minute(s)");
    10. } else {
    11. this.pluginInstance.getLogger().info("Counter denied for player - " + e.getPlayer().getDisplayName() + " due to lack of permissions");
    12. e.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "[AutoKits]" + ChatColor.WHITE + " - " + "You do not have access to AutoKits and therefore it was cancelled.");
    13. }
    14. }


    PlayerJoinEvent seems to work well :D but I thought it was only called when the player first joins?
     
  7. Offline

    PhilipsNostrum

    I don't think there's any event for first join. The thing is that on PlayerLoginEvent the player hasn't actually spawned (I believe).
     
    ryanshah likes this.
Thread Status:
Not open for further replies.

Share This Page