[Reasource][Easy] TellrawAPI

Discussion in 'Resources' started by unon1100, Apr 8, 2014.

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

    unon1100

    Hello, developers!

    Here is a nice resource for you guys to use: http://github.com/unon1100/TellrawAPI

    With this, you can make tellraw things with ease.
    Note: If you use this API, please give credit :)

    Usage
    All of the info needed can be found on the README on the github, but here's a basic walkthrough.

    Basic operation: Make an object for each "segment" of the tellraw, then stitch and send.

    Let's have 3 segments...
    1. Text that says "Hi there" and will be bolded and green.
    2. Text that says "To bukkit!" and will link to bukkit.org. Hover message that says "Click me"
    3. Text that says "Click here". When hovered over, it will say "Want free diamonds? Click here!". When clicked, it puts "APRIL FOOLS" into their chat box.

    First step: Create the objects. This isn't that hard since the constructors are fairly straightforward. Syntax for each constructor is always (String text, <Class-specific things>, <optional>ChatColor cc)
    Code:java
    1. TellrawText text = new TellrawText("Hi there",ChatColor.GREEN);
    2. TellrawURL url = new TellrawURL("To bukkit","bukkit.org"); //Default color for URLs is AQUA
    3. TellrawSuggest fool = new TellrawSuggest("Click here","APRIL FOOLS");

    Second step: Apply the formats to the objects.
    Code:java
    1. text.setBold();
    2. url.setHover("Click me!");
    3. fool.setHover("Want free diamonds? Click here!");

    Third step: Finalize the variables and send!
    Code:java
    1. StringBuilder sb = TellrawAPI.finalize(text,url,suggest);
    2. TellrawAPI.sendToAll(sb);
     
    Windy Day and LCastr0 like this.
  2. Offline

    LCastr0

    unon1100 Awesome :)
    Would it be possible to put an already formated message in the code? So like, I put {text:...} in a string then it goes to all the players? (I need it because I'm gonna put the messages in a .yml file)
     
  3. Offline

    macguy8

    LCastr0
    Something like this should work:

    Code:
    String yourJSON = ...
    IChatBaseComponent comp = ChatSerializer.a(yourJSON);
    PacketPlayOutChat packet =new PacketPlayOutChat(comp, true);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    
     
  4. unon1100 - This looks really useful - I never knew what /tellraw was until now, but the only question I have is, can you rewrite this API using Reflection?
     
  5. Offline

    LCastr0

    I need a code that also adds a string to the start of the JSON, so it would send "Prefix + JSON message on config"
     
  6. Offline

    unon1100

    LCastr0 macguy8 With the API you can do TellrawAPI.sendTo(String json, Player...players);

    KingFaris11 Yeah I'll probably do that


    I'll probably add a "stitch" feature that will stitch tellraw things together. That way, you can do something like...

    TellrawParent prefix = TellrawAPI.stitch(part1,part2,part3);

    Then when finalizing the JSON you can do something like

    StringBuilder sb = TellrawAPI.finalize(prefix, msg1, msg2, msg3);
     
    KingFaris11 and LCastr0 like this.
  7. Offline

    Benlewis9000

    I quite like the hover and message on click parts, especially for the April Fools bit ;) I might give it a go in the future. What exactly is tellRaw though anyway?
     
  8. Offline

    Bammerbom

    +1
    reflection please.
     
    KingFaris11 likes this.
  9. Offline

    xTrollxDudex

    ._.

    Reflection is slow without using Unsafe or ASM/byte code hacks/MethodHandles
     
  10. Offline

    Bammerbom

    xTrollxDudex I want my plugin to be compitable with every version.
     
  11. Offline

    xTrollxDudex

    Jhtzb
    Just update it. It's just a few imports.
     
  12. Offline

    Bammerbom

    xTrollxDudex I know. But just I like reflects more :) Not going to discuss over it.
     
Thread Status:
Not open for further replies.

Share This Page