Skip to content

Commit 5697d24

Browse files
added the CommandSender#getId() method
1 parent 7dd98d5 commit 5697d24

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public boolean hasId(@NotNull UUID id) {
6969
return id.equals(this.id);
7070
}
7171

72+
@Override
7273
public @NotNull UUID getId() {
7374
return id;
7475
}

commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ public interface CommandSender<S> {
3030
boolean hasPermission(String permission);
3131

3232
boolean hasId(@NotNull UUID id);
33+
34+
/**
35+
* @throws IllegalStateException if the sender does not have an ID
36+
*/
37+
@NotNull UUID getId() throws IllegalStateException;
3338
}

core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public boolean hasId(@NotNull UUID id) {
101101
return handle instanceof Entity entity && entity.getUniqueId().equals(id);
102102
}
103103

104+
@Override
105+
public @NotNull UUID getId() throws IllegalStateException {
106+
if (handle instanceof Entity entity)
107+
return entity.getUniqueId();
108+
throw new IllegalStateException(handle + " does not have an ID");
109+
}
110+
104111
@ApiStatus.Internal
105112
public static void clearCache() {
106113
SENDERS_BY_ID.clear();

0 commit comments

Comments
 (0)