Skip to content

Commit

Permalink
Use initial uuid for internal tablist packets to prevent duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed May 11, 2024
1 parent 8d44b93 commit 417b257
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.elytrium.commons.utils.reflection.ReflectionException;
import net.elytrium.limboapi.LimboAPI;
Expand Down Expand Up @@ -131,22 +132,23 @@ private void finish() {
eventManager.fire(new GameProfileRequestEvent(this.inbound, this.player.getGameProfile(), this.player.isOnlineMode())).thenAcceptAsync(
gameProfile -> {
try {
UUID uuid = this.plugin.getInitialID(this.player);
if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_1) <= 0) {
connection.delayedWrite(new LegacyPlayerListItemPacket(
LegacyPlayerListItemPacket.REMOVE_PLAYER,
List.of(new LegacyPlayerListItemPacket.Item(this.player.getUniqueId()))
List.of(new LegacyPlayerListItemPacket.Item(uuid))
));

connection.delayedWrite(new LegacyPlayerListItemPacket(
LegacyPlayerListItemPacket.ADD_PLAYER,
List.of(
new LegacyPlayerListItemPacket.Item(this.player.getUniqueId())
new LegacyPlayerListItemPacket.Item(uuid)
.setName(gameProfile.getUsername())
.setProperties(gameProfile.getGameProfile().getProperties())
)
));
} else if (connection.getState() != StateRegistry.CONFIG) {
UpsertPlayerInfoPacket.Entry playerInfoEntry = new UpsertPlayerInfoPacket.Entry(this.player.getUniqueId());
UpsertPlayerInfoPacket.Entry playerInfoEntry = new UpsertPlayerInfoPacket.Entry(uuid);
playerInfoEntry.setDisplayName(new ComponentHolder(this.player.getProtocolVersion(), Component.text(gameProfile.getUsername())));
playerInfoEntry.setProfile(gameProfile.getGameProfile());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,19 @@ protected void onSpawn(Class<? extends LimboSessionHandler> handlerClass,

MinecraftPacket playerInfoPacket;

UUID uuid = this.plugin.getInitialID(player);
if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_1) <= 0) {
playerInfoPacket = new LegacyPlayerListItemPacket(
LegacyPlayerListItemPacket.ADD_PLAYER,
List.of(
new LegacyPlayerListItemPacket.Item(player.getUniqueId())
new LegacyPlayerListItemPacket.Item(uuid)
.setName(player.getUsername())
.setGameMode(this.gameMode)
.setProperties(player.getGameProfileProperties())
)
);
} else {
UpsertPlayerInfoPacket.Entry playerInfoEntry = new UpsertPlayerInfoPacket.Entry(player.getUniqueId());
UpsertPlayerInfoPacket.Entry playerInfoEntry = new UpsertPlayerInfoPacket.Entry(uuid);
playerInfoEntry.setDisplayName(new ComponentHolder(player.getProtocolVersion(), Component.text(player.getUsername())));
playerInfoEntry.setGameMode(this.gameMode);
playerInfoEntry.setProfile(player.getGameProfile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.awt.image.BufferedImage;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import net.elytrium.limboapi.LimboAPI;
import net.elytrium.limboapi.api.Limbo;
Expand Down Expand Up @@ -200,16 +201,17 @@ public void setGameMode(GameMode gameMode) {
int id = this.gameMode.getID();
this.sendAbilities();
if (!is17) {
UUID uuid = this.plugin.getInitialID(this.player);
if (this.connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_1) <= 0) {
this.writePacket(
new LegacyPlayerListItemPacket(LegacyPlayerListItemPacket.UPDATE_GAMEMODE,
List.of(
new LegacyPlayerListItemPacket.Item(this.player.getUniqueId()).setGameMode(id)
new LegacyPlayerListItemPacket.Item(uuid).setGameMode(id)
)
)
);
} else {
UpsertPlayerInfoPacket.Entry playerInfoEntry = new UpsertPlayerInfoPacket.Entry(this.player.getUniqueId());
UpsertPlayerInfoPacket.Entry playerInfoEntry = new UpsertPlayerInfoPacket.Entry(uuid);
playerInfoEntry.setGameMode(id);

this.writePacket(new UpsertPlayerInfoPacket(EnumSet.of(UpsertPlayerInfoPacket.Action.UPDATE_GAME_MODE), List.of(playerInfoEntry)));
Expand Down Expand Up @@ -305,7 +307,7 @@ private void sendToRegisteredServer(RegisteredServer server) {
if (this.connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_1) <= 0) {
this.connection.delayedWrite(new LegacyPlayerListItemPacket(
LegacyPlayerListItemPacket.REMOVE_PLAYER,
List.of(new LegacyPlayerListItemPacket.Item(this.player.getUniqueId()))
List.of(new LegacyPlayerListItemPacket.Item(this.plugin.getInitialID(this.player)))
));
}

Expand Down

0 comments on commit 417b257

Please sign in to comment.