Get players looking direction?

Discussion in 'Plugin Development' started by Rowinvd, Feb 8, 2015.

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

    Rowinvd

    I'm making a FFA plugin and i want to see a players look direction. Here is my code:
    Code:
    package me.rowinvd;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class RFFA extends JavaPlugin {
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player) sender;
            PlayerInventory pi = p.getInventory();
    
            if (cmd.getName().equalsIgnoreCase("ffa")) {
                pi.clear();
                pi.addItem(new ItemStack(Material.IRON_SWORD, 1));
                pi.addItem(new ItemStack(Material.FISHING_ROD, 1));
                pi.addItem(new ItemStack(Material.BOW, 1));
                pi.addItem(new ItemStack(Material.ARROW, 8));
                pi.setHelmet(new ItemStack(Material.IRON_HELMET, 1));
                pi.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
                pi.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
                pi.setBoots(new ItemStack(Material.IRON_BOOTS, 1));
                p.sendMessage(ChatColor.RED + "FFA" + (ChatColor.DARK_GRAY + " | " + (ChatColor.YELLOW + "Welcome at FFA!")));
                if (getConfig().getConfigurationSection("spawn") == null) {
                    p.sendMessage(ChatColor.RED + "The FFA spawn has not yet been set!");
                    return true;
                }
                World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world"));
                double x = getConfig().getDouble("spawn.x");
                double y = getConfig().getDouble("spawn.y");
                double z = getConfig().getDouble("spawn.z");
                p.teleport(new Location(w, x, y, z));
            }
            if (cmd.getName().equalsIgnoreCase("setffa")) {
                getConfig().set("spawn.world", p.getLocation().getWorld().getName());
                getConfig().set("spawn.x", p.getLocation().getX());
                getConfig().set("spawn.y", p.getLocation().getY());
                getConfig().set("spawn.z", p.getLocation().getZ());
                saveConfig();
                p.sendMessage(ChatColor.GREEN + "FFA spawn set!");
            }
            return true;
        }
    
    }
     
  2. Offline

    1Rogue

    Code:java
    1. player.getLocation().getYaw();


    Yaw controls rotation, pitch controls incline.
     
  3. Offline

    Rowinvd

    @1Rogue How would i put this in my code? Its giving errors.
    p.teleport(new Location(w, x, y, z, yaw)); is not working?
     
  4. Offline

    Rufus5

    You must also define pitch in that method.

    p.teleport(new Location(w, x, y, z, yaw, pitch))
     
  5. Offline

    Rowinvd

  6. Offline

    Rufus5

    Code:
    p.teleport(New Location(w, x, y, z, 0, 0))
    Try that.
     
  7. Code:
    Location loc = new Location(World, X, Y, Z, Yaw, Pitch);
    player.teleport(loc);
    @Rowinvd That's the basic format for teleporting.
     
Thread Status:
Not open for further replies.

Share This Page