Variables in Scoreboards

Discussion in 'Spigot Plugin Development' started by _xXProDudeXx_, May 30, 2017.

  1. Hello all!

    I am currently using a Scoreboard object to make scoreboards easier to code. I can basically create a List of Strings (the lines), then reverse them using Collections.reverse(list) and then I can use Scoreboard#setLines(list);

    Now I want to be able to put Variables in the board, as I do not want to update all lines each time. For example, I want to store kills in the board, then I would like to add a variable like this:

    Scoreboard.withVariable(String var, String replace);
    These two Strings get stored in a Map, but I need to somehow convert the variables into the actual replacement in the board.

    This is what I tried:

    Code (Text):
    private String getString(String str){
            for(String s : variables.keySet()){
                str = str.replace(s, variables.get(s));
            return str;
    In this case, the parameter String can be the {kills} variable in the List, that should be converted to an Integer from a Database.

    I would use Scoreboard.withVariable("{kills}", Database.getKills(player) + "");

    the getString method is used to store the updated strings in another arraylist that is going to be the actual list of lines, set in the scoreboard.

    Unfortunately this way keeps giving me the {kills} in the scoreboard.. What did I do wrong?
  2. Try String#replaceAll(string replacement, string text)
    Works for me.
    • Agree Agree x 1