GetSpawnLocation and Set

Discussion in 'Plugin Development' started by BeeT, Jan 4, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    BeeT

    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.
     
  2. Offline

    DDoS

    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.
     
  3. Offline

    BeeT

    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?
     
  4. Try creating a player listener event for PLAYER_RESPAWN then set there location when it's triggered!
     
  5. Offline

    BeeT

    Doesn't work.
     
  6. Offline

    Seadragon91

    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);
     
  7. Il have a look and find a solution for you when I get home ;)
     
  8. Offline

    BeeT

    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.
     
  9. @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);
     
  10. Offline

    BeeT

    Thank you, i will try it when my friend back and will tell you is it works.
     
  11. I tested it so it should ;)
     
  12. Offline

    BeeT

    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?
     
  13. @BeeT you mean so it does the teleport no matter what height the player is at?
     
  14. Offline

    BeeT

    @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.
     
    Last edited by a moderator: May 22, 2016
Thread Status:
Not open for further replies.

Share This Page