How To Have Two Variables?

Discussion in 'Plugin Development' started by Epicballzy, Apr 24, 2014.

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

    Epicballzy

    I'm trying to make a set of variables so that %AMOUNT = an amount and %PLAYER is players name. However, the way I did it, does not work. The %AMOUNT does though.

    Code:java
    1. sender.sendMessage("§b§l► " + ChatColor.translateAlternateColorCodes("&".charAt(0),
    2. messageConf.getString("coinsPlayer").replaceAll("%AMOUNT", getConfig().getString(sender.getName() + ".Coins")
    3. .replaceAll("%PLAYER", name))));

    Not sure if this is the proper way, but I don't get any errors. The message ends up like "%PLAYER has 10 coins!"
     
  2. Offline

    Cronos79

    Do the replace all's in 2 separate commands. Make a String msg = ("§b§l► " + ChatColor.translateAlternateColorCodes("&".charAt...

    Then do a msg = msg.replaceAll(%AMOUNT ...
    then another msg = msg.replaceAll(%PLAYER ...

    then do the sendMessage(msg);
     
  3. Offline

    rfsantos1996

    Try:
    Code:java
    1. sender.sendMessage(
    2. messageConf.getString("coinsPlayer")
    3. .replaceAll("&", "§") // make color
    4. .replaceAll("%PLAYER", player.getName()) // display name
    5. .replaceAll("%AMOUNT", Integer.toString(getConfig().getInt(sender.getName()+".Coins", 0)))
    6. // display amount with the "default value"
    7. );
     
  4. Offline

    Epicballzy

    Sweet! Thanks, it worked :)
     
  5. Offline

    Plo124

    Epicballzy
    I noticed your error,
    You were replacing all the %PLAYER in be
    getConfig().getString(sender.getName()+".Coins")
    because you forgot to put the extra bracket after the getString() to close off the replaceAll, and you put an extra bracket at the end of the whole line because your IDE said there was a missing bracket.
     
  6. Offline

    RawCode

    if you want multiple replaces use regex expression or invoke replace multiple times.
     
Thread Status:
Not open for further replies.

Share This Page