3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Add tab list documentation

Dieser Commit ist enthalten in:
Desetude 2018-09-30 22:43:24 +01:00
Ursprung 3e65000ab3
Commit 328e06d407
3 geänderte Dateien mit 146 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -101,6 +101,10 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
@Deprecated @Deprecated
void clearHeaderAndFooter(); void clearHeaderAndFooter();
/**
* Returns {@link this} {@link Player}'s tab list.
* @return this player's tab list
*/
TabList getTabList(); TabList getTabList();
/** /**

Datei anzeigen

@ -10,7 +10,6 @@ import java.util.UUID;
/** /**
* Represents the tab list of a {@link Player}. * Represents the tab list of a {@link Player}.
* TODO: Desetude
*/ */
public interface TabList { public interface TabList {
/** /**
@ -25,13 +24,28 @@ public interface TabList {
*/ */
void clearHeaderAndFooter(); void clearHeaderAndFooter();
/**
* Adds a {@link TabListEntry} to the {@link Player}'s tab list.
* @param entry to add to the tab list
*/
void addEntry(TabListEntry entry); void addEntry(TabListEntry entry);
/**
* Removes the {@link TabListEntry} from the tab list with the {@link GameProfile}
* identified with the specified {@link UUID}.
* @param uuid of the
* @return {@link Optional} containing the removed {@link TabListEntry} if present,
* otherwise {@link Optional#empty()}
*/
Optional<TabListEntry> removeEntry(UUID uuid); Optional<TabListEntry> removeEntry(UUID uuid);
/**
* Returns an immutable {@link Collection} of the {@link TabListEntry}s in the tab list.
* @return immutable {@link Collection} of tab list entries
*/
Collection<TabListEntry> getEntries(); Collection<TabListEntry> getEntries();
//Necessary because the TabListEntry implementation isn't in the api // Necessary because the TabListEntry implementation isn't in the api
@Deprecated @Deprecated
TabListEntry buildEntry(GameProfile profile, Component displayName, int latency, int gameMode); TabListEntry buildEntry(GameProfile profile, Component displayName, int latency, int gameMode);
} }

Datei anzeigen

@ -3,34 +3,101 @@ package com.velocitypowered.api.proxy.player;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import net.kyori.text.Component; import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Optional; import java.util.Optional;
/** /**
* TODO: Desetude * Represents a single entry in a {@link TabList}.
*/ */
public interface TabListEntry { public interface TabListEntry {
TabList getTabList(); /**
* Returns the parent {@link TabList} of this {@code this} {@link TabListEntry}.
* @return parent {@link TabList}
*/
@NonNull TabList getTabList();
GameProfile getProfile(); /**
* Returns the {@link GameProfile} of the entry, which uniquely identifies the entry
* with the containing {@link java.util.UUID}, as well as deciding what is shown
* as the player head in the tab list.
* @return {@link GameProfile} of the entry
*/
@NonNull GameProfile getProfile();
Optional<Component> getDisplayName(); /**
* Returns {@link Optional} text {@link Component}, which if present is the text displayed for
* {@code this} entry in the {@link TabList}, otherwise {@link GameProfile#getName()} is shown.
* @return {@link Optional} text {@link Component} of name displayed in the tab list
*/
@NonNull Optional<Component> getDisplayName();
TabListEntry setDisplayName(@Nullable Component displayName); /**
* Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}.
* If {@code null}, {@link GameProfile#getName()} will be shown.
* @param displayName to show in the {@link TabList} for {@code this} entry
* @return {@code this}, for chaining
*/
@NonNull TabListEntry setDisplayName(@Nullable Component displayName);
/**
* Returns the latency for {@code this} entry.
* <p>The icon shown in the tab list is calculated by the latency in the following way:<p>
* <ul>
* <li>A negative latency will display the no connection icon</li>
* <li>0-150 will display 5 bars</li>
* <li>150-300 will display 4 bars</li>
* <li>300-600 will display 3 bars</li>
* <li>600-1000 will display 2 bars</li>
* <li>A latency move than 1 second will display 1 bar</li>
* <li></li>
* </ul>
* @return latency set for {@code this} entry
*/
int getLatency(); int getLatency();
TabListEntry setLatency(int latency); /**
* Sets the latency for {@code this} entry to the specified value
* @see this#getLatency()
* @param latency to changed to
* @return {@code this}, for chaining
*/
@NonNull TabListEntry setLatency(int latency);
/**
* Gets the game mode {@code this} entry has been set to.
* <p>The number corresponds to the game mode in the following way:</p>
* <ol start="0">
* <li>Survival</li>
* <li>Creative</li>
* <li>Adventure</li>
* <li>Spectator</li>
* </ol>
* @return
*/
int getGameMode(); int getGameMode();
/**
* Sets the game mode for {@code this} entry to the specified value
* @see this#getGameMode()
* @param gameMode to change to
* @return {@code this}, for chaining
*/
TabListEntry setGameMode(int gameMode); TabListEntry setGameMode(int gameMode);
/**
* Returns a {@link Builder} to create a {@link TabListEntry}.
* @return {@link TabListEntry} builder
*/
static Builder builder() { static Builder builder() {
return new Builder(); return new Builder();
} }
/**
* Represents a builder which creates {@link TabListEntry}s.
* @see TabListEntry
*/
class Builder { class Builder {
private TabList tabList; private TabList tabList;
private GameProfile profile; private GameProfile profile;
@ -40,31 +107,65 @@ public interface TabListEntry {
private Builder() {} private Builder() {}
/**
* Sets the parent {@link TabList} for this entry,
* the entry will only be able to be added to that specific {@link TabList}.
* @param tabList to set
* @return {@code this}, for chaining
*/
public Builder tabList(TabList tabList) { public Builder tabList(TabList tabList) {
this.tabList = tabList; this.tabList = tabList;
return this; return this;
} }
/**
* Sets the {@link GameProfile} of the {@link TabListEntry}.
* @see TabListEntry#getProfile()
* @param profile to set
* @return {@code this}, for chaining
*/
public Builder profile(GameProfile profile) { public Builder profile(GameProfile profile) {
this.profile = profile; this.profile = profile;
return this; return this;
} }
/**
* Sets the displayed name of the {@link TabListEntry}
* @see TabListEntry#getDisplayName()
* @param displayName to set
* @return {@code this}, for chaining
*/
public Builder displayName(@Nullable Component displayName) { public Builder displayName(@Nullable Component displayName) {
this.displayName = displayName; this.displayName = displayName;
return this; return this;
} }
/**
* Sets the latency of the {@link TabListEntry}
* @see TabListEntry#getLatency()
* @param latency to set
* @return {@code this}, for chaining
*/
public Builder latency(int latency) { public Builder latency(int latency) {
this.latency = latency; this.latency = latency;
return this; return this;
} }
/**
* Sets the game mode of the {@link TabListEntry}
* @see TabListEntry#getGameMode()
* @param gameMode to set
* @return {@code this}, for chaining
*/
public Builder gameMode(int gameMode) { public Builder gameMode(int gameMode) {
this.gameMode = gameMode; this.gameMode = gameMode;
return this; return this;
} }
/**
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
* @return the constructed {@link TabListEntry}
*/
public TabListEntry build() { public TabListEntry build() {
Preconditions.checkState(tabList != null, "The Tablist must be set when building a TabListEntry"); Preconditions.checkState(tabList != null, "The Tablist must be set when building a TabListEntry");
Preconditions.checkState(profile != null, "The GameProfile must be set when building a TabListEntry"); Preconditions.checkState(profile != null, "The GameProfile must be set when building a TabListEntry");