diff --git a/SpongeAPI b/SpongeAPI index c0f65a12e41..f4245597d6d 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit c0f65a12e41afb4a6891efd0c6c00a7b0f2ddea4 +Subproject commit f4245597d6dc09becafbcff46a1afbc365ee2eca diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java index 8d49e1212f2..072decba587 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java @@ -151,6 +151,7 @@ private void addEntry(final ClientboundPlayerInfoUpdatePacket.Entry entry) { entry.latency(), (GameMode) (Object) entry.gameMode(), entry.listed(), + entry.listOrder(), entry.chatSession() == null ? null : entry.chatSession().profilePublicKey() ), false); } @@ -190,11 +191,10 @@ public Optional removeEntry(final UUID uniqueId) { @SuppressWarnings("ConstantConditions") void sendUpdate(final TabListEntry entry, final EnumSet actions) { final ClientboundPlayerInfoUpdatePacket packet = new ClientboundPlayerInfoUpdatePacket(actions, List.of()); - int listOrder = 0; // TODO expose to API 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()), - entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, listOrder, chatSessionData); + entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, entry.weight(), chatSessionData); ((ClientboundPlayerInfoUpdatePacketAccessor) packet).accessor$entries(List.of(data)); this.player.connection.send(packet); } diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java index 355ada3d91b..566f25f008e 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java @@ -52,12 +52,13 @@ public final class SpongeTabListEntry implements TabListEntry { private int latency; private GameMode gameMode; private boolean listed; + private int weight; 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 boolean listed, final ProfilePublicKey.Data profilePublicKey) { + final boolean listed, final int weight, final ProfilePublicKey.Data profilePublicKey) { Preconditions.checkState(list instanceof SpongeTabList, "list is not a SpongeTabList"); this.list = (SpongeTabList) list; this.profile = Objects.requireNonNull(profile, "profile"); @@ -65,6 +66,7 @@ public SpongeTabListEntry( this.latency = latency; this.gameMode = Objects.requireNonNull(gameMode, "game mode"); this.listed = listed; + this.weight = weight; this.profilePublicKey = profilePublicKey; } @@ -126,6 +128,18 @@ public SpongeTabListEntry setListed(boolean listed) { return this; } + @Override + public int weight() { + return this.weight; + } + + @Override + public SpongeTabListEntry setWeight(int weight) { + this.weight = weight; + this.sendUpdate(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LIST_ORDER); + return this; + } + public ProfilePublicKey.Data profilePublicKey() { return this.profilePublicKey; } diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java b/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java index cb974eb6caf..3c1e136d1cd 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java @@ -44,6 +44,7 @@ public final class TabListEntryBuilder implements TabListEntry.Builder { private int latency; private boolean listed = true; private @Nullable GameMode gameMode; + private int weight; @Override public TabListEntry.Builder list(TabList list) { @@ -81,13 +82,19 @@ public TabListEntry.Builder listed(boolean listed) { return this; } + @Override + public TabListEntry.Builder weight(int weight) { + this.weight = weight; + 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, this.listed, null); + return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, this.listed, this.weight, null); } @Override @@ -97,6 +104,7 @@ public TabListEntry.Builder from(TabListEntry value) { this.displayName = value.displayName().orElse(null); this.latency = value.latency(); this.gameMode = Objects.requireNonNull(value.gameMode(), "game mode"); + this.weight = value.weight(); return this; } @@ -107,6 +115,7 @@ public TabListEntry.Builder reset() { this.displayName = null; this.latency = 0; this.gameMode = null; + this.weight = 0; return this; }