Block relative = corner1.getRelative(x, y, z);
int xi = relative.getX() - minX, yi = relative.getY() - minY, zi = relative.getZ() - minZ;
if (changes != null) {
changes[xi][yi][zi] = true;
}
BlockState modify = relative.getState();
ItemStack data = new ItemStack(Material.valueOf(query.getString("type")), 0, query.getShort("data"));
if (modify.getType() != data.getType() || !modify.getData().equals(data.getData())) {
// Update the type & data if it has changed
modify.setType(data.getType());
modify.setData(data.getData());
modify.update(true, false); // No-physics update, preventing the need for deferring blocks
modify = corner1.getRelative(x, y, z).getState(); // Grab a new instance
}
if (query.getString("metadata") == null || query.getString("metadata").isEmpty()) {
continue;
}
try {
if (modify instanceof Sign) {
final String[] lines = query.getString("metadata").split("\n");
for (int i = 0; i < lines.length; i++) {
((Sign) modify).setLine(i, lines[i]);
}
modify.update(true, false);
}
// Containers
if (modify instanceof InventoryHolder) {
YamlConfiguration config = new YamlConfiguration();
config.loadFromString(query.getString("metadata"));
((InventoryHolder) modify).getInventory().clear();
for (Object obj : config.getList("items")) {
if (obj instanceof ItemStack) {
((InventoryHolder) modify).getInventory().addItem((ItemStack) obj);
}
}
modify.update(true, false);
}
// Notes
if (modify instanceof NoteBlock) {
String[] split = query.getString("metadata").split("\n");
Note note = new Note(Integer.parseInt(split[1]), Tone.valueOf(split[0]), Boolean.parseBoolean(split[2]));
((NoteBlock) modify).setNote(note);
modify.update(true, false);
}
// Records
if (modify instanceof Jukebox) {
((Jukebox) modify).setPlaying(Material.valueOf(query.getString("metadata")));
modify.update(true, false);
}
// Skulls
if (modify instanceof Skull) {
String[] opts = query.getString("metadata").split("\n");
if (!opts[0].isEmpty()) {
((Skull) modify).setOwner(opts[0]);
}
((Skull) modify).setSkullType(SkullType.valueOf(opts[1]));
((Skull) modify).setRotation(BlockFace.valueOf(opts[2]));
modify.update(true, false);
}
// Command blocks
if (modify instanceof CommandBlock) {
final String[] commandArray = query.getString("metadata").split("\n");
((CommandBlock) modify).setName(commandArray[0]);
((CommandBlock) modify).setCommand(commandArray[1]);
modify.update(true, false);
}
// Creature spawner
if (modify instanceof CreatureSpawner) {
((CreatureSpawner) modify).setSpawnedType(EntityType.valueOf(query.getString("metadata")));
modify.update(true, false);
}
} catch (Exception ex) {
War.war.getLogger().log(Level.WARNING, "Exception loading some tile data. x:" + x + " y:" + y + " z:" + z + " type:" + modify.getType().toString() + " data:" + modify.getData().toString(), ex);
}
}
query.close();
stmt.close();
return changed;