Skip to content

Commit

Permalink
Add TabListEntry#listed
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Apr 26, 2024
1 parent 7348084 commit d9eff3a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SpongeAPI
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private void addEntry(final ClientboundPlayerInfoUpdatePacket.Entry entry) {
displayName == null ? null : SpongeAdventure.asAdventure(displayName),
entry.latency(),
(GameMode) (Object) entry.gameMode(),
entry.listed(),
entry.chatSession() == null ? null : entry.chatSession().profilePublicKey()
), false);
}
Expand Down Expand Up @@ -193,7 +194,7 @@ void sendUpdate(final TabListEntry entry, final EnumSet<ClientboundPlayerInfoUpd
final RemoteChatSession.Data chatSessionData = ((SpongeTabListEntry) entry).profilePublicKey() == null ? null : new RemoteChatSession.Data(entry.profile().uuid(), ((SpongeTabListEntry) entry).profilePublicKey());
final net.minecraft.network.chat.Component displayName = entry.displayName().isPresent() ? SpongeAdventure.asVanilla(entry.displayName().get()) : null;
final ClientboundPlayerInfoUpdatePacket.Entry data = new ClientboundPlayerInfoUpdatePacket.Entry(entry.profile().uniqueId(), SpongeGameProfile.toMcProfile(entry.profile()),
true, entry.latency(), (GameType) (Object) entry.gameMode(), displayName, chatSessionData);
entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, chatSessionData);
((ClientboundPlayerInfoUpdatePacketAccessor) packet).accessor$entries(List.of(data));
this.player.connection.send(packet);
}
Expand Down Expand Up @@ -223,10 +224,15 @@ public void updateEntriesOnSend(final ClientboundPlayerInfoUpdatePacket packet)
if (actions.contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY)) {
((SpongeTabListEntry) entry).updateWithoutSend();
entry.setLatency(update.latency());
} else if (actions.contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE)) {
}
if (actions.contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE)) {
((SpongeTabListEntry) entry).updateWithoutSend();
entry.setGameMode((GameMode) (Object) update.gameMode());
}
if (actions.contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED)) {
((SpongeTabListEntry) entry).updateWithoutSend();
entry.setListed(update.listed());
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ public final class SpongeTabListEntry implements TabListEntry {
private @Nullable Component displayName;
private int latency;
private GameMode gameMode;
private boolean listed;
private boolean updateWithoutSend;
private final ProfilePublicKey.Data profilePublicKey;

public SpongeTabListEntry(
final TabList list, final GameProfile profile, @Nullable final Component displayName, final int latency, final GameMode gameMode,
final ProfilePublicKey.Data profilePublicKey) {
final boolean listed, final ProfilePublicKey.Data profilePublicKey) {
Preconditions.checkState(list instanceof SpongeTabList, "list is not a SpongeTabList");
this.list = (SpongeTabList) list;
this.profile = Objects.requireNonNull(profile, "profile");
this.displayName = displayName;
this.latency = latency;
this.gameMode = Objects.requireNonNull(gameMode, "game mode");
this.listed = listed;
this.profilePublicKey = profilePublicKey;
}

Expand Down Expand Up @@ -112,6 +114,18 @@ public TabListEntry setGameMode(final GameMode gameMode) {
return this;
}

@Override
public boolean listed() {
return this.listed;
}

@Override
public SpongeTabListEntry setListed(boolean listed) {
this.listed = listed;
this.sendUpdate(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED);
return this;
}

public ProfilePublicKey.Data profilePublicKey() {
return this.profilePublicKey;
}
Expand Down Expand Up @@ -160,6 +174,7 @@ public String toString() {
.add("latency=" + this.latency)
.add("displayName=" + this.displayName)
.add("gameMode=" + this.gameMode)
.add("listed=" + this.listed)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public final class TabListEntryBuilder implements TabListEntry.Builder {
private @Nullable GameProfile profile;
private @Nullable Component displayName;
private int latency;
private boolean listed = true;
private @Nullable GameMode gameMode;

@Override
Expand Down Expand Up @@ -74,13 +75,19 @@ public TabListEntry.Builder gameMode(GameMode gameMode) {
return this;
}

@Override
public TabListEntry.Builder listed(boolean listed) {
this.listed = listed;
return this;
}

@Override
public TabListEntry build() {
Preconditions.checkState(this.list != null, "list must be set");
Preconditions.checkState(this.profile != null, "profile must be set");
Preconditions.checkState(this.gameMode != null, "game mode must be set");

return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, null);
return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, this.listed, null);
}

@Override
Expand Down

0 comments on commit d9eff3a

Please sign in to comment.