From accf186c33dfad1581d489121427a4a570cb0bc9 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 14 Jun 2024 15:21:45 +0100 Subject: [PATCH] refactor: add `isConsole method` --- .../src/main/java/net/william278/uniform/CommandUser.java | 7 ++++++- .../net/william278/uniform/fabric/FabricCommandUser.java | 2 +- .../net/william278/uniform/fabric/FabricCommandUser.java | 2 +- .../net/william278/uniform/paper/PaperCommandUser.java | 2 +- .../william278/uniform/velocity/VelocityCommandUser.java | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/net/william278/uniform/CommandUser.java b/common/src/main/java/net/william278/uniform/CommandUser.java index 3c4f676..7043ab3 100644 --- a/common/src/main/java/net/william278/uniform/CommandUser.java +++ b/common/src/main/java/net/william278/uniform/CommandUser.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable; import java.util.UUID; +@SuppressWarnings("unused") public interface CommandUser { @NotNull @@ -36,6 +37,10 @@ public interface CommandUser { String getName(); @Nullable - UUID getUniqueId(); + UUID getUuid(); + + default boolean isConsole() { + return getName() == null; + } } diff --git a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java index 05cf065..b231a59 100644 --- a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java +++ b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java @@ -44,7 +44,7 @@ public record FabricCommandUser(@NotNull ServerCommandSource source) implements @Override @Nullable - public UUID getUniqueId() { + public UUID getUuid() { return source.getPlayer() != null ? source.getPlayer().getUuid() : null; } diff --git a/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java index 05cf065..b231a59 100644 --- a/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java +++ b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java @@ -44,7 +44,7 @@ public record FabricCommandUser(@NotNull ServerCommandSource source) implements @Override @Nullable - public UUID getUniqueId() { + public UUID getUuid() { return source.getPlayer() != null ? source.getPlayer().getUuid() : null; } diff --git a/paper/src/main/java/net/william278/uniform/paper/PaperCommandUser.java b/paper/src/main/java/net/william278/uniform/paper/PaperCommandUser.java index 9cea7ce..d9a418b 100644 --- a/paper/src/main/java/net/william278/uniform/paper/PaperCommandUser.java +++ b/paper/src/main/java/net/william278/uniform/paper/PaperCommandUser.java @@ -45,7 +45,7 @@ public record PaperCommandUser(@NotNull BukkitBrigadierCommandSource source) imp @Override @Nullable - public UUID getUniqueId() { + public UUID getUuid() { return source.getBukkitEntity() != null ? source.getBukkitEntity().getUniqueId() : null; } } diff --git a/velocity/src/main/java/net/william278/uniform/velocity/VelocityCommandUser.java b/velocity/src/main/java/net/william278/uniform/velocity/VelocityCommandUser.java index f6d385f..d997534 100644 --- a/velocity/src/main/java/net/william278/uniform/velocity/VelocityCommandUser.java +++ b/velocity/src/main/java/net/william278/uniform/velocity/VelocityCommandUser.java @@ -45,7 +45,7 @@ public record VelocityCommandUser(CommandSource source) implements CommandUser { @Override @Nullable - public UUID getUniqueId() { + public UUID getUuid() { return source instanceof Player ? ((Player) source).getUniqueId() : null; }