All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.jorel.commandapi.Execution Maven / Gradle / Ivy

There is a newer version: 9.5.3
Show newest version
package dev.jorel.commandapi;

import dev.jorel.commandapi.arguments.AbstractArgument;
import dev.jorel.commandapi.commandsenders.AbstractCommandSender;

import java.util.ArrayList;
import java.util.List;

/**
 * A list of arguments which results in an execution. This is used for building branches in a {@link AbstractCommandTree}
 */
public class Execution
/// @endcond
> {

	private final List arguments;
	private final CommandAPIExecutor> executor;

	public Execution(List arguments, CommandAPIExecutor> executor) {
		this.arguments = arguments;
		this.executor = executor;
	}

	/**
	 * Register a command with the given arguments and executor to brigadier, by converting it into a {@link AbstractCommandAPICommand}
	 *
	 * @param meta The metadata to register the command with
	 * @param namespace The namespace to use for this command
	 */
	public void register(CommandMetaData meta, String namespace) {
		@SuppressWarnings("unchecked")
		CommandAPIPlatform platform = (CommandAPIPlatform) CommandAPIHandler.getInstance().getPlatform();
		AbstractCommandAPICommand command = platform.newConcreteCommandAPICommand(meta);
		command.withArguments(this.arguments);
		command.setExecutor(this.executor);
		command.register(namespace);
	}

	public Execution prependedBy(Argument argument) {
		List args = new ArrayList<>();
		args.add(argument);
		args.addAll(this.arguments);
		return new Execution<>(args, this.executor);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy