Replace Variable with TextComponent

Discussion in 'BungeeCord Plugin Development' started by Fabb111, May 17, 2016.

  1. 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.
     
  2. 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.
     
  3. 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
     
  4. Wow, is to complicated for unterstand. Can you make it a bit simply? ^^'
     
  5. 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? :p
     
  6. 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! :)
     
  7. I will test it in a few minutes, I'll write the feedback then xD
     
  8. No, also not working :(
     
  9. maybe this can help you:
    Code (Text):
            String s = "text %var%";
            s.replaceAll("%var%", "tree");
            TextComponent.fromLegacyText(s);
     
  10. Length is spelled wrong in your code, I hope that doesn't cause a buggg ^_^
     
  11. lol :p ~german errors~ xD
     
  12. @essem2 I'll try it when I have time :)