From f0ba7e1eea6a253c1f24be294b9e9d00fbdb7169 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 1 Jul 2019 00:07:20 -0400 Subject: [PATCH] Add method to check if an entry already exists in the tab list. --- .../com/velocitypowered/api/proxy/player/TabList.java | 10 +++++++++- .../velocitypowered/proxy/tablist/VelocityTabList.java | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java index 364b188b3..71bb47ba7 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java @@ -37,12 +37,20 @@ public interface TabList { * Removes the {@link TabListEntry} from the tab list with the {@link GameProfile} identified with * the specified {@link UUID}. * - * @param uuid of the + * @param uuid of the entry * @return {@link Optional} containing the removed {@link TabListEntry} if present, otherwise * {@link Optional#empty()} */ Optional removeEntry(UUID uuid); + /** + * Determines if the specified entry exists in the tab list. + * + * @param uuid the UUID of the entry + * @return {@code true} if it exists, {@code false} if it does not + */ + boolean containsEntry(UUID uuid); + /** * Returns an immutable {@link Collection} of the {@link TabListEntry}s in the tab list. * diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index 2851e6e84..aacf26012 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -57,6 +57,8 @@ public class VelocityTabList implements TabList { @Override public Optional removeEntry(UUID uuid) { + Preconditions.checkNotNull(uuid, "uuid"); + TabListEntry entry = entries.remove(uuid); if (entry != null) { PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); @@ -67,6 +69,12 @@ public class VelocityTabList implements TabList { return Optional.ofNullable(entry); } + @Override + public boolean containsEntry(UUID uuid) { + Preconditions.checkNotNull(uuid, "uuid"); + return entries.containsKey(uuid); + } + /** * Clears all entries from the tab list. Note that the entries are written with * {@link MinecraftConnection#delayedWrite(Object)}, so make sure to do an explicit