Variable in IChatBaseComPonent (Packet)

Discussion in 'Plugin Development' started by Grossen, Apr 30, 2015.

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

    Grossen

    Code:
                IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"You need to choose which gamemode you want to challange \", \"extra\":[{\"text\":\"target.getName()\"}]}");
                PacketPlayOutChat packet = new PacketPlayOutChat(comp);
                ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
    Is it possible to add a variable (target#getName) in a IChatBaseComponent (packet)?
    Check the "extra" part of the packet.

    Anyone know if it's possible?
     
  2. Offline

    mine-care

    @Grossen what is target? is it the player where the packet is going to? is it another player? as far as i know you can send it as you would normaly do with a String
    "Blah "+player#getName+" Blah";
     
  3. Thats your current:
    Code:
    [{\"text\":\"target.getName()\"}]}");
    The escaped character is \" (to use " in a string without interrupting the beginning/end of it)
    You need a normal " to close the string, add your variable, and then add another "
    Code:
    [{\"text\":\"" + target.getName() + "\"}]}");
    If you want to handle the json text easier, use my util: JsonBuilder: https://bukkit.org/threads/jsonbuilder.352325/
    For your code it would be:
    Code:
    JsonBuilder jb = new JsonBuilder("You need to choose which gamemode you want to challenge ").withText(target.getName());
    jb.sendJson(player);
     
Thread Status:
Not open for further replies.

Share This Page