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.sender; 018 019import com.github.siroshun09.adventureextender.MessageReceivable; 020import org.jetbrains.annotations.NotNull; 021 022import java.util.UUID; 023 024/** 025 * Interface that wraps a CommandSender that is different on different platforms. 026 */ 027public interface Sender extends MessageReceivable { 028 029 /** 030 * Gets the {@link UUID} of the command sender. 031 * <p> 032 * If it is internal sender, returns {@link ConsoleSender#CONSOLE_UUID}. 033 * 034 * @return sender's {@link UUID}. 035 */ 036 @NotNull 037 UUID getUUID(); 038 039 /** 040 * Gets the name of the command sender. 041 * <p> 042 * If it is internal sender, returns {@link ConsoleSender#CONSOLE_NAME}. 043 * 044 * @return sender's name. 045 */ 046 @NotNull 047 String getName(); 048 049 /** 050 * Checks if the {@link Sender} has the requested permission. 051 * 052 * @param perm a permission. 053 * @return {@code true} if the sender have permission, {@code false} otherwise 054 */ 055 boolean hasPermission(@NotNull String perm); 056 057 /** 058 * Checks if the sender is online. 059 * 060 * @return {@code true} if the sender is online, {@code false} otherwise. 061 */ 062 boolean isOnline(); 063 064 /** 065 * Checks if the sender is console. 066 * 067 * @return {@code true} if the sender is console, {@code false} otherwise. 068 */ 069 default boolean isConsole() { 070 return getUUID().equals(ConsoleSender.CONSOLE_UUID); 071 } 072 073 /** 074 * Gets the command sender that the instance is wrapped in. 075 * 076 * @return the original command sender 077 */ 078 @NotNull Object getOriginalSender(); 079}