[Solved] PlaceHolders with integers

Discussion in 'Spigot Plugin Development' started by Kingdomity, Jun 18, 2015.

  1. Hello I tryed to make this placeholder

    Code (Text):
    player.sendMessage(Settings.config.getString("InCooldownMessage").replace("%timeleft%",
                               Cooldown.get(player.getPlayer().getName())));

    and it does not work. I would like server owner to change the InCooldownMessage like this 'You have %timeleft% seconds left of cooldown or whatever they would like the InCooldownMessage to be.
     
  2. Just use java's formatter:

    Code (Java):
    String example = String.format("This is a format string, number: %d", 42);
    //prints
    "This is a format string, number: 42"
     
  3. That should work fine, are you sure he put %timeleft% exactly as it appears in your code, as in, the same casing and everything?
     
  4. When I do this code the .replace is red.
     
  5. Put + "" after it or String.valueOf()...
     
  6. Maximvdw

    Benefactor

    String.valueOf
     
  7. Like that?

    Code (Text):
    player.sendMessage(Settings.config.getString("InCooldownMessage").replace("%timeleft%", String.valueOf(
                               Cooldown.get(player.getPlayer().getName()))));