Warp direction

Discussion in 'Spigot Plugin Development' started by Koekjeee, Apr 23, 2017.

  1. I've made a warp plugin. It saves the location and the world. But how can i save the direction the player is looking to as well? And how do i receive the information and use it on /warp?
  2. The yaw and the pitch are stored inside the Location class, just like the X, Y, Z and the world.
  3. I don't really get it, how do i add it to this?:
    Code (Text):

    Main.getPlugin().getConfig().set("warps." + args[0].toLowerCase() + ".world", player.getWorld().getName());
          Main.getPlugin().getConfig().set("warps." + args[0].toLowerCase() + ".x", player.getLocation().getBlockX());
          Main.getPlugin().getConfig().set("warps." + args[0].toLowerCase() + ".y", player.getLocation().getBlockY());
          Main.getPlugin().getConfig().set("warps." + args[0].toLowerCase() + ".z", player.getLocation().getBlockZ());
    Code (Text):

      World world = Bukkit.getWorld(Main.getPlugin().getConfig().getString("warps." + args[0].toLowerCase() + ".world"));
          double x = Main.getPlugin().getConfig().getDouble("warps." + args[0].toLowerCase() + ".x", player.getLocation().getBlockX());
          double y = Main.getPlugin().getConfig().getDouble("warps." + args[0].toLowerCase() + ".y", player.getLocation().getBlockY());
          double z = Main.getPlugin().getConfig().getDouble("warps." + args[0].toLowerCase() + ".z", player.getLocation().getBlockZ());
  4. The Location class has this constructor: Location(World world, double x, double y, double z, float yaw, float pitch)
    To get the yaw (for saving): player.getLocation().getYaw();
    You just have to create two more entries in the config file, it's just like you the X, Y, Z.
    • Agree Agree x 1
  5. Do what @Trigary said, here's an example to point you in the right direction:
    Saving the location:
    Code (Text):
    getConfig().set("warps.warpname.x", player.getLocation.getX());
    getConfig().set("warps.warpname.y", player.getLocation.getY());
    getConfig().set("warps.warpname.z", player.getLocation.getZ());
    getConfig().set("warps.warpname.pitch", player.getLocation.getPitch());
    getConfig().set("warps.warpname.yaw",  player.getLocation.getYaw());
    Loading the location:
    Code (Text):

    World world = Bukkit.getWorld(getConfig().getString("warps.warpname.world"));
    double x = getConfig().getDouble("warps.warpname.x");
    double y = getConfig().getDouble("warps.warpname.y");
    double z = getConfig().getDouble("warps.warpname.z");

    //The pitch and yaw are floats, but YamlConfiguration doesnt
    // have a getFloat method so use (float)
    float pitch = (float) getConfig().getDouble("warps.warpname.pitch");
    float yaw = (float) getConfig().getDouble("warps.warpname.yaw");

    Location warpLoc = new Location(world, x, y, z, pitch, yaw);