    001/*
    002 * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
    003 *
    004 *  Permission is hereby granted, free of charge, to any person obtaining
    005 *  a copy of this software and associated documentation files (the
    006 *  "Software"), to deal in the Software without restriction, including
    007 *  without limitation the rights to use, copy, modify, merge, publish,
    008 *  distribute, sublicense, and/or sell copies of the Software, and to
    009 *  permit persons to whom the Software is furnished to do so, subject to
    010 *  the following conditions:
    011 *
    012 *  The above copyright notice and this permission notice shall be
    013 *  included in all copies or substantial portions of the Software.
    014 *
    015 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    016 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    017 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    018 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    019 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    020 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    021 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    022 */
    023
    024package co.aikar.commands;
    025
    026import co.aikar.locales.MessageKey;
    027import co.aikar.locales.MessageKeyProvider;
    028import org.jetbrains.annotations.NotNull;
    029
    030import java.util.UUID;
    031
    032public interface CommandIssuer {
    033    /**
    034     * Gets the issuer in the platforms native object
    035     * @param <T>
    036     * @return
    037     */
    038    <T> T getIssuer();
    039
    040    CommandManager getManager();
    041
    042    /**
    043     * Is this issue a player, or server/console sender
    044     * @return
    045     */
    046    boolean isPlayer();
    047
    048    /**
    049     * Send the Command Issuer a message
    050     * @param message
    051     */
    052    default void sendMessage(String message) {
    053        getManager().sendMessage(this, MessageType.INFO, MessageKeys.INFO_MESSAGE, "{message}", message);
    054    }
    055
    056    /**
    057     * @return the unique id of that issuer
    058     */
    059    @NotNull UUID getUniqueId();
    060
    061    /**
    062     * Has permission node
    063     * @param permission
    064     * @return
    065     */
    066    boolean hasPermission(String permission);
    067
    068    default void sendError(MessageKeyProvider key, String... replacements) {
    069        sendMessage(MessageType.ERROR, key.getMessageKey(), replacements);
    070    }
    071    default void sendSyntax(MessageKeyProvider key, String... replacements) {
    072        sendMessage(MessageType.SYNTAX, key.getMessageKey(), replacements);
    073    }
    074    default void sendInfo(MessageKeyProvider key, String... replacements) {
    075        sendMessage(MessageType.INFO, key.getMessageKey(), replacements);
    076    }
    077    default void sendError(MessageKey key, String... replacements) {
    078        sendMessage(MessageType.ERROR, key, replacements);
    079    }
    080    default void sendSyntax(MessageKey key, String... replacements) {
    081        sendMessage(MessageType.SYNTAX, key, replacements);
    082    }
    083    default void sendInfo(MessageKey key, String... replacements) {
    084        sendMessage(MessageType.INFO, key, replacements);
    085    }
    086    default void sendMessage(MessageType type, MessageKeyProvider key, String... replacements) {
    087        sendMessage(type, key.getMessageKey(), replacements);
    088    }
    089    default void sendMessage(MessageType type, MessageKey key, String... replacements) {
    090        getManager().sendMessage(this, type, key, replacements);
    091    }
    092
    093    /**
    094     * @deprecated Do not call this, for internal use. Not considered part of the API and may break.
    095     * @param message
    096     */
    097    @Deprecated
    098    void sendMessageInternal(String message);
    099}