001/*
002 *     Copyright 2021 Siroshun09
003 *
004 *     Licensed under the Apache License, Version 2.0 (the "License");
005 *     you may not use this file except in compliance with the License.
006 *     You may obtain a copy of the License at
007 *
008 *         http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *     Unless required by applicable law or agreed to in writing, software
011 *     distributed under the License is distributed on an "AS IS" BASIS,
012 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *     See the License for the specific language governing permissions and
014 *     limitations under the License.
015 */
016
017package com.github.siroshun09.mccommand.common;
018
019import com.github.siroshun09.mccommand.common.context.CommandContext;
020import org.jetbrains.annotations.NotNull;
021import org.jetbrains.annotations.Unmodifiable;
022
023import java.util.Collections;
024import java.util.List;
025import java.util.Set;
026
027/**
028 * Represents a command.
029 */
030public interface Command {
031
032    /**
033     * Gets the name of this command.
034     *
035     * @return the name of this command
036     */
037    @NotNull
038    String getName();
039
040    /**
041     * Gets the permission to execute this command.
042     *
043     * @return the permission to execute this command
044     */
045    @NotNull
046    String getPermission();
047
048    /**
049     * Gets aliases of this command.
050     *
051     * @return aliases of this command
052     */
053    @NotNull
054    @Unmodifiable
055    default Set<String> getAliases() {
056        return Collections.emptySet();
057    }
058
059    /**
060     * The method to call when this command is executed.
061     *
062     * @param context the context of the executed command
063     * @return the execution result
064     */
065    @SuppressWarnings("UnusedReturnValue")
066    @NotNull
067    CommandResult onExecution(@NotNull CommandContext context);
068
069    /**
070     * The method to call when command tab completion is requested.
071     *
072     * @param context the context of the command line when tab completion is requested
073     * @return the tab completion result
074     */
075    @NotNull
076    List<String> onTabCompletion(@NotNull CommandContext context);
077}