Set Spawn YAW and PITCH not working

Discussion in 'Plugin Development' started by xCalib0r, Apr 5, 2014.

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

    xCalib0r

    I fixed that problem, now my problem is that my /setspawn is not accurate enough. It's because the setspawn only used ints and not doubles so when I spawn, it spawns me to a block next to me. How can I make this more accurate?

    cmdSetSpawn:
    Code:
    Wrapper.instance.getConfig().set("spawn.world",
    p.getLocation().getWorld().getName());
    Wrapper.instance.getConfig().set("spawn.x", p.getLocation().getX());
    Wrapper.instance.getConfig().set("spawn.y", p.getLocation().getY());
    Wrapper.instance.getConfig().set("spawn.z", p.getLocation().getZ());
    Wrapper.instance.getConfig().set("spawn.yaw",
    p.getLocation().getYaw());
    Wrapper.instance.getConfig().set("spawn.pitch",
    p.getLocation().getPitch());
     
    int x = Wrapper.instance.getConfig().getInt("spawn.x");
    int y = Wrapper.instance.getConfig().getInt("spawn.y");
    int z = Wrapper.instance.getConfig().getInt("spawn.z");
     
    Wrapper.instance.saveConfig();
     
    p.getWorld().setSpawnLocation(x, y + 1, z);
     
    p.sendMessage(ChatColor.GREEN + "Spawn set!");
    
    cmdSpawn:
    Code:
    final Location spawn = p.getWorld().getSpawnLocation();
    spawn.setYaw(yaw);
    spawn.setPitch(pitch);
    p.teleport(spawn);
    
     
  2. Offline

    GotRice

    xCalib0r You need to set the yaw of the location using location.setYaw(yaw); and location.setPitch(pitch); before teleporting the player.
     
  3. Offline

    xCalib0r

    nope not working
    Code:
    p.getLocation().setYaw(yaw);
    p.getLocation().setPitch(pitch);
    p.teleport(spawn);
    
     
  4. Offline

    GotRice

    xCalib0r spawn.setYaw(yaw); spawn.setPitch(pitch);
     
  5. Offline

    xCalib0r

    THANK YOU!!!

    GotRice Also anyway to get the EXACT spawn location? Since as you can see spawn only lets you get ints, anytime you do /spawn your always at the edge of the block and not exactly where you are supposed to be? Anyway to ffix this?

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

    GotRice

    xCalib0r I think bukkit saves spawn as blocks (exact doubles). You would have create your own spawn point with non-exact coords. (Saving doubles to config and loading them, then creating a new location)
     
  7. Offline

    BillyGalbreath

    I hate when people erase the original question like this. Other people that Google this question will now get this page as a result and be even more lost.

    Edit: Thanks for putting the original post back up! ^_^
     
  8. Offline

    xCalib0r

  9. Offline

    GotRice

    xCalib0r Oh I revisited your code, first when you are getting the x y z coords. from your config, get them as Doubles (Currently set as ints).
     
  10. Offline

    xCalib0r

    GotRice you can't , th setspawn method only takes ints.
     
  11. Offline

    GotRice

    xCalib0r Override the Spawn System, create your own location using those doubles, teleport them to your spawn location when they respawn etc.
     
  12. Offline

    BillyGalbreath

    setSpawn() doesnt take pitch and yaw either. Its not a real Location, thus has no direction or velocity. Its just 3 coordinates in 3D space.

    If you wish to control spawn location's pitch and yaw you must override Bukkit's spawn controls and make your own. If you need examples look at Essentials' code, or if you want something less daunting look at my Pl3xSpawn project to see how its done.
     
  13. Offline

    BillyBobJoe168

    Does int and doubles really make a difference for yaw and pitch? if not, you could do player.teleport(world, double x, double y, double z, int yaw, int pitch);
     
  14. Offline

    BillyGalbreath

    Of course it does. Its all about accuracy. Obviously Doubles are far more accurate than Integers.
     
  15. Offline

    coasterman10

    BillyBobJoe168 Integers, doubles, and floats are all different precision numbers. Floats and doubles use floating-point storage which has some bits for exponent and some for value, working like scientific notation, allowing the computer to effectively hold decimal-point values. A double has twice as much memory allocated to it as a float in most circumstances, allowing double the precision, and also larger numbers due to the larger amount of exponent bits and thus higher exponent. Since Minecraft stores angles in degrees, it's not very noticeable, but it's still a good idea to use the original types whenever possible. Casting types unnecessarily is just poor practice and can lead to loss of precision and other corruption, kind of like a game of telephone.
     
  16. Offline

    BillyGalbreath

    Its pretty noticeable, actually. At least to me. being just 1 degree off can create a very "jerky" feeling in the game, depending on what you're doing.
     
  17. Offline

    BillyBobJoe168

    BillyGalbreath Well from what I can tell, he is trying to set up a spawn. Because of this, I don't think it matters if his spawn yaw/pitch is a bit off right?
     
  18. Offline

    BillyGalbreath

    Personal preference, I guess. To me (and my OCDs) it would bother the crap out of me knowing its off even a little. lol
     
  19. Offline

    BillyBobJoe168

    BillyGalbreath lol well
    Show Spoiler
    ////////////////////\///////////////////
     
    BillyGalbreath likes this.
  20. Offline

    xCalib0r

    Guys ,pitch and yaw aren't a problem, it's spawn that I'm trying to figure out .
     
  21. Offline

    BillyBobJoe168

    Well, your code tells the player to spawn at the worlds spawn. You want to do player.teleport(new Location(player.getWorld(), x, y, z, yaw, pitch));
     
  22. Offline

    xCalib0r

    BillyBobJoe168 well no , I don't want that because if they DIE and actually spawn, it won't be the right place.
     
  23. Offline

    BillyGalbreath

    Did you look over the projects I mentioned? Did you even read my posts?
     
    BillyBobJoe168 likes this.
  24. Offline

    BillyBobJoe168

    xCalib0r You know there is a /setworldspawnpoint or something like that command that already is there once you get your server right? If not, since seems like you want a config, you could make a player listener class and for PlayerJoinEvent and PlayerRespawnEvent, just teleport them to the location specified in your config.

    XD

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

    xCalib0r

    BillyBobJoe168 I did make a playerjoin and respawn event telling them to teleport them to the location though they still tp to spawn. Spawn overrides it.

    BillyGalbreath Ya I tried overriding it, it works as when the player joins it put them in the spawn I configed, BUT when they die it puts them in the regular spawn. I tried everything it won't work for when they diee.

    The player joinEvent overrides it but this respawn wont. It teleports you to the reegular spawn again.

    Code:
     
    final World world = Bukkit.getWorld(Wrapper.instance.getConfig()
    .getString("spawn.world"));
    final double x = Wrapper.instance.getConfig().getDouble("spawn.x");
    final double y = Wrapper.instance.getConfig().getDouble("spawn.y");
    final double z = Wrapper.instance.getConfig().getDouble("spawn.z");
    final float yaw = (float) Wrapper.instance.getConfig().getDouble("spawn.yaw");
    final float pitch = (float) Wrapper.instance.getConfig().getDouble("spawn.pitch");
     
    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent e) {
    Player p = e.getPlayer();
    World world = (World) p.getWorld();
     
    if(e instanceof Player) {
    p.teleport(new Location(world, x, y, z, yaw, pitch));
    }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  26. Offline

    GotRice

    xCalib0r You might not like this solution, but you could add a 1-5 tick delay using runnables and then teleport the player.
     
  27. Offline

    xCalib0r

    @BillyGalbreathI also tried this e.setRespawnLocation(new Location(world, x, y, z, yaw, pitch));
    still nothing...

    NEVERMIND, I FIXED IT. THANK YOU EVERYONE.

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

    BillyBobJoe168

    maybe its p.setRespawnLocation?
     
  29. Offline

    xCalib0r

  30. Offline

    Zethariel

    Hook into the OnPlayerSpawnEvent (or whatever it's called), disable it, run your custom teleport script.
     
Thread Status:
Not open for further replies.

Share This Page