Solved More optimized way for getLocation()?

Discussion in 'Plugin Development' started by envic, Jul 9, 2016.

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

    envic

    Hi guys,
    Simply a small problem with getting player location and setup it in config file.
    here a way i tried:

    Code:
    if (args[2].equalsIgnoreCase("first")) {
    
                                    main.getInstance().getConfig().set("spawns.spawn0.w", p.getLocation().getWorld().getName());
                                    main.getInstance().getConfig().set("spawns.spawn0.x", p.getLocation().getX());
                                    main.getInstance().getConfig().set("spawns.spawn0.y", p.getLocation().getY());
                                    main.getInstance().getConfig().set("spawns.spawn0.z", p.getLocation().getZ());
                                    main.getInstance().saveConfig();
                                    main.getInstance().reloadConfig();
                                    main.getInstance().getLogger()
                                            .info(ChatColor.RED + p.getName() + "set a new spawn point(1)!");
                                    sender.sendMessage(pluginname + ChatColor.GREEN + "First spawn point has been set.");
                                    return true;
                                }
    I know it's rather not okay to get config file each time! and in this way i'm not able to get player yaw and pitch!

    Code:
    for (int i = 0; i < 4; i++) {
    
                    World world = Bukkit.getServer().getWorld(this.getConfig().getString("spawns.spawn" + i + ".w"));
                    double x = getConfig().getDouble("spawns.spawn" + i + ".x");
                    double y = getConfig().getDouble("spawns.spawn" + i + ".y");
                    double z = getConfig().getDouble("spawns.spawn" + i + ".z");
                    spawnpoints.add(new Location(world, x, y, z));
                }
    know a way even better?
    glad to hear it.
    thanks
     
  2. just add the values from location.getYaw() and location.getPitch() to the config and read them later, Location constructor has arguments for pitch and yaw btw.
     
  3. Instead of you yourself having to save all the values of the Location, let Yaml do it for you! Location implements ConfigurationSerializable, and that means that you can just do
    Code:
    FileConfiguraton.set("path", Location)
     
    FisheyLP likes this.
Thread Status:
Not open for further replies.

Share This Page