package me.jacobcrofts.simplestructureloader.util;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.json.simple.JSONObject;

public class SavedBlock {

	private final Material type;
	private final byte data;
	private final int relativeX;
	private final int relativeY;
	private final int relativeZ;
	
	@SuppressWarnings("deprecation")
	public SavedBlock(Location baseLocation, Block block) {
		this.type = block.getType();
		this.data = block.getData();
		Location relativeLocation = block.getLocation().subtract(baseLocation);
		this.relativeX = relativeLocation.getBlockX();
		this.relativeY = relativeLocation.getBlockY();
		this.relativeZ = relativeLocation.getBlockZ();
	}
	
	public Material getType() {
		return this.type;
	}
	
	public byte getData() {
		return this.data;
	}
	
	public int getRelativeX() {
		return this.relativeX;
	}
	
	public int getRelativeY() {
		return this.relativeY;
	}
	
	public int getRelativeZ() {
		return this.relativeZ;
	}
	
	@SuppressWarnings("unchecked")
	public JSONObject toJSON() {
		JSONObject json = new JSONObject();
		json.put("type", this.type);
		json.put("data", this.data);
		json.put("relative-x", this.relativeX);
		json.put("relative-y", this.relativeY);
		json.put("relative-z", this.relativeZ);
		return json;
	}
	
}

package me.jacobcrofts.simplestructureloader.util;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.json.simple.JSONObject;

public class SavedBlock {

	private final Material type;
	private final byte data;
	private final int relativeX;
	private final int relativeY;
	private final int relativeZ;
	
	@SuppressWarnings("deprecation")
	public SavedBlock(Location baseLocation, Block block) {
		this.type = block.getType();
		this.data = block.getData();
		Location relativeLocation = block.getLocation().subtract(baseLocation);
		this.relativeX = relativeLocation.getBlockX();
		this.relativeY = relativeLocation.getBlockY();
		this.relativeZ = relativeLocation.getBlockZ();
	}
	
	public SavedBlock(JSONObject savedBlockData) {
		this.type = (Material) savedBlockData.get("type");
		this.data = (byte) savedBlockData.get("data");
		this.relativeX = (int) savedBlockData.get("relative-x");
		this.relativeY = (int) savedBlockData.get("relative-y");
		this.relativeZ = (int) savedBlockData.get("relative-z");
	}
	
	public Material getType() {
		return this.type;
	}
	
	public byte getData() {
		return this.data;
	}
	
	public int getRelativeX() {
		return this.relativeX;
	}
	
	public int getRelativeY() {
		return this.relativeY;
	}
	
	public int getRelativeZ() {
		return this.relativeZ;
	}
	
	@SuppressWarnings("unchecked")
	public JSONObject toJSON() {
		JSONObject savedBlockData = new JSONObject();
		savedBlockData.put("type", this.type);
		savedBlockData.put("data", this.data);
		savedBlockData.put("relative-x", this.relativeX);
		savedBlockData.put("relative-y", this.relativeY);
		savedBlockData.put("relative-z", this.relativeZ);
		return savedBlockData;
	}
	
}

Add feature: SavedBlock may be initialized with a JSONObject