[Help] Config variables!

Discussion in 'Plugin Development' started by Minesuchtiiii, May 17, 2014.

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

    Minesuchtiiii

    Hey I just want to add to my plugin that it's possible to define in the config the join and quit message.
    So I want that in the config %player% means p.getName();
    How would I do this?
    I tried already 'String.replace("%player%", p.getName());' but it doesn't work!

    Thanks
     
  2. Offline

    Rocoty

    Post your config and relevant code please.
     
  3. Offline

    Minesuchtiiii

    Rocoty

    Code:java
    1. FileConfiguration cfg = this.getConfig();
    2.  
    3. JoinEvent...
    4.  
    5. Player p = e.getPlayer();
    6.  
    7. String joinmsg = cfg.getString("JoinMesssage");
    8. ChatColor.translateAlternativeColors('&', joinmsg);
    9. joinmsg.replace("%player%", p.getName());
    10.  
    11.  


    Doesn't work..

    Bumb!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Offline

    tryy3

    do joinmsg = joinmsg.replace("%players%", p.getName()); instead

    Btw only bump once every 24h!
     
  5. Offline

    Rocoty

    Minesuchtiiii Strings are immutable. Any operation performed on a string will NOT change it. It will merely return a new String.
     
  6. Offline

    Minesuchtiiii

    Rocoty
    So what should I change?
     
  7. Offline

    Rocoty

    Minesuchtiiii
     
  8. Offline

    Minesuchtiiii

    Solved it on my own (or not?)
    Code:java
    1. String quitmsg = cfg.getString("QuitMessage");
    2. quitmsg = defaultReplace(p, quitmsg);
    3. ChatColor.translateAlternateColorCodes('&', quitmsg);
    4. quitmsg = quitmsg.replace('&', '§');
    5. quitmsg = quitmsg.replace("%player%", p.getName());
    6.  
    7. e.setQuitMessage(quitmsg);


    Works perfect!
     
  9. Offline

    tryy3

    Minesuchtiiii
    Why are you trying to translateAlternateColorCode and after that change & to §?

    translateAlternateColorCodes returns a string so that line should look like quitmsg = ChatColor.translateAlternateColorCodes('&', quitmsg);

    if you replace & with § you might replace stuff like "Hello & Goodbye" better to just use translateAlternateColorCodes.
     
Thread Status:
Not open for further replies.

Share This Page