Solved how to replace stuff from the config to something else?

Discussion in 'Plugin Development' started by MAYBE, Jun 29, 2015.

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

    MAYBE

    hello i was just wondering how you could make this.
    How could i make that when the user edits the config and it sais like:

    message: Hello {DISPLAYNAME} welcome to out server

    or something thart it makes the "{DISPLAYNAME}" to player.getDisPlayerName();

    or how could i make this also?
    In your coding you make a string like this
    Code:
    String MyMessage = "Welcome to the strangest server ever!";
    
    and when you type this in to the config it gets the "MyMessage" string and looks what is in it.
    OtherMsg: here it should display the "MyMessage" string (i mean the value) {MyMessage}
    it would be nice to explane a little too.
    Thank you!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @MAYBE string.replace("{DISPLAYNAME}",player.getDisPlayerName())
     
  3. Offline

    MAYBE

    so would this work?
    Code:
            String rmsg = e.getMessage();
            String msg = getConfig().getString("Message");
            msg.replace("{DISPLAYNAME}", e.getPlayer().getDisplayName());
            msg.replace("&", "§");
            msg.replace("{MESSAGE}", rmsg);
            player.sendMessage(msg);
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @MAYBE Nope.
    replace returns a string, you need to use that return value if you want anything to change.
     
  5. Offline

    MAYBE

    @timtower can you show me please i dont quite untherstand?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @MAYBE variable = String.replace("something",othervariable)
     
  7. Offline

    MAYBE

    ok and how could i replace more than just one?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @MAYBE You add more lines to it? I barely write functional code on here. I explained how it worked, now you have to implement it in your code.
    If not sure how it works: check the javadocs about it.
     
  9. Offline

    MAYBE

    @timtower ok so one more question so i´d need to do this
    Code:
    variable = String.replace("something",othervariable)
    variable = String.replace("second something",second othervariable)
    
     
    Last edited: Jun 29, 2015
  10. Offline

    timtower Administrator Administrator Moderator

    @MAYBE No, you can just use msg = String.replace(whateveryouhadhere)
     
  11. Offline

    MAYBE

    @timtower ok i think this is it
    Code:
            String rmsg = e.getMessage();
            String msg;
            String value, val, valu;
            value = getConfig().getString("Message");
            valu = value.replace("{DISPLAYNAME}", (CharSequence) e.getPlayer());
            val = valu.replace("{MESSAGE}", rmsg);
            msg = val.replace("&", "§");
            player.sendMessage(msg);
    
     
  12. Offline

    timtower Administrator Administrator Moderator

    @MAYBE No.
    Code:
            String rmsg = e.getMessage();
            String msg = getConfig().getString("Message");
           msg = msg.replace("{DISPLAYNAME}", e.getPlayer().getDisplayName());
           msg =  ChatColor.translateAlternateColorCode('&',msg);
           msg =  msg.replace("{MESSAGE}", rmsg);
            player.sendMessage(msg);
    
     
  13. Offline

    MAYBE

    ok thanks!
     
Thread Status:
Not open for further replies.

Share This Page