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

    CraftCreeper6

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

    TGRHavoc

    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

    Dmrtje

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

    CraftCreeper6

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

    TGRHavoc

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

    Dmrtje

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

    EDIT:
    @TGRHavoc didn't saw you post
     
  10. Offline

    CraftCreeper6

    @Dmrtje
    I was wrong.
     
  11. Offline

    Xtreme727

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

    TheOatBaron

    It is
     
  13. Offline

    CraftCreeper6

  14. Offline

    TGRHavoc

    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

    CraftCreeper6

  16. Offline

    TGRHavoc

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


    @Mao
    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

    TGRHavoc

    @Mao
    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