Package xyz.srnyx.annoyingapi.command
Class AnnoyingSender
java.lang.Object
xyz.srnyx.javautilities.parents.Stringable
xyz.srnyx.javautilities.objects.Arguments
xyz.srnyx.annoyingapi.command.AnnoyingSender
- All Implemented Interfaces:
Annoyable
This class is typically used in conjunction with
AnnoyingCommand-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal @NotNull org.bukkit.command.CommandSenderTheCommandSenderthat was used to initialize thisAnnoyingSenderfinal @Nullable org.bukkit.command.CommandTheCommandthat was usedfinal booleanWhether thecmdSenderis aPlayerfinal @Nullable StringTheCommand's label that was usedfinal @NotNull AnnoyingPluginTheAnnoyingPlugininstanceFields inherited from class xyz.srnyx.javautilities.objects.Arguments
args -
Constructor Summary
ConstructorsConstructorDescriptionAnnoyingSender(@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 String label, @Nullable String[] args) Constructs a newAnnoyingSender -
Method Summary
Modifier and TypeMethodDescription@NotNull Collection<String> addSelectorKeysTo(@NotNull Collection<String> collection) Adds all registered selector keys to a collection
This modifies the input collection!@NotNull Collection<String> addSelectorKeysTo(@NotNull Collection<String> collection, @NotNull Class<?> type) Adds all registered selector keys for a specific type to a collection
This modifies the input collection!booleancheckPermission(@NotNull String permission) Checks if theCommandSenderhas the specified permission.booleanChecks if theCommandSenderis aPlayer.booleanequalsSender(@NotNull org.bukkit.command.CommandSender sender) Checks if the providedCommandSenderis the same as thecmdSender@NotNull AnnoyingPluginTheAnnoyingPlugininstance<T> TgetArgument(int index, @NotNull Function<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 Optional<T> getArgumentOptional(int index, @NotNull Function<String, T> function) <T> @NotNull Optional<T> getArgumentOptionalFlat(int index, @NotNull Function<String, Optional<T>> function) @NotNull StringGets the full/raw command that was used with the arguments (without/)
Example:command arg1 arg2 arg3@Nullable org.bukkit.LocationGets theLocationof theCommandSender@NotNull Optional<org.bukkit.Location> @NotNull org.bukkit.entity.PlayerCasts theCommandSenderto aPlayer@NotNull Optional<org.bukkit.entity.Player> Returns thePlayeras anOptional, empty if theCommandSenderis not aPlayer
If you know that theCommandSenderis aPlayer, usegetPlayer()instead@Nullable org.bukkit.entity.PlayerIf theCommandSenderis aPlayer, it returns it as one.<T> @NotNull SelectorOptional<T> getSelector(int index, @NotNull Class<T> type) Gets the selector at the specified index as aSelectorOptionalGets a list of all registered selector keysgetSelectorKeys(@NotNull Class<?> type) Gets a list of all registered selector keys for a specific typevoidinvalidArgument(@Nullable 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 consolevoidSends the invalid arguments message@NotNull Collection<String> withSelectorKeys(@NotNull Collection<String> collection) Adds all registered selector keys to the beginning of a collection
This returns a NEW List, it does not modify the input collection!withSelectorKeys(@NotNull Collection<String> collection, @NotNull Class<?> type) Adds all registered selector keys for a specific type to the beginning of a collection
This returns a NEW List, it does not modify the input collection!Methods inherited from class xyz.srnyx.javautilities.objects.Arguments
argEquals, getArgument, getArgumentOptional, getArgumentsJoined, getArgumentsJoined, getArgumentsJoinedMethods inherited from class xyz.srnyx.javautilities.parents.Stringable
toString, toString, toString, toString, toString
-
Field Details
-
plugin
TheAnnoyingPlugininstance -
cmdSender
@NotNull public final @NotNull org.bukkit.command.CommandSender cmdSenderTheCommandSenderthat was used to initialize thisAnnoyingSender -
command
@Nullable public final @Nullable org.bukkit.command.Command commandTheCommandthat was used -
label
TheCommand's label that was used -
isPlayer
public final boolean isPlayerWhether thecmdSenderis aPlayer
-
-
Constructor Details
-
AnnoyingSender
public AnnoyingSender(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull org.bukkit.command.CommandSender cmdSender, @Nullable @Nullable org.bukkit.command.Command command, @Nullable @Nullable String label, @Nullable @Nullable 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 Details
-
getAnnoyingPlugin
Description copied from interface:AnnoyableTheAnnoyingPlugininstance- Specified by:
getAnnoyingPluginin interfaceAnnoyable- Returns:
- the plugin instance
-
getFullCommand
Gets the full/raw command that was used with the arguments (without/)
Example:command arg1 arg2 arg3- Returns:
- the full/raw command that was used with the arguments
-
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
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:
IllegalStateException- if theCommandSenderis not aPlayer- See Also:
-
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:
-
getPlayerOptional
Returns thePlayeras anOptional, empty if theCommandSenderis not aPlayer
If you know that theCommandSenderis aPlayer, usegetPlayer()instead- Returns:
- the
Playeras anOptional - See Also:
-
getLocationOfSender
@Nullable public @Nullable org.bukkit.Location getLocationOfSender()Gets theLocationof theCommandSender- Returns:
- the
Locationof theCommandSender, ornullif it cannot be determined - See Also:
-
getLocationOfSenderOptional
- Returns:
- the
Locationof theCommandSenderas anOptional, empty if it cannot be determined - See Also:
-
getArgument
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 Optional<T> getArgumentOptional(int index, @NotNull @NotNull Function<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 Optional<T> getArgumentOptionalFlat(int index, @NotNull @NotNull Function<String, 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
-
getSelector
@NotNull public <T> @NotNull SelectorOptional<T> getSelector(int index, @NotNull @NotNull Class<T> type) Gets the selector at the specified index as aSelectorOptional- Type Parameters:
T- the type of the selector- Parameters:
index- the argument indextype- the selector type- Returns:
- the selector at the specified index as a
SelectorOptional
-
getSelectorKeys
Gets a list of all registered selector keys- Returns:
- a list of all registered selector keys
-
getSelectorKeys
Gets a list of all registered selector keys for a specific type- Parameters:
type- the type to filter by- Returns:
- a list of all registered selector keys for the specified type
-
withSelectorKeys
@NotNull public @NotNull Collection<String> withSelectorKeys(@NotNull @NotNull Collection<String> collection) Adds all registered selector keys to the beginning of a collection
This returns a NEW List, it does not modify the input collection!- Parameters:
collection- the collection to add to- Returns:
- the collection with all registered selector keys added
- See Also:
-
withSelectorKeys
@NotNull public @NotNull List<String> withSelectorKeys(@NotNull @NotNull Collection<String> collection, @NotNull @NotNull Class<?> type) Adds all registered selector keys for a specific type to the beginning of a collection
This returns a NEW List, it does not modify the input collection!- Parameters:
collection- the collection to add totype- the type to filter by- Returns:
- the collection with all registered selector keys for the specified type added
- See Also:
-
addSelectorKeysTo
@NotNull public @NotNull Collection<String> addSelectorKeysTo(@NotNull @NotNull Collection<String> collection) Adds all registered selector keys to a collection
This modifies the input collection!- Parameters:
collection- the collection to add to- Returns:
- the collection with all registered selector keys added (for convenience)
- See Also:
-
addSelectorKeysTo
@NotNull public @NotNull Collection<String> addSelectorKeysTo(@NotNull @NotNull Collection<String> collection, @NotNull @NotNull Class<?> type) Adds all registered selector keys for a specific type to a collection
This modifies the input collection!- Parameters:
collection- the collection to add totype- the type to filter by- Returns:
- the collection with all registered selector keys added (for convenience)
- See Also:
-
invalidArgument
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
-