1.8.8 How to replace just word instead of whole line

Discussion in 'Spigot Plugin Development' started by ChemicalCopy, Jul 6, 2021.

  1. Hi guys, I have issue that when is placeholder in lore, the whole line is replaced instead of the placeholder. Why is it happening and how can I avoid it?
    Code (Java):
    public static String replace(String string, Player player) {
            String playerCount = String.valueOf(Bukkit.getOnlinePlayers().size());
            String playerName = player.getName();


            if (string.contains("<players>")) {
                string = playerCount;
            }
            if (string.contains("<playerName>")) {
                string = playerName;
            }
            return string;
        }
    Code (Java):
    public static List<String> r(List<String> toReplace, Player player) {
            List<String> list = new ArrayList<>();
            for (String line : toReplace) list.add(Placeholders.replace(line, player));
            return list;
        }
    Code (Java):
    itemsMeta.setLore(Color.sl(Replace.r(lores, player)));
     
  2. SteelPhoenix

    Moderator

    String#replace(...)
     
    • Like Like x 2
  3. String#replace() is what you need.
    What you currently do is setting your input to your playercount
     
    • Like Like x 1
  4. Oh yeah, I am totally dumb, thanks
     
  5. Please mark the thread as solved.