97 lines
2.7 KiB
Java
97 lines
2.7 KiB
Java
package envoy.client.data.commands;
|
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Supplier;
|
|
|
|
/**
|
|
* This class is the base class of all {@code SystemCommands} and contains an
|
|
* action and a number of arguments that should be used as input for this
|
|
* function.
|
|
* No {@code SystemCommand} can return anything.
|
|
* Every {@code SystemCommand} must have as argument type {@code String[]} so
|
|
* that the words following the indicator String can be used as input of the
|
|
* function. This approach has one limitation:<br>
|
|
* <b>Order matters!</b> Changing the order of arguments will likely result in
|
|
* unexpected behavior.
|
|
* <p>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>SystemCommand.java</strong><br>
|
|
* Created: <strong>16.07.2020</strong><br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public class SystemCommand implements OnCall {
|
|
|
|
/**
|
|
* The argument count of the command.
|
|
*/
|
|
protected final int numberOfArguments;
|
|
|
|
/**
|
|
* This function takes a {@code String[]} as argument because automatically
|
|
* {@code SystemCommand#numberOfArguments} words following the necessary command
|
|
* will be put into this array.
|
|
*
|
|
* @see String#split(String)
|
|
*/
|
|
protected final Function<String[], Void> action;
|
|
|
|
protected final String description;
|
|
|
|
protected int relevance;
|
|
|
|
/**
|
|
* Constructs a new {@code SystemCommand}.
|
|
*
|
|
* @param action the action performed by the command
|
|
* @param numberOfArguments the argument count accepted by the action
|
|
* @param description the description of this {@code SystemCommand}
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public SystemCommand(Function<String[], Void> action, int numberOfArguments, String description) {
|
|
this.numberOfArguments = numberOfArguments;
|
|
this.action = action;
|
|
this.description = description;
|
|
}
|
|
|
|
/**
|
|
* @return the action that should be performed
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public Function<String[], Void> getAction() { return action; }
|
|
|
|
/**
|
|
* @return the argument count of the command
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public int getNumberOfArguments() { return numberOfArguments; }
|
|
|
|
/**
|
|
* @return the description
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public String getDescription() { return description; }
|
|
|
|
/**
|
|
* @return the relevance
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public int getRelevance() { return relevance; }
|
|
|
|
/**
|
|
* @param relevance the relevance to set
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public void setRelevance(int relevance) { this.relevance = relevance; }
|
|
|
|
@Override
|
|
public void onCall() { relevance++; }
|
|
|
|
@Override
|
|
public void onCall(Supplier<Void> consumer) {
|
|
onCall();
|
|
consumer.get();
|
|
}
|
|
}
|