Solved onLoginEvent

Discussion in 'Plugin Development' started by amatokus, Jul 22, 2014.

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

    amatokus

    Hi I'm working on the onLoginEvent, and here is my problem:

    If a player is not contained in a list he will recieve a message(the message is set in config)

    but the code doesn't work(I have no errors):

    Code:java
    1. File side1File;
    2. FileConfiguration side1Config;
    3.  
    4. File side2File;
    5. FileConfiguration side2Config;
    6.  
    7. List<String> listt1;
    8. List<String> listt2;
    9.  
    10.  
    11.  
    12.  
    13. @EventHandler
    14. public void onConnect(PlayerLoginEvent event){
    15. side1File = new File(plugin.getDataFolder(), plugin.getConfig().getString("side_1.name")+"_players.yml");
    16. side1Config = YamlConfiguration.loadConfiguration(side1File);
    17.  
    18. side2File = new File(plugin.getDataFolder(), plugin.getConfig().getString("side_2.name")+"_players.yml");
    19. side2Config = YamlConfiguration.loadConfiguration(side2File);
    20.  
    21. listt1 = side1Config.getStringList("players");
    22. listt2 = side2Config.getStringList("players");
    23.  
    24. Player player = event.getPlayer();
    25. String splayer = player.getName();
    26. String preconnectmessage = plugin.getConfig().getString("onlogin.noside.message");
    27. String postconnectmessage = preconnectmessage.replace("{Player}", splayer);
    28. String finalconnectmessage = ChatColor.translateAlternateColorCodes('&', postconnectmessage);
    29.  
    30. if(!(listt1.contains(splayer) || listt2.contains(splayer))){
    31. player.sendMessage(finalconnectmessage);
    32. }
    33. }


    BAM!
     
  2. Offline

    thecrystalflame

    Try PlayerJoinEvent instead. i think youll find your trying to send the message before the player is actually capable of recieving one.
     
    amatokus likes this.
  3. Offline

    amatokus

    Thanks this works! +1 Like :D
     
Thread Status:
Not open for further replies.

Share This Page