Making players fly when they respawn

Discussion in 'Plugin Development' started by eric-wieser, Apr 24, 2012.

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

    eric-wieser

    I'm currently using this code to try and make players fly when they respawn

    Code:
    @EventHandler
    public void playerSpawned(PlayerRespawnEvent event) {
    	Player p = event.getPlayer();
    	if (spectators.contains(p)) {
    		p.setAllowFlight(true);
    		p.setFlying(true);
    		getServer().broadcastMessage("Testing flying");
    	}
    }
    However, although the message is broadcast, the player cannot fly. This seems to be because the player has not finished respawning when the flying is enabled. At what point does the player succesfully respawn, and it become valid to call `setFlying` and `setAllowFlight`?
     
  2. Offline

    Zelnehlun

    Try delaying the methods setAllowFlight() and setFlying() for some ticks by using Bukkit.getScheduler().schedule...

    But I am not sure wether this solves this problem.
     
Thread Status:
Not open for further replies.

Share This Page