net.minestom.server.command.builder.arguments.ArgumentStringArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.command.builder.arguments;
import net.minestom.server.command.CommandSender;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.utils.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Pattern;
/**
* Represents an argument which will take all the remaining of the command.
*
* Example: Hey I am a string
*/
public class ArgumentStringArray extends Argument {
public ArgumentStringArray(String id) {
super(id, true, true);
}
@NotNull
@Override
public String[] parse(@NotNull CommandSender sender, @NotNull String input) {
return input.split(Pattern.quote(StringUtils.SPACE));
}
@Override
public String parser() {
return "brigadier:string";
}
@Override
public byte @Nullable [] nodeProperties() {
return NetworkBuffer.makeArray(NetworkBuffer.VAR_INT, 2); // Greedy phrase
}
@Override
public String toString() {
return String.format("StringArray<%s>", getId());
}
}