Hey, for my new plugin I need to replace a variable (%variable%) with a TextComponent (I need the Hover & Click event, thats why I need the TextComponent) and yeah.
You must transform all the sentences into TextComponent. Code (Text): "An exemple of %variable%" became TextComponent textComponent = new TextComponent("An exemple of "); TextComponent variable = new TextComponent("%variable%"); textComponent.addExtra(variable); I thinks it is.
Okey, I will post the Code line for better understanding. Code (Text): TextComponent staffinformmsg = new TextComponent(config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString().replaceAll("%reporter%", reporter.getName()).replaceAll("%reported%", reported).replaceAll("%reason%", config.getString("ReportMode.GommeHDnet.ReasonName")).replaceAll("%join%", replaceVar("%join%", config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString(), helpLenght - 1, random).getText().toString()).replaceAll("%manage%", config.getString("Messages.StaffMessages.NewReport.VARmanage.Message")).replaceAll("&", "ยง")); Code (Text): .replaceAll("%join%", replaceVar("%join%", config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString(), helpLenght - 1, random).toString()) - The replaceVar is a method the %join% is for the declaration (so the method knows which var), config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString() is the message where the variable is in (where the %join% gets replaced) and helpLenght - 1 is an Integer you don't have to know what it does, same as "random" xD
Sure xD Code (Text): new TextComponent(config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString() - The start, the last line of the List "Messages.StaffMessages.NewReport.Message" in the config. Code (Text): .replaceAll("%reporter%", reporter.getName()).replaceAll("%reported%", reported).replaceAll("%reason%", config.getString("ReportMode.GommeHDnet.ReasonName")) - Some variables, don't need to be mentioned Code (Text): .replaceAll("%join%", replaceVar("%join%", config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString(), helpLenght - 1, random).getText().toString()) - This is it xD So, %join% gets replaced with the TextComponent from replaceVar (the () of replaceVar isn't necessary). In my TextComponent I add a Hover & a Click Event. But you cannot replace %join% (String) with replaceVar (TextComponent), they both need to be a String, so I added getText().toString() or toString() but this will print the String of the TextComponent (JSON String). Now better explained?
Yes, you can do. Code (Text): String var = replaceVar("%join%", config.getList("Messages.StaffMessages.NewReport.Message").get(helpLenght - 1).toString(), helpLenght - 1, random).getText().toString())); TextComponent varComponent = new TextComponent(var); I go check it and give you an issue!
maybe this can help you: Code (Text): String s = "text %var%"; s.replaceAll("%var%", "tree"); TextComponent.fromLegacyText(s);