Solved Need help with PlayerRespawnEvent

Discussion in 'Plugin Development' started by Moneymaster2012, Dec 30, 2016.

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

    Moneymaster2012

    I don't have any errors in the console or anything. When I die and respawn, it doesn't teleport me to where I set it.

    Code:
        @EventHandler
        public void onDeath(PlayerRespawnEvent e){
            Player p = (Player) e.getPlayer();
            if (config.getBoolean("Enable-Feature" + ".DeathPlace") == true) {
                World w = Bukkit.getServer().getWorld(settings.getData().getString("deathpoint.world"));
                double x = settings.getData().getDouble("deathpoint.x");
                double y = settings.getData().getDouble("deathpoint.y");
                double z = settings.getData().getDouble("deathpoint.z");
                p.teleport(new Location(w, x, y, z));
            }
        }
     
  2. @Moneymaster2012
    Events are fired before the action actually happens. This is so you can cancel them. In this case, the Event is fired before the player has actually respawned. Either schedule a BukkitRunnable to run on the next tick, or, use the e.setRespawnLocation() (which I strongly recommend).
     
  3. Offline

    Moneymaster2012

    Thank you so much! It works perfectly!
     
Thread Status:
Not open for further replies.

Share This Page