Skip to content

Messages

Hempfest edited this page Oct 7, 2021 · 1 revision

A Message consists of multiple string Chunks containing their own respective tooltip information.

All known tooltip types are as follows [Url(Click), Copy(Click), Suggestion(Click), Command(Click), Text(Hover), Action(Click), Item(Hover)]

A single message chunk can only contain one click tooltip as-well as one hover tooltip, if a chunk only contains 1 click tooltip multiple text hover tips can be applied or 1 item hover tip can be applied not both.

Building a message

Building a message is really easy! A throw-back to some but new to others! Resembling the fanciful library, append different message styles and tooltips with ease!

Using the factory

If you're the type of person who's more comfortable working with functions rather than instantiation, each respective factory contains builder methods for local message building like so:

public class ExampleClass implements Message.Factory {

	@Ordinal(1)
	private void broadcast() {
		Message message = message();
		
		Message.Chunk chunk = text("Hello");
		chunk.style(GALAXY);
		
		ToolTip<String> hover1 = hover("This is a test");
		hover1.color(ORANGE);
		hover1.style(BOLD, UNDERLINE);
		
		ToolTip<String> hover2 = hover("Can you read me?");
		hover2.color(DARK_BLUE);
		
		ToolTip<String> command = command("/help");
		
		chunk.bind(command);
		chunk.bind(hover1);
		chunk.bind(hover2);
		
		message.append(chunk);
	}

}

Manual instantiation

		// Fancy builder
		Message message = new FancyMessage("Hello").style(GALAXY).then(" ").then("World!").style(GALAXY).hover("This is a test").hover("Can you read me?").command("/help");
		
		// Normal builder
		Message message = new MessageBuilder();

		Message.Chunk chunk = new TextChunk("Hello");
		chunk.style(GALAXY);

		ToolTip<String> hover1 = new ToolTip.Text("This is a test");
		hover1.color(ORANGE);
		hover1.style(BOLD, UNDERLINE);

		ToolTip<String> hover2 = new ToolTip.Text("Can you read me?");
		hover2.color(DARK_BLUE);

		ToolTip<String> command = new ToolTip.Command("/help");

		chunk.bind(command);
		chunk.bind(hover1);
		chunk.bind(hover2);

		message.append(chunk);

Json Support

Both Messages and the chunks they contain can be completely formatted into/from strings

To convert a message/chunk to json formatting simply call the local toJson() method.

To deserialize a json message:

Message message = new MessageBuilder().append(yourJsonStringHere);

To deserialize a json chunk:

Message message = new MessageBuilder();
Message.Chunk chunk = new JsonChunk(yourJsonStringHere);
message.append(chunk);