Add compact methods to Text
@@ -193,6 +193,25 @@ static Text of(Object... objects) {
return Sponge.getRegistry().requireFactory(Factory.class).of(objects);
}
+ /**
+ * Builds a compact {@link Text} from a given array of objects.
+ *
+ * <p>Like the normal {@link #of(Object...)} method, but will try to
+ * compact the passed in text objects if possible. No guarantees are given
+ * regarding the structure of the {@link Text}, only that it will
+ * display the same.</p>
+ *
+ * <p>The result of this might be, but does not need to be equivalent to
+ * {@code Text.of(arrayOfObjects).compact()}.</p>
+ *
+ * @see #of(Object...) For more information on the normal of factory.
+ * @param objects The object array
+ * @return The built compact text object
+ */
+ static Text ofCompact(Object... objects) {
+ return Sponge.getRegistry().requireFactory(Factory.class).ofCompact(objects);
+ }
+
/**
* Creates a {@link Text.Builder} with empty text.
*
@@ -597,6 +616,17 @@ static Text joinWith(Text separator, Iterator<? extends Text> texts) {
*/
Text replace(String oldValue, Text newValue);
+ /**
+ * Removes unneeded children from this {@link Text} and it's children
+ * while keeping the appearance the same.
+ *
+ * <p>No guarantees are given regarding the structure of the {@link Text},
+ * only that it will display the same.</p>
+ *
+ * @return Text result
+ */
+ Text compact();
+
@Override
default Text toText() {
return this;
@@ -729,6 +759,18 @@ default Text toText() {
*/
List<Text> getChildren();
+ /**
+ * Gets if this builder should try to compact when appending text.
+ *
+ * @return If this builder will compact when appended text
+ */
+ boolean shouldCompact();
+
+ /**
+ * Sets if this builder should compact when appending text.
+ */
+ Builder setCompact(boolean compact);
+
/**
* Appends the specified {@link Text} to the end of this text.
*
@@ -895,6 +937,8 @@ default Text toText() {
interface Factory {
Text of(Object... objects);
+ Text ofCompact(Object... objects);
+
Text joinWith(Text separator, Text... texts);
Text joinWith(Text separator, Iterator<? extends Text> texts);
