Teleport player on death event

Discussion in 'Plugin Development' started by danielh112, Jun 24, 2014.

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

    danielh112

    Hi I have been trying to teleport a player back to a certain location once they die, but I cannot get it to work. The code I am using is below, Thank you in advance!

    Code:java
    1. @EventHandler
    2. public void onPlayerRespawn(PlayerRespawnEvent e){
    3. Arena a = this.a(e.getPlayer());
    4. if(a == null) {
    5. return;
    6. }
    7. this.teleportDeadPlayer(e, a);
    8. }
    9.  


    Code:java
    1. public void teleportDeadPlayer(final PlayerRespawnEvent e, final Arena a)
    2. {
    3. final String pName = e.getPlayer().getName();
    4. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    5. public void run() {
    6. if(a.checkPoints().containsKey(pName)) {
    7. e.setRespawnLocation(a.checkPoints.get(pName));
    8. } else {
    9. e.setRespawnLocation(a.GetStartLoc());
    10. }
    11. }
    12. }, 5L);
    13. }
    14. }
     
  2. Offline

    Traks

    Have you registered the listener?
     
  3. Offline

    danielh112

    Yes I have registered, also got other listeners working in that class
     
  4. Offline

    AoH_Ruthless

    danielh112
    1. Did you try debugging?
    2. Did you try raising your event priority?
    3. Maybe players are respawning before the delayed task runs ... I honestly can't even see why you have a delayed task before setting the respawn location. Try removing that.
     
  5. Offline

    danielh112

    Thank you, yes I turned out the second one fixed the issue (as well as doing the third one anyway :) )
     
Thread Status:
Not open for further replies.

Share This Page