Last active
August 29, 2015 14:06
-
-
Save Dykam/2f531f303b999b6aa808 to your computer and use it in GitHub Desktop.
Message Object Format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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