String List in scoreboard

Discussion in 'Spigot Plugin Development' started by Blizarg, Aug 5, 2018.

  1. I know many will tell me to learn java, if you are going to tell me the same thing I better keep your words that do not interest me.

    What I want to do is the following, I want to create a marker configuration in chain mode List, I also want to replace the varibles Deaths and killss by these variables %deaths%, %kills% someone helps me help with a small code´

    Code (Text):
    public void run() {
            Player[] array;
            for (int j = (array = Bukkit.getOnlinePlayers()).length, i = 0; i < j; ++i) {
                final Player player = array[i];
                final ScoreboardHelper board = this.scoreboardHandler.getScoreboard(player);
                final File sa = new File("plugins/FusionFFA/stats.yml");
                final YamlConfiguration stats = YamlConfiguration.loadConfiguration(sa);
                final int kills = stats.getInt("players." + player.getName() + ".kills");
                final int deaths = stats.getInt("players." + player.getName() + ".deaths");
                board.clear();
                if (player.getLocation().getWorld().getName().equals("world")) {
                    board.add(this.lines);
                    board.add("&6&lName: &f" + player.getName());
                    board.add("&f&l - &7Kills: &f" + kills);
                    board.add("&f&l - &7Deaths: &f" + deaths);
                    board.add("&f&l - &7Money:" );
                    board.add(this.lines);
                    board.add("&c     howlyhit.us" );
                }
             
                board.update(player);
            }
        }
     
  2. ------------------------------------------------------------
    helppppppppppppppppppp????
    ---------------------------------------------------------
     
  3. For starters:
    Code (Java):

            Player[] array;
            for (int j = (array = Bukkit.getOnlinePlayers()).length, i = 0; i < j; ++i) {
               final Player player = array[i];
               }
     
    One word: why?
    Code (Java):

    for (Player player : Bukkit.getOnlinePlayers()) {
    // code
    }
     

    For the replace feature you'll be using:
    Code (Java):
    String#replace(String toBeReplaced, String toReplace)
    Finally:
    I've no idea what you want to achieve. Could you explain it differently/better?
     
  4. I'm not sure but i think @JavaLogs wants to make a string list in config display as a scoreboard.
    Example config:
    Code (Text):
    scoreboard:
      - "stats:"
      - "kills"
      - "%kills%"
      - "deaths"
      - "%deaths%"
      - "etc"
    would display a scoreboard saying
    Code (Text):
    stats:
    kills
    3
    deaths:
    2
    etc
    (this being an example)
    Hope i explained what i think s/he was trying to say well enough.
     
  5. FrostedSnowman

    Resource Staff

    he decompiled the code. it isn't his
     
    • Agree Agree x 2
  6. As for your string list you'd do something like this:
    Code (Java):
    FileConfiguration#getStringList#forEach(board::add)
    (You may want to translate the color codes in those strings so as to have colored text)

    It seems like he did to be honest. All these final field declarations are quite odd since 90% of those who code plugins (or in general, not sure) do not declare their local objects as final even if they have to be final (some compilers declare these fields as final themselves).
     
  7. because I get that error, why is it a variable of type int?
    I do not understand why I get that error in that second "replaceAll"
    [​IMG]
    Code (Text):
    for (String lines : UHCPlugin.getInstance().getConfig().getStringList("PATH")) {
                         board.add(ChatColor.translateAlternateColorCodes('&', lines).replaceAll("%player%", player.getName()).replaceAll("%kills%", kills));
                    }
     
  8. Try "kills.toString()"
     
  9. Use methode .split ?
     
  10. Firstly, replaceAll is not for your case use simply replace. Secondly, the error shows up because you attempt to replace a string with an int and the second parameter of the replace method only accepts a string. fix that up.
     
    #10 darklazerog, Aug 6, 2018
    Last edited: Aug 6, 2018
  11. I can pass the code solved, I'm sorry but the truth is that 1 month ago I started with the spi api
     
  12. Mark the thread as solved if you have no more issues. Also, we can read perfectly fine even if you do not change the boldness of your messages or the size.
     
  13. I have not solved the problem, so I'm not going to close it
     
  14. The issue you are currently facing is different. Please mark this thread as solved and open a new one if you have any other issue.