Class AnnoyingSender

java.lang.Object
xyz.srnyx.javautilities.parents.Stringable
xyz.srnyx.javautilities.objects.Arguments
xyz.srnyx.annoyingapi.command.AnnoyingSender
All Implemented Interfaces:
Annoyable

public class AnnoyingSender extends xyz.srnyx.javautilities.objects.Arguments implements Annoyable
This class is typically used in conjunction with AnnoyingCommand
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final @NotNull org.bukkit.command.CommandSender
    The CommandSender that was used to initialize this AnnoyingSender
    final @Nullable org.bukkit.command.Command
    The Command that was used
    final boolean
    Whether the cmdSender is a Player
    final @Nullable String
    The Command's label that was used
    final @NotNull AnnoyingPlugin
    The AnnoyingPlugin instance

    Fields inherited from class xyz.srnyx.javautilities.objects.Arguments

    args
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnnoyingSender(@NotNull AnnoyingPlugin plugin, @NotNull org.bukkit.command.CommandSender cmdSender)
    Constructs a new AnnoyingSender without a Command
    AnnoyingSender(@NotNull AnnoyingPlugin plugin, @NotNull org.bukkit.command.CommandSender cmdSender, @Nullable org.bukkit.command.Command command, @Nullable String label, @Nullable String[] args)
    Constructs a new AnnoyingSender
  • Method Summary

    Modifier and Type
    Method
    Description
    @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!
    boolean
    checkPermission(@NotNull String permission)
    Checks if the CommandSender has the specified permission.
    boolean
    Checks if the CommandSender is a Player.
    boolean
    equalsSender(@NotNull org.bukkit.command.CommandSender sender)
    Checks if the provided CommandSender is the same as the cmdSender
    The AnnoyingPlugin instance
    <T> T
    getArgument(int index, @NotNull Function<String,T> function)
    Gets the argument at the specified index after applying the specified function
    If it's null before/after the function, send the invalid argument message
    Example usage:
    <T> @NotNull Optional<T>
    getArgumentOptional(int index, @NotNull Function<String,T> function)
    Gets the argument at the specified index as an Optional after applying the specified function
    If it's empty before/after the function, send the invalid argument message
    Example usage:
    <T> @NotNull Optional<T>
    getArgumentOptionalFlat(int index, @NotNull Function<String,Optional<T>> function)
    Gets the argument at the specified index as an Optional after applying the specified function and flattening it
    If it's empty before/after the function, send the invalid argument message
    Example usage:
    @NotNull String
    Gets the full/raw command that was used with the arguments (without /)
    Example: command arg1 arg2 arg3
    @Nullable org.bukkit.Location
    Gets the Location of the CommandSender
    @NotNull Optional<org.bukkit.Location>
    Gets the Location of the CommandSender as an Optional
    @NotNull org.bukkit.entity.Player
    Casts the CommandSender to a Player
    @NotNull Optional<org.bukkit.entity.Player>
    Returns the Player as an Optional, empty if the CommandSender is not a Player
    If you know that the CommandSender is a Player, use getPlayer() instead
    @Nullable org.bukkit.entity.Player
    If the CommandSender is a Player, it returns it as one.
    <T> @NotNull SelectorOptional<T>
    getSelector(int index, @NotNull Class<T> type)
    Gets the selector at the specified index as a SelectorOptional
    @NotNull List<String>
    Gets a list of all registered selector keys
    @NotNull List<String>
    getSelectorKeys(@NotNull Class<?> type)
    Gets a list of all registered selector keys for a specific type
    void
    invalidArgument(@Nullable Object argument)
    Sends the invalid argument message, replacing %argument% with the specified argument
    void
    Sends the invalid argument message, replacing %argument% with the specified argument
    If Arguments.args is null or the specified index is out of bounds, it logs a warning to console
    void
    Sends 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!
    @NotNull List<String>
    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, getArgumentsJoined

    Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

    toString, toString, toString, toString, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • plugin

      @NotNull public final @NotNull AnnoyingPlugin plugin
      The AnnoyingPlugin instance
    • cmdSender

      @NotNull public final @NotNull org.bukkit.command.CommandSender cmdSender
      The CommandSender that was used to initialize this AnnoyingSender
    • command

      @Nullable public final @Nullable org.bukkit.command.Command command
      The Command that was used
    • label

      @Nullable public final @Nullable String label
      The Command's label that was used
    • isPlayer

      public final boolean isPlayer
      Whether the cmdSender is a Player
  • 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 new AnnoyingSender
      Parameters:
      plugin - the AnnoyingPlugin instance
      cmdSender - the CommandSender to be used
      command - the Command that was used
      label - the Command's label that was used
      args - the Command's arguments that were used
    • AnnoyingSender

      public AnnoyingSender(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull org.bukkit.command.CommandSender cmdSender)
      Constructs a new AnnoyingSender without a Command
      Parameters:
      plugin - the AnnoyingPlugin instance
      cmdSender - the CommandSender to be used
  • Method Details

    • getAnnoyingPlugin

      @NotNull public @NotNull AnnoyingPlugin getAnnoyingPlugin()
      Description copied from interface: Annoyable
      The AnnoyingPlugin instance
      Specified by:
      getAnnoyingPlugin in interface Annoyable
      Returns:
      the plugin instance
    • getFullCommand

      @NotNull public @NotNull String 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 provided CommandSender is the same as the cmdSender
      Parameters:
      sender - the CommandSender to check
      Returns:
      if the provided CommandSender is the same as the cmdSender
    • checkPlayer

      public boolean checkPlayer()
      Checks if the CommandSender is a Player. If they aren't, it sends the MessagesOptions.MessageKeys.playerOnly message
      Returns:
      whether the CommandSender is a Player
    • checkPermission

      public boolean checkPermission(@NotNull @NotNull String permission)
      Checks if the CommandSender has the specified permission. If they don't, it sends the MessagesOptions.MessageKeys.noPermission message
      Parameters:
      permission - the permission to check
      Returns:
      if the CommandSender has the specified permission
    • getPlayer

      @NotNull public @NotNull org.bukkit.entity.Player getPlayer()
      Casts the CommandSender to a Player

      Only use this if you know that the CommandSender is a Player, otherwise use getPlayerOrNull()

      Returns:
      the Player that was used
      Throws:
      IllegalStateException - if the CommandSender is not a Player
      See Also:
    • getPlayerOrNull

      @Nullable public @Nullable org.bukkit.entity.Player getPlayerOrNull()
      If the CommandSender is a Player, it returns it as one. Otherwise, it returns null
      If you know that the CommandSender is a Player, use getPlayer() instead
      Returns:
      the Player, or null if the CommandSender is not a Player
      See Also:
    • getPlayerOptional

      @NotNull public @NotNull Optional<org.bukkit.entity.Player> getPlayerOptional()
      Returns the Player as an Optional, empty if the CommandSender is not a Player
      If you know that the CommandSender is a Player, use getPlayer() instead
      Returns:
      the Player as an Optional
      See Also:
    • getLocationOfSender

      @Nullable public @Nullable org.bukkit.Location getLocationOfSender()
      Gets the Location of the CommandSender
      Returns:
      the Location of the CommandSender, or null if it cannot be determined
      See Also:
    • getLocationOfSenderOptional

      @NotNull public @NotNull Optional<org.bukkit.Location> getLocationOfSenderOptional()
      Gets the Location of the CommandSender as an Optional
      Returns:
      the Location of the CommandSender as an Optional, empty if it cannot be determined
      See Also:
    • getArgument

      @Nullable public <T> T getArgument(int index, @NotNull @NotNull Function<String,T> function)
      Gets the argument at the specified index after applying the specified function
      If it's null before/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 index
      function - 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 an Optional after applying the specified function
      If it's empty before/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 index
      function - the function to apply to the argument
      Returns:
      the argument at the specified index as an Optional after 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 an Optional after applying the specified function and flattening it
      If it's empty before/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 index
      function - the function to apply to the argument
      Returns:
      the argument at the specified index as an Optional after 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 a SelectorOptional
      Type Parameters:
      T - the type of the selector
      Parameters:
      index - the argument index
      type - the selector type
      Returns:
      the selector at the specified index as a SelectorOptional
    • getSelectorKeys

      @NotNull public @NotNull List<String> getSelectorKeys()
      Gets a list of all registered selector keys
      Returns:
      a list of all registered selector keys
    • getSelectorKeys

      @NotNull public @NotNull List<String> getSelectorKeys(@NotNull @NotNull Class<?> type)
      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 to
      type - 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 to
      type - the type to filter by
      Returns:
      the collection with all registered selector keys added (for convenience)
      See Also:
    • invalidArgument

      public void invalidArgument(@Nullable @Nullable 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
      If Arguments.args is null or 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