Solved Teleport player with Pitch and Yaw

Discussion in 'Plugin Development' started by ARCT3CK, Sep 16, 2014.

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

    ARCT3CK

    - SOLVED -

    Hi everyone, i need some help doing this.
    Currently i'm making a lobby plugin for my server, but i have this issue.
    I store the cords of the spawn in a config (This works).
    Then i make the player appear in the coords (This works too).
    But the player appears looking at the sky, (but in the correct block position x,y,z) yaw and pitch aren't working...
    The code:
    Code:java
    1. // SPAWN TP
    2.  
    3. @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
    4. public void onJoin(PlayerJoinEvent event) {
    5. Player p = event.getPlayer();
    6. if (Main.config.spawnTP == true) {
    7. @SuppressWarnings("unused")
    8. String mundo = Main.config.lobbyWorld;
    9. double warpX = Main.config.lobbySpawnX;
    10. double warpY = Main.config.lobbySpawnY;
    11. double warpZ = Main.config.lobbySpawnZ;
    12. float warpPitch = Main.config.lobbySpawnPitch;
    13. float warpYaw = Main.config.lobbySpawnYaw;
    14. p.teleport(new Location(p.getWorld(), warpX, warpY, warpZ,
    15. warpYaw, warpPitch));
    16. p.getLocation().setPitch(warpPitch);
    17. p.getLocation().setY(warpYaw);
    18. }
    19. }


    And the method to store the coords on config:

    Code:java
    1. final Location location = ((Player) sender).getLocation();
    2. this.config.lobbyWorld = location.getWorld().getName();
    3. this.config.lobbySpawnX = location.getX();
    4. this.config.lobbySpawnY = location.getY();
    5. this.config.lobbySpawnZ = location.getZ();
    6. this.config.lobbySpawnYaw = location.getYaw();
    7. this.config.lobbySpawnPitch = location.getPitch();
    8. try {
    9. this.config.save();
    10. } catch (InvalidConfigurationException e) {
    11. sender.sendMessage("§f[§6Skylobby§f] §cError al guardar la ubicación.");
    12. e.printStackTrace();
    13. }
    14. sender.sendMessage("§f[§6Skylobby§f] §fLobby establecido §8» §fX:"
    15. + location.getBlockX()
    16. + "§b,§f Y:"
    17. + location.getBlockY()
    18. + "§b,§f Z:"
    19. + location.getBlockZ()
    20. + "§b,§f YAW:"
    21. + location.getYaw()
    22. + "§b,§f PITCH:" + location.getPitch());

    Thank you
     
  2. Offline

    BeastCraft3

    ARCT3CK
    This is the code I usually use, I hope you find anything inside it that's useful for you.
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. Player p = e.getPlayer();
    4. if(plugin.getConfig().getConfigurationSection("Kitpvp") != null) {
    5. World w = Bukkit.getServer().getWorld(plugin.getConfig().getString("Kitpvp.world"));
    6. float yaw = (float) plugin.getConfig().getDouble("Kitpvp.yaw");
    7. float pitch = (float) plugin.getConfig().getDouble("Kitpvp.pitch");
    8. double x = plugin.getConfig().getDouble("Kitpvp.x");
    9. double y = plugin.getConfig().getDouble("Kitpvp.y");
    10. double z = plugin.getConfig().getDouble("Kitpvp.z");
    11. Location loc = new Location (w, x, y, z);
    12. loc.setYaw(yaw);
    13. p.getLocation().setPitch(pitch);
    14. p.teleport(loc);
    15. }
    16.  
     
    ARCT3CK likes this.
  3. Offline

    ARCT3CK

    Ohh, this works!! thank you so much brother :D
     
  4. Offline

    BeastCraft3

Thread Status:
Not open for further replies.

Share This Page