Hello, I have one question. How to get PLAYER spawn location and how to set PLAYER spawnlocation? I know this: loc = player.getWorld().getSpawnLocation(); But it's world spawn location. I need only player. Thank you.
I'm not sure about what your looking for, but if you want to know where a player is gonna respawn, and if you want to change that location, use the PlayerRespawnEvent.
It doeasn't work for me, can you help me? I want after respawn get player spawn location and set it to: oldLocation variable, after that I want to set new spawn location and spawn him and then set oldLocation. Or maybe you know how to teleport player after respawn?
Try that BeeT: Code: PluginManager manager = this.getServer().getPluginManager(); manager.registerEvent(Type.PLAYER_RESPAWN, new PlayerListener() { public void onPlayerRespawn(PlayerRespawnEvent event) { Player p = event.getPlayer(); event.setRespawnLocation(p.getWorld().getSpawnLocation()); } }, Priority.Normal, this);
CraigEge thank you very much. I'm waiting. It will be nice if you can help me teleport players on respawn to another location or get and set his locations.
@BeeT Try this: Code: PluginManager manager = this.getServer().getPluginManager(); manager.registerEvent(Type.PLAYER_RESPAWN, new PlayerListener() { public void onPlayerRespawn(PlayerRespawnEvent event) { //Player Player p = event.getPlayer(); //Getting old spawn location Location oldSpawn = p.getWorld().getSpawnLocation(); //Setting new spawn location (setting as oldSpawn originally to initialise the value) Location newSpawn = oldSpawn; newSpawn.setX(5.5); newSpawn.setY(20.0); newSpawn.setZ(10.2); event.setRespawnLocation(newSpawn); }, Priority.Normal, this);
Thank you very much! Now maybe you can help me with radius? I want if player respawn in this location: int x = -16; int y = 72; int z = 270; He should be teleported else nothing. I made it, but it deason't work all time, because sometimes player respawned to -15, how to increase radius?
@CraigEge no, i mean it's no matter where he is -16 to -11; 72 to 77; 270 to 275 Because now sometimes he is at 71 and sometimes he is at 72 and i want to increase radius. @CraigEge I think I need to use for cycle yes? EDIT by Moderator: merged posts, please use the edit button instead of double posting.