3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-06 00:00:47 +01:00

Add method to check if an entry already exists in the tab list.

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-01 00:07:20 -04:00
Ursprung 275685f45f
Commit f0ba7e1eea
2 geänderte Dateien mit 17 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -37,12 +37,20 @@ public interface TabList {
* Removes the {@link TabListEntry} from the tab list with the {@link GameProfile} identified with * Removes the {@link TabListEntry} from the tab list with the {@link GameProfile} identified with
* the specified {@link UUID}. * the specified {@link UUID}.
* *
* @param uuid of the * @param uuid of the entry
* @return {@link Optional} containing the removed {@link TabListEntry} if present, otherwise * @return {@link Optional} containing the removed {@link TabListEntry} if present, otherwise
* {@link Optional#empty()} * {@link Optional#empty()}
*/ */
Optional<TabListEntry> removeEntry(UUID uuid); Optional<TabListEntry> 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. * Returns an immutable {@link Collection} of the {@link TabListEntry}s in the tab list.
* *

Datei anzeigen

@ -57,6 +57,8 @@ public class VelocityTabList implements TabList {
@Override @Override
public Optional<TabListEntry> removeEntry(UUID uuid) { public Optional<TabListEntry> removeEntry(UUID uuid) {
Preconditions.checkNotNull(uuid, "uuid");
TabListEntry entry = entries.remove(uuid); TabListEntry entry = entries.remove(uuid);
if (entry != null) { if (entry != null) {
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry);
@ -67,6 +69,12 @@ public class VelocityTabList implements TabList {
return Optional.ofNullable(entry); 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 * 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 * {@link MinecraftConnection#delayedWrite(Object)}, so make sure to do an explicit