Solved 1.7 Chat Features

Discussion in 'Plugin Development' started by willeb96, Dec 26, 2013.

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

    willeb96

    I'm looking to make a plugin that sends a clickable link to the client, so something like:
    Code:
    Click here to do something.


    Using the /tellraw command this would be easy:
    Code:
    /tellraw tellraw Player
        {
            text: "Click ",
            color: gold,
            extra:
            [
                {
                    text: "here",
                    color: yellow,
                    underlined: true,
                    clickEvent:
                    {
                        action: open_url,
                        value: "http://google.com"
                    },
                    hoverEvent:
                    {
                        action: show_text,
                        value: "Do something"
                    }
                },
                {
                    text: " to do something.",
                    color: gold
                }
            ]
        }
    But how do I do that from Bukkit? I assume I'll have to either send a raw packet or use ProtocolLib, any hints on where to begin?
     
  2. Offline

    Chlorek

    sendRawMessage()
     
  3. Offline

    willeb96

    Oh, sweet! Thanks man :)
     
  4. Offline

    aredherring

    If I understand you correctly, you can just send a message to a player containing that JSON.
    edit: ninja'd
     
  5. Offline

    willeb96

    Uhm... I tried using Player.sendRawMessage() but it just displays the json as a big block of text in chat :/
     
  6. Offline

    Blingdaddy1

    My god 1.7 is complex O_O
     
  7. Offline

    aredherring

    willeb96, can we see your code using sendRawMessage()?
     
  8. Offline

    willeb96

    aredherring
    Here you go
    Code:java
    1. sendRawMessage("{text:\"Click \",color:gold,extra:[{text:\"here\",color:yellow,underlined:true,clickEvent:{action:open_url,value:\"[URL]http://google.com\[/URL]"},hoverEvent:{action:show_text,value:\"Do something\"}},{text:\"to do something.\",color:gold}]}");


    aredherring Still there?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    Chlorek

    I think I fixed it, check now (pastebin bcuz bukkit forums break that code):
    http://pastebin.com/LAw5Bkt8
     
  10. Offline

    willeb96

    That still doesn't work :/
    What did you change?

    I got it working using ProtocolLib
    Code:java
    1. PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.CHAT);
    2. packet.getChatComponents.write(0, WrappedChatComponent.fromJson("... JSON goes here ..."));
    3. ProtocolLibrary.getProtocolManager().sendServerPacket(Player, packet);
    4.  
     
Thread Status:
Not open for further replies.

Share This Page