diff --git a/src/main/java/net/minestom/server/entity/EntityManager.java b/src/main/java/net/minestom/server/entity/EntityManager.java index 85836b6a5..a3da70a1c 100644 --- a/src/main/java/net/minestom/server/entity/EntityManager.java +++ b/src/main/java/net/minestom/server/entity/EntityManager.java @@ -160,6 +160,8 @@ public class EntityManager { while ((waitingPlayer = waitingPlayers.poll()) != null) { final Player playerCache = waitingPlayer; playersPool.execute(() -> { + playerCache.init(); + PlayerLoginEvent loginEvent = new PlayerLoginEvent(); playerCache.callEvent(PlayerLoginEvent.class, loginEvent); Instance spawningInstance = loginEvent.getSpawningInstance(); diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 55d915786..98631cae4 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -137,42 +137,27 @@ public class Player extends LivingEntity { setRespawnPoint(new Position(0, 0, 0)); - // FakePlayer init its connection there - playerConnectionInit(); - - init(); - - // Some client update - getPlayerConnection().sendPacket(getPropertiesPacket()); // Send default properties - refreshHealth(); - refreshAbilities(); - - sendUpdateHealthPacket(); - this.settings = new PlayerSettings(); this.inventory = new PlayerInventory(this); setCanPickupItem(true); // By default + this.gameMode = GameMode.SURVIVAL; + this.dimension = Dimension.OVERWORLD; + this.levelType = LevelType.DEFAULT; + refreshPosition(0, 0, 0); + + // FakePlayer init its connection there + playerConnectionInit(); + MinecraftServer.getEntityManager().addWaitingPlayer(this); } /** - * Used when the player is created + * Used when the player is created ({@link EntityManager#waitingPlayersTick()}) * Init the player and spawn him */ protected void init() { - GameMode gameMode = GameMode.SURVIVAL; - Dimension dimension = Dimension.OVERWORLD; - LevelType levelType = LevelType.DEFAULT; - final float x = 0; - final float y = 0; - final float z = 0; - - this.dimension = dimension; - this.gameMode = gameMode; - refreshLevelType(levelType); - refreshPosition(x, y, z); // TODO complete login sequence with optionals packets JoinGamePacket joinGamePacket = new JoinGamePacket(); @@ -249,6 +234,13 @@ public class Player extends LivingEntity { } } // Recipes end + + // Some client update + playerConnection.sendPacket(getPropertiesPacket()); // Send default properties + refreshHealth(); + refreshAbilities(); + + sendUpdateHealthPacket(); } /** @@ -1389,10 +1381,6 @@ public class Player extends LivingEntity { sendPacketToViewersAndSelf(playerInfoPacket); } - protected void refreshLevelType(LevelType levelType) { - this.levelType = levelType; - } - public void refreshOnGround(boolean onGround) { this.onGround = onGround; } diff --git a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java index 118fce5f7..593d8388b 100644 --- a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java @@ -16,8 +16,11 @@ public class LoginStartPacket implements ClientPreplayPacket { @Override public void process(PlayerConnection connection, ConnectionManager connectionManager) { // TODO send encryption request OR directly login success - UUID adam = UUID.fromString("58ffa9d8-aee1-4587-8b79-41b754f6f238"); - UUID playerUuid = UUID.fromString("ab70ecb4-2346-4c14-a52d-7a091507c24e");//UUID.randomUUID(); + + // TODO: Skin + //UUID adam = UUID.fromString("58ffa9d8-aee1-4587-8b79-41b754f6f238"); + //UUID mode = UUID.fromString("ab70ecb4-2346-4c14-a52d-7a091507c24e"); + UUID playerUuid = UUID.randomUUID(); LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username); connection.sendPacket(successPacket);