Implements the add condition command and its tab completion
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.utility.TabCompleteHelper;
|
||||
import net.knarcraft.paidsigns.utility.Tokenizer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The tab completer for the add paid sign condition command
|
||||
*/
|
||||
public class AddConditionTabCompleter implements TabCompleter {
|
||||
|
||||
private List<String> lineIndices;
|
||||
private List<String> stringsToMatch;
|
||||
private List<String> booleans;
|
||||
private List<String> optionStates;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
if (lineIndices == null) {
|
||||
initializeValues();
|
||||
}
|
||||
|
||||
List<String> arguments = Tokenizer.tokenize(String.join(" ", args));
|
||||
int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
|
||||
if (argumentSize < 1) {
|
||||
return TabCompleteHelper.getPaidSignNames();
|
||||
} else if (argumentSize < 2) {
|
||||
return this.lineIndices;
|
||||
} else if (argumentSize < 3) {
|
||||
return stringsToMatch;
|
||||
} else if (argumentSize < 4) {
|
||||
return booleans;
|
||||
} else if (argumentSize < 6) {
|
||||
return optionStates;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the values available for tab completion
|
||||
*/
|
||||
private void initializeValues() {
|
||||
lineIndices = TabCompleteHelper.getSignLines();
|
||||
stringsToMatch = TabCompleteHelper.getExampleConditionStrings();
|
||||
booleans = TabCompleteHelper.getBooleans();
|
||||
optionStates = TabCompleteHelper.getOptionStates();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user