How to set a way someone is facing?

Discussion in 'Plugin Development' started by CandyCranium, Mar 15, 2014.

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

    CandyCranium

    I'm currently trying to make it so that when someone joins or dies, they get teleported to a specific area, and everything is set and all, except I need the player to face a certain direction.

    How would I do this?
    This is what I have so far:
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerJoin(PlayerJoinEvent e) {
    4. Location sspawn = new Location(e.getPlayer().getWorld(), -2532.5, 44, 689.5);
    5. e.getPlayer().teleport(sspawn);
    6. }
    7.  
    8. @EventHandler
    9. public void onPlayerDeath(PlayerDeathEvent e) {
    10. Location sspawn = new Location(e.getEntity().getPlayer().getWorld(), -2532.5, 44, 689.5);
    11. e.getEntity().getPlayer().teleport(sspawn);
    12. }
    13.  
     
  2. Offline

    Keyboard

    try something like
    Location sspawn = new Location(e.getPlayer().getWorld(), -2532.5, 44, 689.5, 0, 0);

    0, 0 is where the 'f' coordinate is and where they face
     
  3. Offline

    ehArcher

    Here buddy, this is my /setspawn and /spawn.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2.  
    3. Player player = (Player) sender;
    4.  
    5. if(cmd.getName().equalsIgnoreCase("setspawn")) {
    6.  
    7. plugin.getConfig().set("spawn.x", player.getLocation().getBlockX());
    8. plugin.getConfig().set("spawn.y", player.getLocation().getBlockY());
    9. plugin.getConfig().set("spawn.z", player.getLocation().getBlockZ());
    10. sender.sendMessage(ChatColor.GREEN + "You have set your spawn point.");
    11. plugin.saveConfig();
    12. plugin.logger.info(pdffile.getName() + " [ " + player.getName() + " has set a new spawn point ]");
    13.  
    14. }
    15.  
    16. if(cmd.getName().equalsIgnoreCase("spawn")) {
    17.  
    18. int x = plugin.getConfig().getInt("spawn.x"), y = plugin.getConfig().getInt("spawn.y"),
    19. z = plugin.getConfig().getInt("spawn.z");
    20. player.teleport(new Location(player.getWorld(), x, y, z));
    21. sender.sendMessage(ChatColor.GREEN + "You have teleported to spawn.");
    22.  
    23. }
    24.  
    25. return false;
    26. }
     
  4. Offline

    AoH_Ruthless

    CandyCranium
    Set the player's Yaw and Pitch. In your location, just add two more fields at the end, which is the yaw and pitch respectively.
     
  5. Offline

    Garris0n

    ehArcher Please don't spoonfeed people, and that's totally irrelevant to what he's doing anyway as you don't save the yaw/pitch. Also you could just save the location instead of constructing one from the config every time.
     
  6. Offline

    CandyCranium

    AoH_Ruthless
    When one presses F3, which one represents the Yaw and Pitch?

    Anybody?

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

    AoH_Ruthless

    CandyCranium
    If you want a smooth teleport, just set the yaw to the player's yaw, and set the pitch to the player's pitch.

    I believe Yaw is the first float. Either way, a simple google search would probably yield you the answer.

    Please refrain from bumping more than once per 24 hours.
     
Thread Status:
Not open for further replies.

Share This Page