Package xyz.srnyx.annoyingapi.command
Class AnnoyingSender
- java.lang.Object
-
- xyz.srnyx.javautilities.parents.Stringable
-
- xyz.srnyx.annoyingapi.Arguments
-
- xyz.srnyx.annoyingapi.command.AnnoyingSender
-
- All Implemented Interfaces:
Annoyable
public class AnnoyingSender extends Arguments implements Annoyable
This class is typically used in conjunction withAnnoyingCommand
-
-
Field Summary
Fields Modifier and Type Field Description @NotNull org.bukkit.command.CommandSendercmdSenderTheCommandSenderthat was used to initialize thisAnnoyingSender@Nullable org.bukkit.command.CommandcommandTheCommandthat was usedbooleanisPlayerWhether thecmdSenderis aPlayer@Nullable java.lang.StringlabelTheCommand's label that was used@NotNull AnnoyingPluginpluginTheAnnoyingPlugininstance
-
Constructor Summary
Constructors Constructor Description AnnoyingSender(@NotNull AnnoyingPlugin plugin, @NotNull org.bukkit.command.CommandSender cmdSender)Constructs a newAnnoyingSenderwithout aCommandAnnoyingSender(@NotNull AnnoyingPlugin plugin, @NotNull org.bukkit.command.CommandSender cmdSender, @Nullable org.bukkit.command.Command command, @Nullable java.lang.String label, @Nullable java.lang.String[] args)Constructs a newAnnoyingSender
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckPermission(@NotNull java.lang.String permission)Checks if theCommandSenderhas the specified permission.booleancheckPlayer()Checks if theCommandSenderis aPlayer.booleanequalsSender(@NotNull org.bukkit.command.CommandSender sender)Checks if the providedCommandSenderis the same as thecmdSender@NotNull AnnoyingPlugingetAnnoyingPlugin()TheAnnoyingPlugininstance<T> TgetArgument(int index, @NotNull java.util.function.Function<java.lang.String,T> function)Gets the argument at the specified index after applying the specified function
If it'snullbefore/after the function, send the invalid argument message
Example usage:<T> @NotNull java.util.Optional<T>getArgumentOptional(int index, @NotNull java.util.function.Function<java.lang.String,T> function)Gets the argument at the specified index as anOptionalafter applying the specified function
If it'semptybefore/after the function, send the invalid argument message
Example usage:<T> @NotNull java.util.Optional<T>getArgumentOptionalFlat(int index, @NotNull java.util.function.Function<java.lang.String,java.util.Optional<T>> function)Gets the argument at the specified index as anOptionalafter applying the specified function and flattening it
If it'semptybefore/after the function, send the invalid argument message
Example usage:@NotNull org.bukkit.entity.PlayergetPlayer()Casts theCommandSenderto aPlayer@NotNull java.util.Optional<org.bukkit.entity.Player>getPlayerOptional()Returns thePlayeras anOptional, empty if theCommandSenderis not aPlayer
If you know that theCommandSenderis aPlayer, usegetPlayer()instead@Nullable org.bukkit.entity.PlayergetPlayerOrNull()If theCommandSenderis aPlayer, it returns it as one.voidinvalidArgument(@Nullable java.lang.Object argument)Sends the invalid argument message, replacing%argument%with the specified argumentvoidinvalidArgumentByIndex(int index)Sends the invalid argument message, replacing%argument%with the specified argument
IfArguments.argsisnullor the specified index is out of bounds, it logs a warning to consolevoidinvalidArguments()Sends the invalid arguments message-
Methods inherited from class xyz.srnyx.annoyingapi.Arguments
argEquals, getArgument, getArgumentOptional, getArgumentsJoined, getArgumentsJoined, getArgumentsJoined
-
-
-
-
Field Detail
-
plugin
@NotNull public final @NotNull AnnoyingPlugin plugin
TheAnnoyingPlugininstance
-
cmdSender
@NotNull public final @NotNull org.bukkit.command.CommandSender cmdSender
TheCommandSenderthat was used to initialize thisAnnoyingSender
-
command
@Nullable public final @Nullable org.bukkit.command.Command command
TheCommandthat was used
-
label
@Nullable public final @Nullable java.lang.String label
TheCommand's label that was used
-
isPlayer
public final boolean isPlayer
Whether thecmdSenderis aPlayer
-
-
Constructor Detail
-
AnnoyingSender
public AnnoyingSender(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull org.bukkit.command.CommandSender cmdSender, @Nullable @Nullable org.bukkit.command.Command command, @Nullable @Nullable java.lang.String label, @Nullable @Nullable java.lang.String[] args)Constructs a newAnnoyingSender- Parameters:
plugin- theAnnoyingPlugininstancecmdSender- theCommandSenderto be usedcommand- theCommandthat was usedlabel- theCommand's label that was usedargs- theCommand's arguments that were used
-
AnnoyingSender
public AnnoyingSender(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull org.bukkit.command.CommandSender cmdSender)Constructs a newAnnoyingSenderwithout aCommand- Parameters:
plugin- theAnnoyingPlugininstancecmdSender- theCommandSenderto be used
-
-
Method Detail
-
getAnnoyingPlugin
@NotNull public @NotNull AnnoyingPlugin getAnnoyingPlugin()
Description copied from interface:AnnoyableTheAnnoyingPlugininstance- Specified by:
getAnnoyingPluginin interfaceAnnoyable- Returns:
- the plugin instance
-
equalsSender
public boolean equalsSender(@NotNull @NotNull org.bukkit.command.CommandSender sender)Checks if the providedCommandSenderis the same as thecmdSender- Parameters:
sender- theCommandSenderto check- Returns:
- if the provided
CommandSenderis the same as thecmdSender
-
checkPlayer
public boolean checkPlayer()
Checks if theCommandSenderis aPlayer. If they aren't, it sends theMessagesOptions.MessageKeys.playerOnlymessage- Returns:
- whether the
CommandSenderis aPlayer
-
checkPermission
public boolean checkPermission(@NotNull @NotNull java.lang.String permission)Checks if theCommandSenderhas the specified permission. If they don't, it sends theMessagesOptions.MessageKeys.noPermissionmessage- Parameters:
permission- the permission to check- Returns:
- if the
CommandSenderhas the specified permission
-
getPlayer
@NotNull public @NotNull org.bukkit.entity.Player getPlayer()
Casts theCommandSenderto aPlayerOnly use this if you know that the
CommandSenderis aPlayer, otherwise usegetPlayerOrNull()- Returns:
- the
Playerthat was used - Throws:
java.lang.IllegalStateException- if theCommandSenderis not aPlayer- See Also:
getPlayerOrNull()
-
getPlayerOrNull
@Nullable public @Nullable org.bukkit.entity.Player getPlayerOrNull()
If theCommandSenderis aPlayer, it returns it as one. Otherwise, it returnsnull
If you know that theCommandSenderis aPlayer, usegetPlayer()instead- Returns:
- the
Player, ornullif theCommandSenderis not aPlayer - See Also:
getPlayer()
-
getPlayerOptional
@NotNull public @NotNull java.util.Optional<org.bukkit.entity.Player> getPlayerOptional()
Returns thePlayeras anOptional, empty if theCommandSenderis not aPlayer
If you know that theCommandSenderis aPlayer, usegetPlayer()instead- Returns:
- the
Playeras anOptional - See Also:
getPlayer()
-
getArgument
@Nullable public <T> T getArgument(int index, @NotNull @NotNull java.util.function.Function<java.lang.String,T> function)Gets the argument at the specified index after applying the specified function
If it'snullbefore/after the function, send the invalid argument message
Example usage:final Player target = sender.getArgument(2, Bukkit::getPlayer); if (target == null) return;- Type Parameters:
T- the type of the argument- Parameters:
index- the argument indexfunction- the function to apply to the argument- Returns:
- the argument at the specified index after applying the specified function
-
getArgumentOptional
@NotNull public <T> @NotNull java.util.Optional<T> getArgumentOptional(int index, @NotNull @NotNull java.util.function.Function<java.lang.String,T> function)Gets the argument at the specified index as anOptionalafter applying the specified function
If it'semptybefore/after the function, send the invalid argument message
Example usage:final Optional<Player> target = sender.getArgument(2, Bukkit::getPlayer); if (!target.isPresent()) return;- Type Parameters:
T- the type of the argument- Parameters:
index- the argument indexfunction- the function to apply to the argument- Returns:
- the argument at the specified index as an
Optionalafter applying the specified function
-
getArgumentOptionalFlat
@NotNull public <T> @NotNull java.util.Optional<T> getArgumentOptionalFlat(int index, @NotNull @NotNull java.util.function.Function<java.lang.String,java.util.Optional<T>> function)Gets the argument at the specified index as anOptionalafter applying the specified function and flattening it
If it'semptybefore/after the function, send the invalid argument message
Example usage:final Optional<OfflinePlayer> target = sender.getArgumentFlat(2, BukkitUtility::getOfflinePlayer); if (!target.isPresent()) return;- Type Parameters:
T- the type of the argument- Parameters:
index- the argument indexfunction- the function to apply to the argument- Returns:
- the argument at the specified index as an
Optionalafter applying the specified function and flattening it
-
invalidArgument
public void invalidArgument(@Nullable @Nullable java.lang.Object argument)Sends the invalid argument message, replacing%argument%with the specified argument- Parameters:
argument- the argument to replace%argument%with
-
invalidArgumentByIndex
public void invalidArgumentByIndex(int index)
Sends the invalid argument message, replacing%argument%with the specified argument
IfArguments.argsisnullor the specified index is out of bounds, it logs a warning to console- Parameters:
index- the argument index
-
invalidArguments
public void invalidArguments()
Sends the invalid arguments message
-
-