Class AnnoyingSender

    • 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 java.lang.String label, @Nullable java.lang.String[] args)
      Constructs a new AnnoyingSender
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkPermission​(@NotNull java.lang.String permission)
      Checks if the CommandSender has the specified permission.
      boolean checkPlayer()
      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
      @NotNull AnnoyingPlugin getAnnoyingPlugin()
      The AnnoyingPlugin instance
      <T> T getArgument​(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's null before/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 an Optional after applying the specified function
      If it's empty before/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 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 org.bukkit.entity.Player getPlayer()
      Casts the CommandSender to a Player
      @NotNull java.util.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
      @Nullable org.bukkit.entity.Player getPlayerOrNull()
      If the CommandSender is a Player, it returns it as one.
      void invalidArgument​(@Nullable java.lang.Object argument)
      Sends the invalid argument message, replacing %argument% with the specified argument
      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
      void invalidArguments()
      Sends the invalid arguments message
      • Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

        toString, toString
      • Methods inherited from class java.lang.Object

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

      • 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 java.lang.String label
        The Command's label that was used
      • isPlayer

        public final boolean isPlayer
        Whether the cmdSender is a Player
    • 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 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 Detail

      • 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 java.lang.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:
        java.lang.IllegalStateException - if the CommandSender is not a Player
        See Also:
        getPlayerOrNull()
      • 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:
        getPlayer()
      • getPlayerOptional

        @NotNull
        public @NotNull java.util.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:
        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'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 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 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 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 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
      • 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
        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