Do not send gamemode related packets before the player spawn

This commit is contained in:
themode 2020-12-18 00:57:23 +01:00
parent 3e532b24a8
commit 943aae7397

View File

@ -1700,12 +1700,16 @@ public class Player extends LivingEntity implements CommandSender {
public void setGameMode(@NotNull GameMode gameMode) {
Check.notNull(gameMode, "GameMode cannot be null");
this.gameMode = gameMode;
// Condition to prevent sending the packets before spawning the player
if (isActive()) {
sendChangeGameStatePacket(ChangeGameStatePacket.Reason.CHANGE_GAMEMODE, gameMode.getId());
PlayerInfoPacket infoPacket = new PlayerInfoPacket(PlayerInfoPacket.Action.UPDATE_GAMEMODE);
infoPacket.playerInfos.add(new PlayerInfoPacket.UpdateGamemode(getUuid(), gameMode));
sendPacketToViewersAndSelf(infoPacket);
}
}
/**
* Gets if this player is in creative. Used for code readability.