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

dev.jorel.commandapi.arguments.SafeOverrideableArgument Maven / Gradle / Ivy

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

import com.mojang.brigadier.arguments.ArgumentType;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;

import java.util.function.Function;

/**
 * An interface declaring methods required to override argument suggestions
 *
 * @param  The type of the underlying object that this argument casts to
 * @param  A custom type which is represented by this argument. For example,
 *            a {@link StringArgument} will have a custom type
 *            String
 */
public abstract class SafeOverrideableArgument extends Argument implements SafeOverrideable, Argument, CommandSender> {
	private final Function mapper;

	/**
	 * Instantiates this argument and assigns the mapper to the provided mapper
	 *
	 * @param nodeName the node name of this argument
	 * @param rawType  the NMS raw argument type of this argument
	 * @param mapper   the mapping function that maps this argument type to a string
	 *                 for suggestions
	 */
	protected SafeOverrideableArgument(String nodeName, ArgumentType rawType, Function mapper) {
		super(nodeName, rawType);
		this.mapper = mapper;
	}

	@Override
	public Function getMapper() {
		return mapper;
	}

	/**
	 * 

* Composes a S to a NamespacedKey mapping function to * convert S to a String * * @param mapper the mapping function from S to * NamespacedKey * @return a composed function that converts S to * String */ public static Function fromKey(Function mapper) { return mapper.andThen(NamespacedKey::toString); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy