Player respawn issue

Discussion in 'Plugin Development' started by Cosmicluck, Jun 28, 2013.

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

    Cosmicluck

    Hello!
    So in my minigame, I want the teams to respawn in their respective places. Here's my code:
    Code:java
    1. @EventHandler
    2. public void onPlayerRespawnEvent(PlayerRespawnEvent event) {
    3. spawn = new Location(Bukkit.getWorld("world"), 93.9, 57.0, 932.0);
    4. spawn1 = new Location(Bukkit.getWorld("world"), 93.9, 57.0, 816.0);
    5. Player player = event.getPlayer();
    6. player.getInventory().clear();
    7. player.getEquipment().clear();
    8. player.sendMessage("The respawning will be fixed in the future!");
    9. if (team.hasPlayer(player)) {
    10.  
    11. player.teleport(spawn);
    12. }
    13. if (team1.hasPlayer(player)) {
    14.  
    15. player.teleport(spawn1);
    16. }
    17. }
    18.  
    19. }



    However, this does NOT work. Is there something I am doing wrong?

    P.S: I have registered team, team1, spawn, and spawn1 in the class.


    Thanks!
     
  2. Offline

    Seadragon91

    Use the method setRespawnLocation(respawnLocation) from the class PlayerRespawnEvent .
    Code:
    event.setRespawnLocation(respawnLocation);
     
  3. Offline

    Cosmicluck

    I now have this:
    Code:java
    1. @EventHandler
    2. public void onPlayerRespawnEvent(PlayerRespawnEvent event) {
    3. spawn = new Location(Bukkit.getWorld("world"), 93.9, 57.0, 932.0);
    4. spawn1 = new Location(Bukkit.getWorld("world"), 93.9, 57.0, 816.0);
    5. Player player = event.getPlayer();
    6. if (team.hasPlayer(player)) {
    7. event.setRespawnLocation(spawn);
    8. }
    9. if (team1.hasPlayer(player)) {
    10. event.setRespawnLocation(spawn1);
    11.  
    12. }
    13. }
    14. }



    And it doesnt work lol
     
  4. Offline

    skipperguy12

    Cosmicluck
    You could:
    • Wait a tick and then manually teleport them to their location (use scheduler)
    • Set their bed location to the team spawn location at the beginning of the game
     
Thread Status:
Not open for further replies.

Share This Page