001package com.mrivanplays.commandworker.core.argument; 002 003import com.mojang.brigadier.arguments.ArgumentType; 004import com.mojang.brigadier.suggestion.SuggestionsBuilder; 005import java.util.List; 006import java.util.function.Consumer; 007import org.jetbrains.annotations.NotNull; 008import org.jetbrains.annotations.Nullable; 009 010/** 011 * Represents wrapped argument, which would get wrapped in a brigadier one later when command is 012 * being registered. 013 */ 014public interface Argument { 015 016 /** 017 * Returns the name of the argument. Usually the completion you see if the argument is literal 018 * 019 * @return name 020 */ 021 @NotNull 022 String getName(); 023 024 /** 025 * Returns the brigadier argument type, if the argument is required. 026 * 027 * <p>A literal argument does not have a dedicated argument type, and this will return null if the 028 * argument is literal. 029 * 030 * @param <T> the type held by the argument type. 031 * @return argument type 032 */ 033 @Nullable 034 default <T> ArgumentType<T> getArgumentType() { 035 return null; 036 } 037 038 /** 039 * Returns whether or not this argument is literal. 040 * 041 * @return <code>true</code> if literal, <code>false</code> otherwise 042 */ 043 default boolean isLiteral() { 044 return getArgumentType() == null; 045 } 046 047 /** 048 * Returns the {@link SuggestionsBuilder} consumer, which is able to modify the suggestions for 049 * this argument. By default, this returns null. 050 * 051 * <p><i>We do not suggest using suggestions builder to add your suggestions. Instead, use literal 052 * arguments with combination with a required one</i> 053 * 054 * @return suggestions consumer 055 */ 056 @Nullable 057 default Consumer<SuggestionsBuilder> getSuggestionsConsumer() { 058 return null; 059 } 060 061 /** 062 * Returns whether or not this argument should call the base command's execute method when the 063 * argument ends up being the last typed argument. This marking is being ignored if brigadier 064 * isn't supported for the minecraft version your plugin is being ran on. 065 * 066 * @return <code>true</code> if should have execute, <code>false</code> otherwise 067 */ 068 boolean shouldExecuteCommand(); 069 070 /** 071 * Returns unmodifiable copy of the children this argument is holding. 072 * 073 * @return children 074 */ 075 @NotNull 076 List<Argument> getChildren(); 077}