[LIB] Fanciful: pleasant chat message formatting

Discussion in 'Resources' started by mkremins, Nov 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    Really Awesome Lib. Good Work @mkremins keep going. But I've got some more Questions.

    1. Are you gonna add more Colours? Would be nice if you would add all possible ChatColors :D if you already did, I'm just too stupid to see them...
    2. Can I use \n in the tooltip to add a new Line?
    3. I created this:
        static String vip() {
        return new FancyMessage("VIP")
        .tooltip("VIP\nBuy VIP from the Online Store")
    can I send it to the Player with this:
  2. Offline


    1. ;D
    2. tooltip takes an array, just use
    tooltip("VIP","Buy VIP from the Online Store")
    for multiple lines
    3. You can send the player the JSON String, but it will not look like you expect. You should try sendRawMessage or better use fanciful's own send method. Your method should return an FancyMessage object, which you can send to the player
    TheLexoPlexx likes this.
  3. Offline


    okay Thanks man, but how can I use fancifuls own send method? I searched thru the Sources but I didn't find anything.

    P.S.: Deine Signatur ist der Hammer :DD
  4. Offline


    TheLexoPlexx likes this.
  5. Offline


  6. Offline


    Glanced through all 7 pages of comments (it's midnight, may have missed it, but) is there a way to convert color codes into JSON or FancyMessage and vice-versa?
    "&3this is a cyan message" <=> {text:"this is a cyan message",color:dark_aqua}
    Figured out I need something of the sort, and don't want to reinvent the wheel. ._.
    not only that ^^^ but also
    "&6this is a &3cyan &6message." <=> {text:"this is a ",color:gold},{text:"cyan ",color:dark_aqua},{text:"message.",color:gold}
    (I can just append "{text:\"\",extra[" + "]}" later)

    --EDIT 2--
    threw this together. It should work for just the colors, (i'll be adding the hover effect to it later), I think. Did I mess up somewhere?
    2. public String colorToJson(String s,String hover){
    3. String[] p = s.split("&");
    4. String end="{text:\"\",extra[";
    5. for(int i=0; i < p.length; i++){
    7. if(p[i].startsWith("0")){end=end+"{text:\""+p[i].substring(1)+"\",color:black}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    8. }
    9. else if(p[i].startsWith("1")){end=end+"{text:\""+p[i].substring(1)+"\",color:dark_blue}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    10. }
    11. else if(p[i].startsWith("2")){end=end+"{text:\""+p[i].substring(1)+"\",color:dark_green}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    12. }
    13. else if(p[i].startsWith("3")){end=end+"{text:\""+p[i].substring(1)+"\",color:dark_aqua}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    14. }
    15. else if(p[i].startsWith("4")){end=end+"{text:\""+p[i].substring(1)+"\",color:dark_red}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    16. }
    17. else if(p[i].startsWith("5")){end=end+"{text:\""+p[i].substring(1)+"\",color:purple}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    18. }
    19. else if(p[i].startsWith("6")){end=end+"{text:\""+p[i].substring(1)+"\",color:gold}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    20. }
    21. else if(p[i].startsWith("7")){end=end+"{text:\""+p[i].substring(1)+"\",color:gray}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    22. }
    23. else if(p[i].startsWith("8")){end=end+"{text:\""+p[i].substring(1)+"\",color:dark_gray}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    24. }
    25. else if(p[i].startsWith("9")){end=end+"{text:\""+p[i].substring(1)+"\",color:blue}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    26. }
    27. else if(p[i].startsWith("a")){end=end+"{text:\""+p[i].substring(1)+"\",color:green}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    28. }
    29. else if(p[i].startsWith("b")){end=end+"{text:\""+p[i].substring(1)+"\",color:aqua}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    30. }
    31. else if(p[i].startsWith("c")){end=end+"{text:\""+p[i].substring(1)+"\",color:red}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    32. }
    33. else if(p[i].startsWith("d")){end=end+"{text:\""+p[i].substring(1)+"\",color:pink}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    34. }
    35. else if(p[i].startsWith("e")){end=end+"{text:\""+p[i].substring(1)+"\",color:yellow}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    36. }
    37. else if(p[i].startsWith("f")){end=end+"{text:\""+p[i].substring(1)+"\",color:white}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    38. }
    39. else if(p[i].startsWith("r")){end=end+"{text:\""+p[i].substring(1)+"\",color:white}";if(!(hover==null)){end=end+ makeHover(hover) + "}";}if(!p[i].equals(p.length)){end=end+", ";}
    40. }
    41. }
    43. return end;
    44. }
    46. public String makeHover(String hover){
    47. String[] p = hover.split("&");
    48. String end=",hoverEvent:{action:show_text,value:";
    49. for(int i=0; i < p.length; i++){
    51. if(p[i].startsWith("0")){end=end+"{text:\""+p[1].substring(1)+"\",color:black}";if(!p[i].equals(p.length)){end=end+", ";}
    52. }
    53. else if(p[i].startsWith("1")){end=end+"{text:\""+p[1].substring(1)+"\",color:dark_blue}";if(!p[i].equals(p.length)){end=end+", ";}
    54. }
    55. else if(p[i].startsWith("2")){end=end+"{text:\""+p[1].substring(1)+"\",color:dark_green}";if(!p[i].equals(p.length)){end=end+", ";}
    56. }
    57. else if(p[i].startsWith("3")){end=end+"{text:\""+p[1].substring(1)+"\",color:dark_aqua}";if(!p[i].equals(p.length)){end=end+", ";}
    58. }
    59. else if(p[i].startsWith("4")){end=end+"{text:\""+p[1].substring(1)+"\",color:dark_red}";if(!p[i].equals(p.length)){end=end+", ";}
    60. }
    61. else if(p[i].startsWith("5")){end=end+"{text:\""+p[1].substring(1)+"\",color:purple}";if(!p[i].equals(p.length)){end=end+", ";}
    62. }
    63. else if(p[i].startsWith("6")){end=end+"{text:\""+p[1].substring(1)+"\",color:gold}";if(!p[i].equals(p.length)){end=end+", ";}
    64. }
    65. else if(p[i].startsWith("7")){end=end+"{text:\""+p[1].substring(1)+"\",color:gray}";if(!p[i].equals(p.length)){end=end+", ";}
    66. }
    67. else if(p[i].startsWith("8")){end=end+"{text:\""+p[1].substring(1)+"\",color:dark_gray}";if(!p[i].equals(p.length)){end=end+", ";}
    68. }
    69. else if(p[i].startsWith("9")){end=end+"{text:\""+p[1].substring(1)+"\",color:blue}";if(!p[i].equals(p.length)){end=end+", ";}
    70. }
    71. else if(p[i].startsWith("a")){end=end+"{text:\""+p[1].substring(1)+"\",color:green}";if(!p[i].equals(p.length)){end=end+", ";}
    72. }
    73. else if(p[i].startsWith("b")){end=end+"{text:\""+p[1].substring(1)+"\",color:aqua}";if(!p[i].equals(p.length)){end=end+", ";}
    74. }
    75. else if(p[i].startsWith("c")){end=end+"{text:\""+p[1].substring(1)+"\",color:red}";if(!p[i].equals(p.length)){end=end+", ";}
    76. }
    77. else if(p[i].startsWith("d")){end=end+"{text:\""+p[1].substring(1)+"\",color:pink}";if(!p[i].equals(p.length)){end=end+", ";}
    78. }
    79. else if(p[i].startsWith("e")){end=end+"{text:\""+p[1].substring(1)+"\",color:yellow}";if(!p[i].equals(p.length)){end=end+", ";}
    80. }
    81. else if(p[i].startsWith("f")){end=end+"{text:\""+p[1].substring(1)+"\",color:white}";if(!p[i].equals(p.length)){end=end+", ";}
    82. }
    83. else if(p[i].startsWith("r")){end=end+"{text:\""+p[1].substring(1)+"\",color:white}";if(!p[i].equals(p.length)){end=end+", ";}
    84. }
    85. }
    86. return end;
    87. }[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
    --EDIT 3--
    Updated code. Still haven't tested, but logic looks alright. I'm a beginner, though, so if there's an easier way to do this, please enlighten me. :)[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
  7. Offline


    I have a small problem here. I want to display the displayname of an ItemStack in the chat. But when it does not have ItemMeta, it cannot display the default name.
    1. FancyMessage msg = new FancyMessage("");
    2. ItemStack hand = player.getItemInHand();
    3. msg.then(hand.getItemMeta().getDisplayName()).itemTooltip(hand);
  8. Offline


    Repo isn't found, any other way to use this?
  9. Offline


    I duplicated the repository on my own Maven repository to solve this problem.
    Feel free to use it, just replace the repository tag with:
  10. Offline


    I'd like to give this a try in 1.8 ;)
  11. Offline


    It currently doesn't work, because of spigot don't remapping the gson lib.
  12. Easy fix for this :)
    Change "net.minecraft.util" to "org.bukkit.craftbukkit.libs"
    Spigot still have the google gson libs! ;)
  13. Offline


    I know. I am using it like this. Someone should submit a pull request ;D
  14. Offline


    How do I use this for 1.8? Are there alternatives?
  15. Offline


    @woutwoot By looking at the 2(maybe 3) comments above you >.<
  16. Offline


    I read a lot of comments above mine. Just couldn't get it to work. Anyway, I managed to do it now by looking at your latest commit.
  17. Offline


    Could someone please explain a little more in depth of how they got it to display correctly in 1.8? I have Fanciful as a Repo/Dependency in my pom.xml but the maven repo has not been updated.

    I'm referring to this, in case anyone was wondering
    Last edited: Jan 6, 2015
  18. Offline


    @XylenTV You are sending the player the JSON message (most likely via Player#sendMessage(String) )

    But afaik you have to send the packet with the JSON text ;)
    XylenTV likes this.
  19. Offline


    Thanks. I was able to get it to work but I had to use the .send. This doesn't work exactly for what I need since I need to be able to combine it with regular strings. I tried (Assuming player is an instance of Player) player.sendRawMessage(advertisement()); both having .toJSONString and .toString at the end of the advertisement method (I also tried sendMessage and toString together). If anyone has figured out an efficient way to send it without packets that would be great.
  20. Offline


  21. Offline


    I've just released version 0.3.0.

    Important note for anyone who's been using Fanciful up until now: we've switched over from using a GitHub branch as a hacky pseudo-Maven repository thanks to @franga2000, who is now hosting a proper Jenkins CI instance and Maven repository for Fanciful on his own server. As such, you'll need to update the fanciful-mvn-repo repository entry in your POM to make use of the new repo's URL (http://repo.franga2000.com/artifactory/public) in order to be able to pull down new releases of Fanciful going forward.
  22. Offline


    Any one wanna point me in the right direction on how to use this as a normal eclipse java project? Or import it into one!
  23. Offline


  24. Offline


    As @MiniDigger pointed out to me earlier, the 0.3.0 artifact I'd supposedly deployed never actually made it to the public Maven repo. To fix this I've just deployed a new 0.3.1 artifact that should definitely be available to everyone, for real this time ;)
  25. Offline


    How do you send it after this?
  26. Offline


    you can return a fancymessage and send it via the send(Player) method.
  27. Offline


    Use the then(String) message on FancyMessage to append normal text to a FancyMessage during construction.

    Use FancyMessage.send(Player) [not static BTW]
  28. I'm not sure if this has been answered, but anyway, I want to make it so a player sends out a hover text thingy. Is that possible? I want it to use the same chat formatting as normal, so I don't want to always use the default EssentialsChat format incase they don't use EssentialsChat. I could use Vault instead, but that'll mean they require Vault and not all servers use Vault (though to be honest, they should anyway).

    [{prefix}] {displayname}: {hovertext}
  29. Offline


    just create a fancymessage as normal and add the "hover text thingy" using the tooltip method. You you add a tooltip to a messagepart you can hover over that messagepart and it will open the tooltip with the text you entered
    KingFaris11 likes this.
  30. Offline


    How can I use this with Eclipse?
Thread Status:
Not open for further replies.

Share This Page