Skip to content

Chat Displays

Faizaan edited this page Jun 24, 2017 · 1 revision

ChatDisplays allow you to create and send uniformly formatted messages to users. It's important that Prison, and modules built for Prison, use a consistent user interface as to not confuse users and to keep the experience clean. ChatDisplays help to do just that.

Creating a ChatDisplay

ChatDisplays are very easy to create. You begin by initializing it with a title.

ChatDisplay display = new ChatDisplay("Title Here");

Next, you add some DisplayComponents to it. A DisplayComponent is a single segment on the ChatDisplay. As of now, there are three components. Let's see how to use each of them here.

The TextComponent

The text component is the most basic of the group. It simply sends a string of colorizable text to the recipient.

TextComponent text = new TextComponent("&7We are &b#&d!", 1);
display.addComponent(text);

As you can see, it's very straightforward. Most, if not all, of the time, we don't even have to use the TextComponent class. ChatDisplay comes with an inbuilt utility method to do the exact same thing more concisely.

display.text("&7We are &b#%d!", 1);

You may also add empty lines by calling display.emptyLine().

ProTip You can chain your ChatDisplay method calls. For example, typing new ChatDisplay("Title").text("...").text("...").addComponent(...)... will work!

The FancyMessageComponent

Prison comes pre-packaged with an adapted version of the FancyMessage API. You may add these FancyMessages to your ChatDisplay.

FancyMessage msg = new FancyMessage("Click me!").link("http://mc-prison.tech");
FancyMessageComponent fancyMessage = new FancyMessageComponent(msg);
display.addComponent(fancyMessage);

The BulletedListComponent

Sometimes, you want to present a list of stuff to the user. You can do this easily with the BulletedListComponent. However, unlike the other DisplayComponents, you must use the BulletedListComponent.BulletedListBuilder builder to make it.

BulletedListComponent.BulletedListBuilder builder = new BulletedListComponent.BulletedListBuilder();
BulletedListComponent bulletedList = builder.add("Line 1").add("Line 2").build();        
display.addComponent(bulletedList);

Very simple.

Sending your ChatDisplay

Now that you've created your ChatDisplay, you'll want to send it. To do that, simply invoke the ChatDisplay.send(CommandSender) method.

// ...
display.send(sender);

All done! You've just learned how to use the useful ChatDisplay API to create nice-looking messages for your users. Go ahead and use this to craft something awesome.