public class AnnoyingSender extends xyz.srnyx.javautilities.parents.Stringable implements Annoyable
AnnoyingCommand| Modifier and Type | Field and Description |
|---|---|
@Nullable java.lang.String[] |
args
The
Command's arguments that were used |
@NotNull org.bukkit.command.CommandSender |
cmdSender
The
CommandSender that was used to initialize this AnnoyingSender |
@Nullable org.bukkit.command.Command |
command
The
Command that was used |
boolean |
isPlayer
Whether the
cmdSender is a Player |
@Nullable java.lang.String |
label
The
Command's label that was used |
@NotNull AnnoyingPlugin |
plugin
The
AnnoyingPlugin instance |
| Constructor and 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 |
| Modifier and Type | Method and Description |
|---|---|
boolean |
argEquals(int index,
java.lang.String... strings)
Returns if the specified
args index is equal to any of the specified strings (case-insensitive) |
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 |
@Nullable java.lang.String |
getArgument(int index)
Gets the argument at the specified index
|
<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: |
@NotNull java.util.Optional<java.lang.String> |
getArgumentOptional(int index)
Gets the argument at the specified index as an
Optional |
<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 java.lang.String |
getArgumentsJoined()
Gets all arguments joined together
If no arguments are found, it returns an empty string |
@NotNull java.lang.String |
getArgumentsJoined(int start)
Gets multiple arguments joined together starting from the specified index
If no arguments are found, it returns an empty string |
@NotNull java.lang.String |
getArgumentsJoined(int start,
int end)
Gets multiple arguments joined together starting from the specified index and ending at the specified index (if too high, it will stop at the last argument)
If no arguments are found, it returns an empty string |
@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 args is null or the specified index is out of bounds, it logs a warning to console |
void |
invalidArguments()
Sends the invalid arguments message
|
@NotNull public final @NotNull AnnoyingPlugin plugin
AnnoyingPlugin instance@NotNull public final @NotNull org.bukkit.command.CommandSender cmdSender
CommandSender that was used to initialize this AnnoyingSender@Nullable public final @Nullable org.bukkit.command.Command command
Command that was used@Nullable public final @Nullable java.lang.String label
Command's label that was used@Nullable public final @Nullable java.lang.String[] args
Command's arguments that were usedpublic final boolean isPlayer
cmdSender is a Playerpublic 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)
AnnoyingSenderplugin - the AnnoyingPlugin instancecmdSender - the CommandSender to be usedcommand - the Command that was usedlabel - the Command's label that was usedargs - the Command's arguments that were usedpublic AnnoyingSender(@NotNull
@NotNull AnnoyingPlugin plugin,
@NotNull
@NotNull org.bukkit.command.CommandSender cmdSender)
AnnoyingSender without a Commandplugin - the AnnoyingPlugin instancecmdSender - the CommandSender to be used@NotNull public @NotNull AnnoyingPlugin getAnnoyingPlugin()
AnnoyableAnnoyingPlugin instancegetAnnoyingPlugin in interface Annoyablepublic boolean equalsSender(@NotNull
@NotNull org.bukkit.command.CommandSender sender)
CommandSender is the same as the cmdSendersender - the CommandSender to checkCommandSender is the same as the cmdSenderpublic boolean argEquals(int index,
@Nullable
java.lang.String... strings)
args index is equal to any of the specified strings (case-insensitive)index - the argument indexstrings - the strings to compare totrue if the specified args index is equal to any of the specified strings (case-insensitive)public boolean checkPlayer()
CommandSender is a Player. If they aren't, it sends the MessagesOptions.MessageKeys#playerOnly messageCommandSender is a Playerpublic boolean checkPermission(@NotNull
@NotNull java.lang.String permission)
CommandSender has the specified permission. If they don't, it sends the MessagesOptions.MessageKeys#noPermission messagepermission - the permission to checkCommandSender has the specified permission@NotNull public @NotNull org.bukkit.entity.Player getPlayer()
CommandSender to a Player
Only use this if you know that the CommandSender is a Player, otherwise use getPlayerOrNull()
Player that was usedjava.lang.IllegalStateException - if the CommandSender is not a PlayergetPlayerOrNull()@Nullable public @Nullable org.bukkit.entity.Player getPlayerOrNull()
CommandSender is a Player, it returns it as one. Otherwise, it returns null
CommandSender is a Player, use getPlayer() insteadPlayer, or null if the CommandSender is not a PlayergetPlayer()@NotNull public @NotNull java.util.Optional<org.bukkit.entity.Player> getPlayerOptional()
Player as an Optional, empty if the CommandSender is not a Player
CommandSender is a Player, use getPlayer() insteadPlayer as an OptionalgetPlayer()@Nullable public @Nullable java.lang.String getArgument(int index)
index - the argument index@Nullable
public <T> T getArgument(int index,
@NotNull
@NotNull java.util.function.Function<java.lang.String,T> function)
null before/after the function, send the invalid argument message
final Player target = sender.getArgument(2, Bukkit::getPlayer);
if (target == null) return;
T - the type of the argumentindex - the argument indexfunction - the function to apply to the argument@NotNull public @NotNull java.util.Optional<java.lang.String> getArgumentOptional(int index)
Optionalindex - the argument indexOptional@NotNull
public <T> @NotNull java.util.Optional<T> getArgumentOptional(int index,
@NotNull
@NotNull java.util.function.Function<java.lang.String,T> function)
Optional after applying the specified function
empty before/after the function, send the invalid argument message
final Optional<Player> target = sender.getArgument(2, Bukkit::getPlayer);
if (!target.isPresent()) return;
T - the type of the argumentindex - the argument indexfunction - the function to apply to the argumentOptional after applying the specified function@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)
Optional after applying the specified function and flattening it
empty before/after the function, send the invalid argument message
final Optional<OfflinePlayer> target = sender.getArgumentFlat(2, BukkitUtility::getOfflinePlayer);
if (!target.isPresent()) return;
T - the type of the argumentindex - the argument indexfunction - the function to apply to the argumentOptional after applying the specified function and flattening it@NotNull
public @NotNull java.lang.String getArgumentsJoined(int start,
int end)
start - the starting indexend - the ending index@NotNull public @NotNull java.lang.String getArgumentsJoined(int start)
start - the starting index@NotNull public @NotNull java.lang.String getArgumentsJoined()
public void invalidArgument(@Nullable
@Nullable java.lang.Object argument)
%argument% with the specified argumentargument - the argument to replace %argument% withpublic void invalidArgumentByIndex(int index)
%argument% with the specified argument
args is null or the specified index is out of bounds, it logs a warning to consoleindex - the argument indexpublic void invalidArguments()