Respawn points not working

Discussion in 'Plugin Development' started by bobthefish, Jul 16, 2014.

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

    bobthefish

    Hi,

    In my plugin, I need to have it so that after a player dies, he spawns again in a spot based on what arena he was in when he died (its a pvp plugin)

    here is my RespawnListenerClass:
    Code:java
    1. package me.BobTheFish.Kitpvp;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.World;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerRespawnEvent;
    10.  
    11. public class RespawnListener implements Listener {
    12.  
    13. mainKitPvp plugin;
    14. public RespawnListener(mainKitPvp plugin) {
    15. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    16. this.plugin = plugin;
    17. }
    18.  
    19. @EventHandler
    20. public void click(PlayerRespawnEvent e){
    21. Player p = e.getPlayer();
    22. String arena = plugin.playerConfig.getString("Players." + p.getName() + ".Arena");
    23.  
    24. if(arena.equals("none")){
    25. p.sendMessage("none");
    26. World s = Bukkit.getWorld(plugin.getConfig().getString("Spawn.world"));
    27. p.sendMessage("none");
    28. Location spawn = new Location(s,
    29. plugin.getConfig().getInt("Spawn.x"),
    30. plugin.getConfig().getInt("Spawn..y"),
    31. plugin.getConfig().getInt("Spawn.z"),
    32. plugin.getConfig().getInt("Spawn.yaw"),
    33. plugin.getConfig().getInt("Spawn.pitch"));
    34. p.sendMessage("none");
    35. p.teleport(spawn);
    36. p.sendMessage("none");
    37. }
    38. else{
    39. p.sendMessage("Other");
    40. World w = Bukkit.getWorld(plugin.getConfig().getString("Arenas." + arena + ".world"));
    41. Location loc = new Location(w,
    42. plugin.getConfig().getInt("Arenas." + arena + ".x"),
    43. plugin.getConfig().getInt("Arenas." + arena + ".y"),
    44. plugin.getConfig().getInt("Arenas." + arena + ".z"));
    45. p.teleport(loc);
    46. }
    47.  
    48. }
    49.  
    50. }
    51.  


    when I die, it gives me all four "none"s but doesnt teleport me anywhere (I spawn at the default world spawn)

    here is my Config file, and then my PlayerConfig:

    Code:
    Spawn:
      x: 271.0
      y: 79.0
      z: 236.0
      world: world
      pitch: 30.449978
      yaw: 92.399475
    Arenas:
      IcyForest:
        price: 0
        world: test
        x: 159.0
        y: 5.0
        z: -979.0
        item: STONE
        color: f
    Code:
    Players:
      pkbear:
        Arena: none
        Account: 0
      AdmiralA01:
        Arena: none
        Account: 0
    Im not getting any errors in the console right now
     
  2. Offline

    MrKeals

    PHP:
    plugin.getConfig().getDouble("Spawn.z")
    getDouble() not getInt()
     
  3. Offline

    bobthefish

    MrKeals I tried that, but I couldnt add the pitch and yaw with doubles, but I could change the spawn point to an int
     
  4. Offline

    Gater12

  5. Offline

    MrKeals

    Yaw and Pitch are float values
     
  6. Offline

    bobthefish

    Gater12 no I havent, I thought that set the whole worlds respawn location, but I have different arenas in the same world MrKeals ahhh ok that might make more sense

    MrKeals so how do I get a float value from the config then?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  7. Offline

    Gater12

  8. Offline

    bobthefish

    Gater12 so then something like:

    Code:java
    1. float f = Float.parseFloat(plugin.getConfig().getString("Spawn.yaw"));

    then put "f" as the value for the yaw

    EDIT: I tried that, still no effect
     
  9. Offline

    Gater12

  10. Offline

    bobthefish

  11. Offline

    MrKeals

    Code:java
    1.  
    2. World s = Bukkit.getWorld(plugin.getConfig().getString("Spawn.world"));
    3. p.sendMessage("none");
    4. Location spawn = new Location(s,
    5. plugin.getConfig().getDouble("Spawn.x"),
    6. plugin.getConfig().getDouble("Spawn..y"),
    7. plugin.getConfig().getDouble("Spawn.z"),
    8. (float)plugin.getConfig().getDouble("Spawn.yaw"),
    9. (float)plugin.getConfig().getDouble("Spawn.pitch"));
     
  12. Offline

    bobthefish

    MrKeals It still didnt work, there was no apparent effect

    MrKeals, I just realized, I have multiverse and essentials installed, could they be resetting the spawn location?

    does anyone know whats wrong with it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  13. Offline

    AoH_Ruthless

    bobthefish
    Are you calling a new instance of your respawn listener in your main class? If so, show that code.
     
  14. Offline

    bobthefish

    AoH_Ruthless I figured it out, idk why it wasn't happening, but I delayed the task by 1 tick, and now it works just fine:
    Code:java
    1. public void onRespawn(PlayerRespawnEvent e){
    2. final Player p = e.getPlayer();
    3. final String arena = plugin.playerConfig.getString("Players." + p.getName() + ".Arena");
    4. if(arena.equals("none")){
    5. new BukkitRunnable (){
    6.  
    7. @Override
    8. public void run() {
    9. p.sendMessage("none");
    10. World s = Bukkit.getWorld(plugin.getConfig().getString("Spawn.world"));
    11. p.sendMessage("none");
    12. Location spawn = new Location(s,
    13. plugin.getConfig().getDouble("Spawn.x"),
    14. plugin.getConfig().getDouble("Spawn..y"),
    15. plugin.getConfig().getDouble("Spawn.z"),
    16. (float)plugin.getConfig().getDouble("Spawn.yaw"),
    17. (float)plugin.getConfig().getDouble("Spawn.pitch"));
    18. p.teleport(spawn);
    19. p.sendMessage("none");
    20.  
    21. }
    22.  
    23. }.runTaskLater(plugin, 1);
     
Thread Status:
Not open for further replies.

Share This Page