Solved Changing a config idetifier to a variable in a message

Discussion in 'Spigot Plugin Development' started by Stellrow, Aug 9, 2018.

  1. So im trying to get the seconds left(cooldown left) of a player while also using a config message
    The config message im trying to get
    Code (Text):
    MesajTimpRamas: "&cTrebuie sa mai astepti inca &e%secunde &csecunde pentru a spawna un creeper"
    So i want the %secunde to change with a int
    Code (Text):
                    int secunde = plugin.cdtime.get(uuid).;
                    String timpramas = plugin.getConfig().getString(".MesajTimpRamas").replaceAll("%secunde", secunde);
                    String timpramas2 = timpramas.replaceAll("&" , "§");
                    String mesajtr = timpramas2.replaceAll("§§" , "&");
    This is what im using to get the message and all
    The .replaceAll part is not working as its an int not a string,im new to working with config on a more advanced side,any help?
  2. If you wish to use chatcolor codes please use the already provided method:

    ChatColor#translateAlternateColorCodes(altColorChar, textToTranslate)

    Additionally, in your case using replaceAll is not necessary. Instead use the String#replace method.

    This method requires a string to be replaced and another string to replace it with.

    If the string that will be used to replace is an int or whatever you can use the String method valueOf. (String#valueOf).
  3. I would use string.replace instead of string.replaceAll.

    The replaceAll and the replace methods excepting strings. You can do:
    Code (Java):
    Why are you doing so much replace?

    You can easily do:
    Code (Java):
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message););
    And it's useless sending colors to console. sender can be a commandBlock, or console, too.
  4. The string replaced with another string gave me a dumb ideea that worked
    Code (Text):
                    int secunde = plugin.cdtime.get(uuid);
                    String secundev = "" + secunde;
                    String timpramas = plugin.getConfig().getString(".MesajTimpRamas").replaceFirst("%secunde", secundev);
                    String timpramas2 = timpramas.replaceAll("&" , "§");
                    String mesajtr = timpramas2.replaceAll("§§" , "&");
    Might not be the best but seems to do its job