Solved When a player dies, they are tped to spawn and not the location I provide.

Discussion in 'Plugin Development' started by ProSl3nderMan, Sep 8, 2015.

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

    ProSl3nderMan

    Hey guys, for the RespawnPlayerEvent, it's not respawning the player in the location given but instead spawn. code:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onRespawn(PlayerRespawnEvent event) {
            Player p = event.getPlayer();
            int x = AccessControl.plugin.getConfig().getInt("players." + p.getPlayer().getUniqueId() + ".cell.x");
            int y = AccessControl.plugin.getConfig().getInt("players." + p.getPlayer().getUniqueId() + ".cell.y");
            int z = AccessControl.plugin.getConfig().getInt("players." + p.getPlayer().getUniqueId() + ".cell.z");
            event.setRespawnLocation(new Location(Bukkit.getWorld(AccessControl.plugin.getConfig().getString("players." + p.getPlayer().getUniqueId() + ".map")), x, y, z));
        }
    Please help?
     
  2. Offline

    BrickBoy55

    @ProSl3nderMan Try
    Code:
    player.getUniqueId().toString()
    
    Also, no point using basically Player.getPlayer(), just use your player variable.
     
  3. Offline

    bowlerguy66

    Put a delay on it

    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
        @Override
               public void run() {
                      //Your code here
                      return;
                }
    }, 20L); // 1 second == 20L
     
  4. Offline

    mine-care

    @BrickBoy55 that is exacly the same as what the op does, the toString() is called by default.

    SomeObject obj = new SomeObject(...);
    print("Object: "+obj);
    print("Object: "+obj.toString());

    they have the same output. Your second point is correct!


    @bowlerguy66
    Why returning exacly? Also keep spoonfeeding low :/ it doesnt help.
     
    BrickBoy55 likes this.
  5. Offline

    oceantheskatr

    Using player.getUniqueId() will return a UUID, you need to use .toString() to convert to a string.
     
  6. Offline

    mine-care

    @oceantheskatr Νot what i ment,
    In the context it is used, it doesnt matter if you invoke toString() or not. I provided an example...

    I ment that by using for instance pring("A string" + anObject) will invoke toString() for the object, you dont have to do it.
     
  7. Offline

    oceantheskatr

    @mine-care Ahh right, didn't look at OP's code xP
     
  8. Offline

    mine-care

  9. Are you sure the event is working ? Did you register the events ?
     
    ferrybig likes this.
  10. Offline

    Signatured

    Try setting the respawn location on death rather than respawn. It may be respawn is happening to quickly.

    If that doesn't work, try putting a 1-2 tick delay on it to make sure.
     
  11. Offline

    RoboticPlayer

    @ProSl3nderMan I think it would be much easier to simply set a delayed task (for maybe 1 or 2 ticks), then teleport the player to that location.
     
  12. Offline

    ProSl3nderMan

    Whoa whoa whoa, it works lol. I just forgot to say it does xP
     
Thread Status:
Not open for further replies.

Share This Page