Could someone learn me how to use CONFIG in coding?

Discussion in 'Plugin Development' started by JavaNaza, Jan 14, 2018.

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


    Hello, could someone learn me how to use configs in coding? I dont know how to save Location.
    Last edited: Jan 14, 2018
  2. Bukkit doesn't have Locations implemented in FileConfiguration, so you have to add it manually.

    Put this in your code:

    public static void setLocation (FileConfiguration config, String path, Location l) {
        config.set(path+".world", l.getWorld().getName());
        config.set(path+".x", l.getX());
        config.set(path+".y", l.getY());
        config.set(path+".z", l.getZ());
        config.set(path+".yaw", (double)l.getYaw());
        config.set(path+".pitch", (double)l.getPitch());
    public static Location getLocation (FileConfiguration config, String path) {
        return new Location(
    and you can use it as so:

    Location spawn = ((Player)sender).getLocation(); // Assuming this is in a /setspawn command, as an example
    setLocation(getConfig(), "locations.spawn", spawn); // "locations." is not needed, it just organizes the config
    sender.sendMessage("Spawn set!"); // Example message
    Location spawn = getLocation(getConfig(), "locations.spawn") // Assuming this is in a /spawn command
    ((Player)sender).teleport(spawn); // Teleport the player
    sender.sendMessage("Welcome back to spawn!"); // Example message
Thread Status:
Not open for further replies.

Share This Page