Package top.focess.qq.api.command
Class CommandSender
- java.lang.Object
-
- top.focess.qq.api.command.CommandSender
-
public class CommandSender extends Object
This class present an executor to execute command. We can use it to distinguish different permissions.
-
-
Field Summary
Fields Modifier and Type Field Description static CommandSenderCONSOLEPresent CONSOLE or we call it Terminate
-
Constructor Summary
Constructors Constructor Description CommandSender(@NonNull Friend friend)Present FriendCommandSender(@NonNull Member member)Present Member in GroupCommandSender(@NonNull Stranger stranger)Present Stranger
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)voidexec(String command)Execute command with this CommandSender@Nullable BotgetBot()Get the bot@Nullable FriendgetFriend()Get the Mirai Friend instance, or null if this CommandSender does not present a Mirai Friend instance.IOHandlergetIOHandler()Get the receiver by this CommandSender@Nullable MembergetMember()Get the Mirai Member instance, or null if this CommandSender does not present a Mirai Member instance.@NonNull CommandPermissiongetPermission()Get permissionSessiongetSession()Get Session of a special CommandSender.inthashCode()booleanhasPermission(CommandPermission permission)Indicate whether this CommandSender owns the permissionbooleanisAdministrator()Indicate whether this is an AdministratorbooleanisConsole()Indicate whether it is CONSOLEbooleanisFriend()Indicate whether this is a Mirai Friend instancebooleanisMember()Indicate whether this is a Mirai Member instancebooleanisStranger()Indicate whether this is a Mirai Stranger instanceStringtoString()
-
-
-
Field Detail
-
CONSOLE
public static final CommandSender CONSOLE
Present CONSOLE or we call it Terminate
-
-
Constructor Detail
-
CommandSender
public CommandSender(@NonNull Friend friend)
Present Friend- Parameters:
friend- the Mirai Friend instance
-
CommandSender
public CommandSender(@NonNull Member member)
Present Member in Group- Parameters:
member- The Mirai Member Instance
-
CommandSender
public CommandSender(@NonNull Stranger stranger)
Present Stranger- Parameters:
stranger- The Mirai Stranger Instance
-
-
Method Detail
-
getFriend
public @Nullable Friend getFriend()
Get the Mirai Friend instance, or null if this CommandSender does not present a Mirai Friend instance.- Returns:
- the Mirai Friend instance
-
isFriend
@EnsuresNonNullIf(expression="getFriend()", result=true) public boolean isFriend()Indicate whether this is a Mirai Friend instance- Returns:
- true if this CommandSender presents a Mirai Friend instance, false otherwise
-
hasPermission
public boolean hasPermission(CommandPermission permission)
Indicate whether this CommandSender owns the permission- Parameters:
permission- the compared permission- Returns:
- true if the permission of this CommandSender is higher or equivalent to the compared permission, false otherwise
-
getMember
public @Nullable Member getMember()
Get the Mirai Member instance, or null if this CommandSender does not present a Mirai Member instance.- Returns:
- the Mirai Member instance
-
isMember
@EnsuresNonNullIf(expression="getMember()", result=true) public boolean isMember()Indicate whether this is a Mirai Member instance- Returns:
- true if this CommandSender presents a Mirai Member instance, false otherwise
-
isAdministrator
public boolean isAdministrator()
Indicate whether this is an Administrator- Returns:
- true if this CommandSender presents its id is equal to the id of the Administrator, false otherwise
-
getPermission
public @NonNull CommandPermission getPermission()
Get permission- Returns:
- permission of this sender
-
isConsole
public boolean isConsole()
Indicate whether it is CONSOLE- Returns:
- true if it is
CONSOLE, false otherwise
-
getIOHandler
public IOHandler getIOHandler()
Get the receiver by this CommandSender- Returns:
- the receiver by this CommandSender
-
exec
public void exec(String command)
Execute command with this CommandSender- Parameters:
command- the command CommandSender execute- See Also:
CommandLine.exec(CommandSender, String)
-
getSession
public Session getSession()
Get Session of a special CommandSender. It can be used to store some data for future using. But the data it stored will be lost after Bot exiting.- Returns:
- Session of sender
-
getBot
public @Nullable Bot getBot()
Get the bot- Returns:
- the bot
-
isStranger
public boolean isStranger()
Indicate whether this is a Mirai Stranger instance- Returns:
- true if this CommandSender presents a Mirai Stranger instance, false otherwise
-
-