Skip to content

Instantly share code, notes, and snippets.

@mattmess1221
Created September 11, 2014 19:25
Show Gist options
  • Save mattmess1221/8cb1be0237869d4a9250 to your computer and use it in GitHub Desktop.
Save mattmess1221/8cb1be0237869d4a9250 to your computer and use it in GitHub Desktop.
Text Message Builder for Sponge
package org.spongepowered.api.util;
/**
* Base interface for creating a Builder.
*
* @param B The builder
* @param T The type this builder is building
*/
public interface Builder<B extends Builder<?, T>, T> {
/**
* Builds the object {@code T}.
*
* @return
*/
T build();
/**
* Gets the object at the given index.
*
* @param index
* @return
*/
T getObjectAt(int index);
/**
* Gets an iterable list of objects in this builder.
*
* @return
*/
Iterable<T> iterate();
/**
* Sets the next Object to be inserted at the given index.
*
* @param index
* @return This instance
*/
B setIndex(int index);
/**
* Sets the next object to be inserted at the end.
*
* @return This instance
*/
B setIndexLast();
/**
* Resets the builder, removing all added objects.
*
* @return
*/
B reset();
}
package org.spongepowered.api.text;
import java.net.URL;
import org.spongepowered.api.util.Builder;
/**
* Builder for easily creating messages.
*/
public interface MessageBuilder extends Builder<MessageBuilder, TextMessage> {
/**
* Appends a message to the end of this builder.
*
* @param text
* @param formats
* @return This instance
*/
MessageBuilder appendString(String text, TextFormatting... formats);
/**
* Appends a message with an event to the end of this builder. Can be either
* click or hover.
*
* @param display
* @param action
* @param value
* @param formats
* @return This instance.
*/
MessageBuilder append(String display, TextAction action, String value,
TextFormatting... formats);
/**
* Appends a message with a link to the end of this builder.<br/>
* <p>
* Same thing as calling
* {@code appendEvent(display, TextAction.OPEN_LINK, url.toString(), formats);}
* </p>
* <p>
* file:// protocols are not allowed.
* </p>
*
* @param display Text to display
* @param url The URL of the link. File:// protocols are not allowed.
* @param formats The formatting codes to use.
* @return This instance.
*/
MessageBuilder appendLink(String display, URL url,
TextFormatting... formats);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment