net.lenni0451.commandlib.nodes.StringNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of CommandLib Show documentation
Show all versions of CommandLib Show documentation
A command lib with a simple and powerful API
The newest version!
package net.lenni0451.commandlib.nodes;
import net.lenni0451.commandlib.contexts.CompletionContext;
import net.lenni0451.commandlib.contexts.ExecutionContext;
import net.lenni0451.commandlib.exceptions.ArgumentParseException;
import net.lenni0451.commandlib.utils.StringReader;
import net.lenni0451.commandlib.utils.comparator.ArgumentComparator;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Set;
/**
* The string node only matches the given string.
* The case-sensitivity is defined by the {@link ArgumentComparator} of the command executor.
*
* @param The type of the executor
*/
public class StringNode extends ArgumentNode {
public StringNode(final String name) {
super(name);
this.weight = 100;
this.providesArgument = false;
}
public StringNode(final String name, @Nullable final String description) {
super(name, description);
this.weight = 100;
this.providesArgument = false;
}
@Nonnull
@Override
protected String parseValue(ExecutionContext executionContext, StringReader reader) throws ArgumentParseException, RuntimeException {
String result = reader.readWordOrString();
if (executionContext.getArgumentComparator().compare(result, this.name())) return this.name();
throw ArgumentParseException.namedReason(this.name(), "Expected '" + this.name() + "'");
}
@Override
protected void parseCompletions(Set completions, CompletionContext completionContext, ExecutionContext executionContext, StringReader stringReader) {
completions.add(this.name());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy