Skip to content

Instantly share code, notes, and snippets.

@Dykam
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dykam/2f531f303b999b6aa808 to your computer and use it in GitHub Desktop.
Save Dykam/2f531f303b999b6aa808 to your computer and use it in GitHub Desktop.
Message Object Format
interface TextMessage {}
interface RawTextMessage extends TextMessage { String getValue(); }
interface Style extends TextMessage { TextStyle getStyle(); TextMessage getMessage(); }
interface Action extends TextMessage { TextAction getAction(); TextEvent getEvent(); TextMessage getMessage(); }
/* Combines multiple texts */
interface Combined extends TextMessage { List<TextMessage> getMessages(); }
// build message
TextFactory factory = Sponge.getTextFactory();
TextMessage message = factory.lines(
factory.color(Colors.Red,
factory.text("the text");
),
factory.combined(
factory.text("Click here: "),
factory.link("http://google.com", factory.text("Go to google")),
factory.text(". or here: "),
factory.commandSugggestion("tp owner", factory.text("Teleport to owner")
)
);
// filter out links
filter(message);
TextMessage filter(TextMessage in) {
if(!(in instanceOf Action))
return in;
Action action = (Action)in;
if(action.getAction().getName("open_url"))
return action.getMessage();
return action;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment