Solved PlayerJoinEvent... calling twice?

Discussion in 'Spigot Plugin Development' started by Scholler, Jun 12, 2019.

  1. So.. I am making a FirstJoin plugin, and I have a problem.
    This is the code:
    Code (Java):
    public void onJoin(PlayerJoinEvent e)
    {
        String name = e.getPlayer().getName();
        if (getConfig().getString(name) != null)
        {
            if (getConfig().getBoolean("ShowJoinMsgWhenNotNew") != false && !getConfig().getString("MessageWhenNotNew").isEmpty())
            {
                e.setJoinMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("MessageWhenNotNew") + getConfig().getString("MessageWhenNotNew").replace("{PLAYER}", name)));
            }
        } else
        {
            String s = getConfig().getString("joinmsg");
            s = s.replace("{PLAYER}", name);
            e.setJoinMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("joinmsg")) + s); //THERE
            getConfig().addDefault(name, "joined");
            saveConfig();
        }
           
           
    }
    So, I put //THERE at the line which doesn't work as excepted. The default joinmsg in config.yml is
    &cWelcome {PLAYER} at our server! This is the first time you're playing!
    And the result:
    (red chatcolor)Welcome {PLAYER} at our server! This is the first time you're playing!&cWelcome Scholler at our server! This is the first tome you're playing!

    So it first says the default joinmsg with the ChatColor.translate thing working, then it says with the {PLAYER} replaced with name thing working, but color translate is not.

    Hope you understand it :c
     
  2. you're adding it twice here.
    Code (Java):

    e.setJoinMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("MessageWhenNotNew")
       + getConfig().getString("MessageWhenNotNew").replace("{PLAYER}", name)));

     
     
    • Like Like x 1
  3. Thanks, the problem was at where I put //there but it was the same problem. I will try it and mark thread as SOLVED if it's working
     
  4. You are doing the same thing there too
    Code (Java):

    String s = getConfig().getString("joinmsg");
    s = s.replace("{PLAYER}", name);
    e.setJoinMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("joinmsg")) + s); //THERE
     
    you get the message then you get it again and append the two and send them both here
     

Share This Page