diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingSender.java b/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingSender.java index 19f04d3..d29dd87 100644 --- a/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingSender.java +++ b/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingSender.java @@ -119,9 +119,13 @@ public boolean checkPermission(@NotNull String permission) { /** * Casts the {@link CommandSender} to a {@link Player} - *
Only use this if you know that the {@link CommandSender} is a {@link Player} + *
Only use this if you know that the {@link CommandSender} is a {@link Player}, otherwise use {@link #getPlayerOrNull()}
*
- * @return the {@link Player} that was used
+ * @return the {@link Player} that was used
+ *
+ * @throws IllegalStateException if the {@link CommandSender} is not a {@link Player}
+ *
+ * @see #getPlayerOrNull()
*/
@NotNull
public Player getPlayer() {
@@ -129,6 +133,19 @@ public Player getPlayer() {
return (Player) cmdSender;
}
+ /**
+ * If the {@link CommandSender} is a {@link Player}, it returns it as one. Otherwise, it returns {@code null}
+ *
If you know that the {@link CommandSender} is a {@link Player}, use {@link #getPlayer()} instead
+ *
+ * @return the {@link Player}, or {@code null} if the {@link CommandSender} is not a {@link Player}
+ *
+ * @see #getPlayer()
+ */
+ @Nullable
+ public Player getPlayerOrNull() {
+ return isPlayer ? (Player) cmdSender : null;
+ }
+
/**
* Sends the invalid argument message, replacing {@code %argument%} with the specified argument
*