How do you replaceAll() with a text component?

Discussion in 'Spigot Plugin Development' started by pondamo, Jul 12, 2015.

  1. So the plugin im currently working has a JSON feature. Im not the best with JSON so this hasnt been an easy route but im almost done! Let me show you my code then I can explain a little bit better.
    Code (Text):
    if (strFormat.contains("%Variable%")) {
                        TextComponent tc = new TextComponent((String)blank);
                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder((String)blank).create()));
                        strFormat = strFormat.replaceAll("%Variable%", tc);
    Now as im sure some of you may have picked up after reading my code, my issue is that "The method replaceAll(String, String) in the type String is not applicable for the arguments (String, TextComponent)" I tried converting tc into a string but that just resulted into all of the json LITERALLY turning into a string. Any suggestion on what to do? Thank you!
  2. Still waiting for assistance ._.
  3. so just to clarify... you have tried String.valueOf() and textComponent.toString() (if those are actually possible) and some people will hate me for saying this because i might sound like i don't know wha tim doing (just thinking of all possibilities) you could in theory try

    String string = "" + textComponent;

    and if you say you have tried all of those... and what I'm seeing in your code you might want to have a deep search through google about this.

    P.S if I'm completely wrong with what i have said, thats alright! people take things in differently so don't be negative just ignore it
  4. Well first off I just want to say thank you for actually trying to help me. Yes I have tried all that you said and this is what happens:
    Also, i have tried looking all over the place for an answer and I have come up with nothing which is why im here.
  5. have you tried replace() instead of replaceAll()? if you have, i can't help you any further... sorry
  6. Yea it still wont work. From what I understand you cant convert a TextComponent into a string otherwise it like breaks it down as shown in the image above. I appreciate you atleast trying. Thanks and hopefully someone else is able to assist me!
  7. How about tc.getText()?
    I believe such a method exists.
  8. The method does exist but how would I use it...
  9. strFormat = strFormat.replaceAll("%Variable%", tc.getText());

    Edit: It depends on what you're trying to do here. Do you want %Variable% to become the text of tc?
  10. Okay I just tried that and it works sorta it just doesnt add the hover to the word which is my main goal.
  11. Yea thats what im trying to accomplish. The plugin will print out the text in chat and there will be multiples of %Variable% in the message. I need all of them to have a tooltip. So I created a text component because thats how you add tooltips. So now im trying to replace all of the %Variable% With the text component
  12. Anyone else want to try and help meh :3
  13. Why don't you replace all before you put the string into the text component?
  14. If I did that then how would I make the key words have a tooltip...
  15. Edit.... you should send the entire message as a json, not just parts of it. The spigot version of send message can handle a text component array. So build your message in multiple text components and then send the array to the player
    #17 Fearmig, Jul 14, 2015
    Last edited: Jul 14, 2015
  16. My only issue with that is I only want certain words to have JSON and each of those words will have a different tooltip based off of the word.
  17. Did you create a string variable then use that replaceall and save it as another variable thats displayed in wherever you want it? I've done this before and i got it to work...
  18. Yep, then this happens: