me.deecaad.core.commands.SuggestionsBuilder Maven / Gradle / Ivy
package me.deecaad.core.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.IntStream;
public class SuggestionsBuilder {
private final List options;
private Function function;
public SuggestionsBuilder() {
this.options = new ArrayList<>();
}
/**
* Adds the given option to the suggestions list. The given type may be a {@link List}, an
* {@link java.lang.reflect.Array}, a {@link Tooltip}, or any object that overrides the
* {@link #toString()} method to produce a simple, human-readable result.
*
*
* For example, 'DOG', 'HOUSE', 'ALL', and 'GLASS' are all readable, but 'MyObject@3423',
* 'MyObject{a=2, b=3, c=4}' are not readable. In general, suggestions should not include special
* characters or spaces (See
* {@link com.mojang.brigadier.StringReader#isAllowedInUnquotedString(char)}).
*
* @param option The non-null option to add to the suggestions list.
* @return A non-null reference to this (builder-pattern).
*/
@SuppressWarnings("unchecked")
public SuggestionsBuilder with(Object option) {
if (option == null)
throw new IllegalArgumentException("option cannot be null");
// I highly doubt people will add their own Tooltips or lists like
// this, since their code would be unreadable. However, we will
// support nested arrays/lists.
if (option instanceof Tooltip)
options.add((Tooltip) option);
else if (option instanceof Collection)
with((Collection