package me.jacobcrofts.simplestructureloader.api;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import me.jacobcrofts.simplestructureloader.util.Selection;

public final class StructureAPI {
	
	private StructureAPI() {}
	
	public static void writeToFile(String path, Selection selection) throws IOException {
		FileWriter writer = new FileWriter(path);
		writer.write(selection.toJSON().toJSONString());
		writer.close();
	}
	
	public static JSONArray readFromFile(String path) throws FileNotFoundException, IOException, ParseException {
		return (JSONArray) new JSONParser().parse(new FileReader(path));
	}
	
	public static void placeStructure(Selection selection) {
		// TODO
	}
	
}

@@ -161,24 +161,83 @@
 Exception;%0A%0A
+import org.bukkit.Location;%0Aimport org.bukkit.block.Block;%0A
 import org.j
@@ -258,16 +258,16 @@
 NArray;%0A
-
 import o
@@ -343,24 +343,85 @@
 Exception;%0A%0A
+import me.jacobcrofts.simplestructureloader.util.SavedBlock;%0A
 import me.ja
@@ -914,32 +914,66 @@
 er(path));%0A%09%7D%0A%09%0A
+%09@SuppressWarnings(%22deprecation%22)%0A
 %09public static v
@@ -1014,21 +1014,288 @@
 tion
-) %7B%0A%09%09// TODO
+, Location baseLocation) %7B%0A%09%09for (SavedBlock block : selection.getSavedBlocks()) %7B%0A%09%09%09Block realBlock = baseLocation.add(block.getRelativeX(), block.getRelativeY(), block.getRelativeZ()).getBlock();%0A%09%09%09realBlock.setType(block.getType());%0A%09%09%09realBlock.setData(block.getData());%0A%09%09%7D
 %0A%09%7D%0A

Add feature: support for pasting structure at a given location