diff --git a/src/main/java/com/loohp/limbo/Events/PlayerJoinEvent.java b/src/main/java/com/loohp/limbo/Events/PlayerJoinEvent.java index d1ffc65..9a4d45a 100644 --- a/src/main/java/com/loohp/limbo/Events/PlayerJoinEvent.java +++ b/src/main/java/com/loohp/limbo/Events/PlayerJoinEvent.java @@ -1,11 +1,22 @@ package com.loohp.limbo.Events; +import com.loohp.limbo.Location.Location; import com.loohp.limbo.Player.Player; public class PlayerJoinEvent extends PlayerEvent { - - public PlayerJoinEvent(Player player) { + + private Location spawnLocation; + + public PlayerJoinEvent(Player player, Location spawnLoc) { super(player); + spawnLocation = spawnLoc; } + public Location getSpawnLocation() { + return spawnLocation; + } + + public void setSpawnLocation(Location spawnLocation) { + this.spawnLocation = spawnLocation; + } } diff --git a/src/main/java/com/loohp/limbo/Server/ClientConnection.java b/src/main/java/com/loohp/limbo/Server/ClientConnection.java index 3a88020..6bd1535 100644 --- a/src/main/java/com/loohp/limbo/Server/ClientConnection.java +++ b/src/main/java/com/loohp/limbo/Server/ClientConnection.java @@ -292,14 +292,18 @@ public class ClientConnection extends Thread { if (state == ClientState.PLAY) { TimeUnit.MILLISECONDS.sleep(500); - - ServerProperties p = Limbo.getInstance().getServerProperties(); + + ServerProperties p = Limbo.getInstance().getServerProperties(); + Location s = p.getWorldSpawn(); + + PlayerJoinEvent evt = new PlayerJoinEvent(player, s); + Limbo.getInstance().getEventsManager().callEvent(evt); + s = evt.getSpawnLocation(); + PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, p.getDefaultGamemode(), Limbo.getInstance().getWorlds().stream().map(each -> new NamespacedKey(each.getName()).toString()).collect(Collectors.toList()).toArray(new String[Limbo.getInstance().getWorlds().size()]), Limbo.getInstance().getDimensionRegistry().getCodec(), p.getWorldSpawn().getWorld(), 0, (byte) p.getMaxPlayers(), 8, p.isReducedDebugInfo(), true, false, true); sendPacket(join); Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, p.getDefaultGamemode()); - - Location s = p.getWorldSpawn(); - + //PacketPlayOutKeepAlive alive = new PacketPlayOutKeepAlive((long) (Math.random() * Long.MAX_VALUE)); World world = s.getWorld(); @@ -336,8 +340,6 @@ public class ClientConnection extends Thread { sendPacket(declare); } - Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player)); - PacketPlayOutSpawnPosition spawnPos = new PacketPlayOutSpawnPosition(BlockPosition.from(s)); sendPacket(spawnPos);