[Urgent] Raw Message ClickAble?

Discussion in 'Plugin Development' started by XxZHALO13Xx, Jul 14, 2014.

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

    XxZHALO13Xx

    Hi... Ik for a a fact that this is possible.. i want a example of how i would send a play a raw message.. iknow how to do that but how do i make it so when they click the message it executes a command? please help and i am certain it works.. ive searched google and everything and i cant figure it out
     
  2. Offline

    Gater12

  3. Offline

    XxZHALO13Xx

    Gater12 i find it very confusing lol
     
  4. Offline

    ImDeJay


    Fanciful is the only way of making it possible(that i know of).
    Sending a player a raw json msg doesn't work, i've tried.
     
  5. Offline

    XxZHALO13Xx

    ImDeJay how would i use fanciful then? example please
     
  6. Offline

    Gater12

  7. Offline

    ResultStatic

    Gater12 if you dont want to use fanciful, i created a little mini library that i privately use, its not as efficient as fanciful, but gets rid of dependencies and gets the job done, its only 2 classes and its pretty simple.
     
  8. Offline

    Gater12

    ResultStatic
    You could post it in the Resources subsection if you want to publicly let developers use it.
     
  9. Offline

    ResultStatic

    Gater12 XxZHALO13Xx I dont want to post it in the resource section because fanciful does it better. here it is if anyone wants to use it, i use this weird complex syntax. it also fixes the glitch where if there is multiple lines they lose color. you can see that on the send method. if you have question or fixes for anything tag me. the only thing that doesnt work is adding multiple actions onclickable text. i tried but i couldnt get it to work. i tried using the array format you can see with adding text, it just didnt work the same with actions and events

    Code:
    public class FancyText {
     
        String text;
        int letters;
        EnumChatFormat format;
     
        public FancyText(String base, EnumChatFormat format) {
            this.text = "{\"text\":\"" + "" + "\"" + ",\"extra\":[" + "{\"text\":\"" + base + "\"}";
            this.format = format;
        }
     
        public FancyText addText(String message) {
            this.text = text + (",{\"text\":\" " + message + "\"}");
            return this;
     
     
        public void addHoverableText(String hoverable, String message) {
            this.text = text + ",{\"text\":\"" + hoverable + "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + message + "\"}}";
        }
     
        public ClickableFancyText addClickableText(String clickable) {
            this.text = text + ",{\"text\":\"" + clickable + "\",\"clickEvent\":";
            return new ClickableFancyText(this);
        }
    //you must call this at the end your message
        public FancyText closeText() {
            this.text = text + "]}";
            return this;
     
        }
     
        public void sendText(Player player) {
            IChatBaseComponent chat = ChatSerializer.a(text);
            chat.getChatModifier().setColor(format);
            PacketPlayOutChat packet = new PacketPlayOutChat(chat, false);
            Nms.getCraftPlayer(player).playerConnection.sendPacket(packet);
        }
    }
    
    first you create a new instance of FancyText, then you can add click modifiers to it with this class. also i couldnt figure out how to have multiple click actions on one text. this library isnt perfect i just wrote it for my personal server plugin.
    dont use the then() method and you must always close the messages.

    Code:
    FancyText text;
        public ClickableFancyText(FancyText instance){
            text = instance;
        }
     
        public ClickableFancyText openlink(String url){
            text.text = text.text + "{\"action\":\"open_url\",\"value\":\"" + url + "\"}";
            return this;
        }
     
     
        public ClickableFancyText runCommand(String command){
            text.text = text.text + "{\"action\":\"run_command\",\"value\":\"" + command + "\"}";
            return this;
        }
     
        public ClickableFancyText chatSuggestion(String chat){
            text.text = text.text + "{\"action\":\"suggest_command\",\"value\":\"" + chat + "\"}";
            return this;
        }
     
        public ClickableFancyText openFile(String file){
            text.text = text.text + "{\"action\":\"open_file\",\"value\":\"" + file + "\"}";
            return this;
        }
    //broken at the moment, would have been used to split up the click actions
        public ClickableFancyText then(){
        text.text = text.text + ",";
        return this;
        }
    // this is also mandatory to close the click action, you could add "}" to the end of each action but
    i find this makes it more organized and it keeps it open for multiple click actions per line of text.
        public void close(){
            text.text = text.text + "}";
     
        }
    }
    you also need this
    Code:
      public static EnumChatFormat getNmsColor(ChatColor chat){
      return EnumChatFormat.valueOf(chat.name());
    }
    and this
    Code:
      public static EntityPlayer getCraftPlayer(Player player){
        return ((CraftPlayer)player).getHandle();
    }
     
  10. Offline

    XxZHALO13Xx

    ResultStatic Still very confused on this.. new to messages like this.. how would i make it so where, when a player joins the server it sends a normal message.. ive done that.. then sends a raw clickable message that says Server Info, they click it then executes a command i made?
     
  11. Offline

    ResultStatic

    XxZHALO13Xx listen on join, and do this. i have the getNmsColor in a Nms util class
    Code:
    FancyText fancy = new FancyText("", Nms.getNmsColor(ChatColor.DARK_BLUE)//set this as the last color you plan the message to use);
    fancy.addText("the normal message goes here ");// is in order of placement. so this would come before the clickable text
    fancy.addClickableText(ChatColor.DARK_BLUE + "ServerInfo: <-- Click Me ").runCommand("command").close();//make sure u close the action off
    //since the color in the constructor is dark_blue the rest of the message even on new lines will be blue
    fancy.closeText();//close the message
    fancy.sendText(player);
     
  12. Offline

    XxZHALO13Xx

    ResultStatic Ok... What Do I Do With

    Code:java
    1. public class FancyText {
    2.  
    3. String text;
    4. int letters;
    5. EnumChatFormat format;
    6.  
    7. public FancyText(String base, EnumChatFormat format) {
    8. this.text = "{\"text\":\"" + "" + "\"" + ",\"extra\":[" + "{\"text\":\"" + base + "\"}";
    9. this.format = format;
    10. }
    11.  
    12. public FancyText addText(String message) {
    13. this.text = text + (",{\"text\":\" " + message + "\"}");
    14. return this;
    15.  
    16.  
    17. public void addHoverableText(String hoverable, String message) {
    18. this.text = text + ",{\"text\":\"" + hoverable + "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + message + "\"}}";
    19. }
    20.  
    21. public ClickableFancyText addClickableText(String clickable) {
    22. this.text = text + ",{\"text\":\"" + clickable + "\",\"clickEvent\":";
    23. return new ClickableFancyText(this);
    24. }
    25. //you must call this at the end your message
    26. public FancyText closeText() {
    27. this.text = text + "]}";
    28. return this;
    29.  
    30. }
    31.  
    32. public void sendText(Player player) {
    33. IChatBaseComponent chat = ChatSerializer.a(text);
    34. chat.getChatModifier().setColor(format);
    35. PacketPlayOutChat packet = new PacketPlayOutChat(chat, false);
    36. Nms.getCraftPlayer(player).playerConnection.sendPacket(packet);
    37. }
    38. }
     
  13. ImDeJay You could do it the same way Fanciful did it, and there's probably more than just that one way, but I'm not sure. I haven't looked into it. :)

    XxZHALO13Xx Once again, this in no way is urgent. Please just stop doing that and then I will take you seriously.
     
  14. Offline

    ResultStatic

    XxZHALO13Xx i posted 2 seperate classes. drop it into a new class and use the code i sent u.
     
  15. Offline

    XxZHALO13Xx

    ResultStatic Thank you so much!!!

    Code:java
    1. XxZHALO13Xx().gives(ResultStatic(1 Like));
    2.  
    3. =====O====O======
    4. +
    5. |_________|
    6.  
     
  16. Offline

    mazentheamazin

    XxZHALO13Xx
    If I wrote the whole story of Narnia without speech quotes in a java class and compiled it would throw less errors as well as make more sense then what you wrote.
     
  17. mazentheamazin Ironic part is he didn't even like one of his posts.
     
    mazentheamazin and KingFaris11 like this.
  18. I hate how you can't give more likes than one. :/ That deserves thousands. :)
     
Thread Status:
Not open for further replies.

Share This Page