Skip to content

Concatenation

Gellért Dániel edited this page Feb 20, 2022 · 11 revisions

This is for to concatenate arguments' value into a single value with a concatenation process. Concatenator belongs to command and it can be registered with Command#addConcatenator(Concatenator, Argument...) with a type of Concatenator and a list of arguments that values have to be concatenated as parameter. Multiple concatenators can be specified, but the order is matter! If there is a concatenator that uses the same arguments that has been concatenated before by another concatenator, the concatenated value will be passed to the second concatenator instead of the single values. That means for example if there is a concatenator that concatenates two string values into one, and there is another concatenator that uses the same two arguments, the second concatenator will get just one string value, that is the result of the first concatenator.

Optional arguments do not get concatenated when they are not set. Values that gets concatenated gets replaced in the action listener with the result of the concatenation process.

There are two types of concatenators in this resource by default:

String concatenator

Concatenates the values into a String separated with a delimiter. It takes just the delimiter as parameter that is a string value.

Adding concatenator to command:

// In this case every value will be separated by a space
command.addConcatenator(new StringConcatenator(" "), argument1, argument2);

In the action listener the two string values gets replaced with concatenated string value:

String concatenated = event.getArguments()[0].get();

Type concatenator

Concatenates the values into a specified type. It uses reflection to create an instance of the type by calling its constructor that matches the parameters' count, order and type. It takes a Class<?> as parameter that is the class of the type the values have to be concatenated to.

Adding concatenator to command (the parameter's order matters, they have to match with one of the constructor in that class!):

// This returns an instance of the Command class with the name and description specified in the arguments
command.addConcatenator(new TypeConcatenator(Command.class), stringNameArgument, stringDescArgument);

In the action listener the two string values gets replaced with the instance of the type:

Command command = event.getArguments()[0].get();