What event can I use for when a player first spawns in on the server? I want to change the place they spawn in at.
Code:java @EventHandler//use the PlayerJoinEvent as the player has not yet joined the game in the PlayerLoginEvent and cannot teleport public void onPlayerJoinEvent(PlayerJoinEvent event){Player p = event.getPlayer();//if statement gets if the player is new to the server.if(!p.hasPlayedBefore()){//to prevent lag when the player teleportsyourSpawnLocation.getChunk().load();//teleport the player to the spawn locationp.teleport(yourSpawnLocation);}} :3
I did that, but I get an error in console. Code: 01:39:02 [INFO] Disconnecting ViiRuSxModz [/192.168.1.201:9404]: Internal server error 01:39:02 [WARNING] Failed to handle packet: java.lang.IllegalStateException: Fai led to add player. net.minecraft.server.EntityPlayer@474(ViiRuSxModz at 65.36991 184780035,62.0,135.64627202655322) already is in chunk 4, 8 java.lang.IllegalStateException: Failed to add player. net.minecraft.server.Enti tyPlayer@474(ViiRuSxModz at 65.36991184780035,62.0,135.64627202655322) already i s in chunk 4, 8 at net.minecraft.server.PlayerInstance.a(PlayerInstance.java:31) at net.minecraft.server.PlayerManager.addPlayer(PlayerManager.java:88) at net.minecraft.server.ServerConfigurationManager.c(ServerConfiguration Manager.java:143) at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:129) at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:41) at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:6 1) at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492) I'm trying to teleport the player to a location in a different world by the way, not a location in the same world.
I use p.teleport(Location object here) I found out PlayerTeleportEvent is called when a player spawns, but if I use event.setTo(location), it doesn't work. The player does not spawn in the correct location. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Location location = new Location(worldname, x, y, z); p.teleport(location); also if you put that in and it doesnt work make sure you have @EventHandler above your method.