Solved {name} In the config

Discussion in 'Plugin Development' started by Mao, Jan 27, 2015.

Thread Status:
Not open for further replies.
  1. Hey I was wondering if it would be possible to make it so that {name} would get change to the player name when the message is gotten from the config

    So like the config is

    Welcome to the server {name}

    and the message that is sent is

    Welcome to the server p.getName()

    This is only en example and not that I want to use it for.
  2. Offline


    String message = myConfig().get("my.Path");
    message.replace(What I want to replace, replace with);
  3. Offline


    Get the string then do String#replace("{name}", Player#getName())

    Edit: Ninja'd by @CraftCreeper6
  4. @Mao Yeah. Get the message, for example (EXAMPLE!) config.getString("MyMessageHere").replace("{name}", p.getName());
    That would get you the message and replace {name} with your players name.
  5. Yhea the fun thins is that just before reloading this page I stumbled into a thread where I got my answer, but much thanks to all of you :)
  6. Offline


    isn't it better to do String#replaceAll(""{name}, Player#getName()) ?
  7. Offline


    Yes, either way, but by the looks of it he only wants to replace one. Therefore, it's not mandatory.
  8. Offline


    String#replaceAll is mainly used for RegEx. String#replace also doesn't just replace one instance, it replaces all.
  9. Offline


    @CraftCreeper6 but just to be sure if he wants to add more of {name} for Example Hello {name}, I know you {name}

    @TGRHavoc didn't saw you post
  10. Offline


    I was wrong.
  11. Offline


    Actually, I thought {} was one of those characters that throws errors? If it is, try "\\{stuff\\}"
    TheOatBaron likes this.
  12. Offline


    It is
  13. Offline


  14. Offline


    I don't believe that the "{}" characters need to be escaped. I've used strings such as {name} in strings many times without escaping with no issues what so ever.
  15. Offline


  16. Offline


    Fair point, just don't want people to be spreading false information :p

    Has your issue been solved?
  17. Yes it has, I thank all of you who helped me. Have a good day :)
  18. Marked thread as solved.

    @Mao When it is solved go to thread tools > edit thread > Prefix > Solved
  19. Offline


    Could you please mark this thread as "Solved" then?
    It's under "Thread Tools". Glad you've managed to fix your problem :)

    Edit: Blimey, the Ninjas are out tonight ;)
    CraftCreeper6 likes this.
Thread Status:
Not open for further replies.

Share This Page