TextComponent And Strings

Discussion in 'Spigot Plugin Development' started by XelfeGamer, May 17, 2015.

  1. Hey guys you know how to send an string with textcomponent? i can send textcomponent normaly, but if i try send string + textcomponent, textcomponent is like this:

    if somebody can help me would be great!
  2. try string+<textComponent>.getText()
  3. This returns the string but i can't use ClickEvent or HoverEvent
  4. Why not the String to a second textcomponent?


    //Does not work^^
    #4 mr_splash, May 17, 2015
    Last edited: May 17, 2015
  5. How i can do that?
  6. To send textcomponents (and BaseComponents) you should use player.spigot().sendMessage(...);
    • Useful Useful x 1
  7. Oh, bad forum, im coding in the Bungee API xD, some way for fix this in the Bungee API?
  8. Use TextComponent#addExtra(found here) to add strings to a TextComponent.
    • Useful Useful x 1
  9. Try this:

    Code (Text):

    TextComponent tc = new TextComponent(string);
    tc.addExtra(" " + yourtextcomponent);
    So now it's all in one textcomponent.

  10. Ummm, you can't append a TextComponent object to a string.
  11. Yeah that's good, but some way for use the string first and then the textcomponent?
  12. Not sure what you mean, can you elaborate?
  13. The void addextra is for add an string after the textcomponent, i want add an string before the textcomponent.
  14. Use the ComponentBuilder(found here).
  15. Works...^^
  16. Code (Java):
    TextComponent textComponent = new TextComponent("Hello,");
    TextComponent anotherComponent = new TextComponent( "World" );
    textComponent.addExtra( " " + anotherComponent );
    The code would output:
    Code (Text):
    Hello, TextComponent{text=World, BaseComponent(color=§f, bold=null, italic=null, underlined=null, strikethrough=null, obfuscated=null, extra=null, clickEvent=null, hoverEvent=null)}
    You are obviously oblivious to the fact that when you try to append a string with another object it combines the String with that object's toString method.
  17. The BungeeCord API has ProxiedPlayer::sendMessage(BaseComponent...), as this is the BungeeCord Chat API.

    General adviced to use the ComponentBuulder unless otherwise stated.