/* * Copyright (C) 2014 eccentric_nz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package me.eccentric_nz.TARDIS.desktop; import java.io.File; import java.util.HashMap; import java.util.UUID; import me.eccentric_nz.TARDIS.JSON.JSONArray; import me.eccentric_nz.TARDIS.JSON.JSONObject; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.builders.TARDISInteriorPostioning; import me.eccentric_nz.TARDIS.builders.TARDISTIPSData; import me.eccentric_nz.TARDIS.database.QueryFactory; import me.eccentric_nz.TARDIS.database.ResultSetTardis; import me.eccentric_nz.TARDIS.database.data.Tardis; import me.eccentric_nz.TARDIS.schematic.TARDISSchematicGZip; import me.eccentric_nz.TARDIS.utility.TARDISBlockSetters; import me.eccentric_nz.TARDIS.utility.TARDISMessage; import me.eccentric_nz.TARDIS.utility.TARDISNumberParsers; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.entity.Player; /** * There was also a safety mechanism for when TARDIS rooms were deleted, * automatically relocating any living beings in the deleted room, depositing * them in the control room. * * @author eccentric_nz */ public class TARDISWallFloorRunnable extends TARDISThemeRunnable implements Runnable { private final TARDIS plugin; private final UUID uuid; private final TARDISUpgradeData tud; private boolean running; int id, slot, level = 0, row = 0, h, w, c, startx, starty, startz, resetx, resetz, j = 2; World world; JSONArray arr; Material wall_type, floor_type; byte wall_data, floor_data; QueryFactory qf; boolean own_world; Player player; public TARDISWallFloorRunnable(TARDIS plugin, UUID uuid, TARDISUpgradeData tud) { this.plugin = plugin; this.uuid = uuid; this.tud = tud; this.qf = new QueryFactory(this.plugin); } @Override @SuppressWarnings("deprecation") public void run() { // initialise if (!running) { String directory = (tud.getSchematic().isCustom()) ? "user_schematics" : "schematics"; String path = plugin.getDataFolder() + File.separator + directory + File.separator + tud.getSchematic().getPermission() + ".tschm"; File file = new File(path); if (!file.exists()) { plugin.debug(plugin.getPluginName() + "Could not find a schematic with that name!"); return; } // get JSON JSONObject obj = TARDISSchematicGZip.unzip(path); // get dimensions JSONObject dimensions = (JSONObject) obj.get("dimensions"); h = dimensions.getInt("height"); w = dimensions.getInt("width"); c = dimensions.getInt("length"); // calculate startx, starty, startz HashMap<String, Object> wheret = new HashMap<String, Object>(); wheret.put("uuid", uuid.toString()); ResultSetTardis rs = new ResultSetTardis(plugin, wheret, "", false, 0); if (!rs.resultSet()) { // abort and return energy HashMap<String, Object> wherea = new HashMap<String, Object>(); wherea.put("uuid", uuid.toString()); int amount = plugin.getArtronConfig().getInt("upgrades." + tud.getSchematic().getPermission()); qf.alterEnergyLevel("tardis", amount, wherea, player); } Tardis tardis = rs.getTardis(); slot = tardis.getTIPS(); id = tardis.getTardis_id(); if (slot != -1) { // default world - use TIPS TARDISInteriorPostioning tintpos = new TARDISInteriorPostioning(plugin); TARDISTIPSData pos = tintpos.getTIPSData(slot); startx = pos.getCentreX(); resetx = pos.getCentreX(); startz = pos.getCentreZ(); resetz = pos.getCentreZ(); } else { int gsl[] = plugin.getLocationUtils().getStartLocation(tardis.getTardis_id()); startx = gsl[0]; resetx = gsl[1]; startz = gsl[2]; resetz = gsl[3]; } starty = (tud.getSchematic().getPermission().equals("redstone")) ? 65 : 64; String[] split = tardis.getChunk().split(":"); world = plugin.getServer().getWorld(split[0]); own_world = plugin.getConfig().getBoolean("creation.create_worlds"); // wall/floor block prefs String wall[] = tud.getWall().split(":"); String floor[] = tud.getFloor().split(":"); wall_type = Material.valueOf(wall[0]); floor_type = Material.valueOf(floor[0]); wall_data = TARDISNumberParsers.parseByte(wall[1]); floor_data = TARDISNumberParsers.parseByte(floor[1]); // get input array arr = (JSONArray) obj.get("input"); // set running running = true; player = plugin.getServer().getPlayer(uuid); // remove upgrade data plugin.getTrackerKeeper().getUpgrades().remove(uuid); } if (level == (h - 1) && row == (w - 1)) { // we're finished cancel the task plugin.getServer().getScheduler().cancelTask(taskID); taskID = 0; TARDISMessage.send(player, "UPGRADE_FINISHED"); } else { JSONArray floor = (JSONArray) arr.get(level); JSONArray r = (JSONArray) floor.get(row); // place a row of blocks for (int col = 0; col < c; col++) { JSONObject bb = (JSONObject) r.get(col); int x = startx + row; int y = starty + level; int z = startz + col; // if we're setting the biome to sky, do it now if (plugin.getConfig().getBoolean("creation.sky_biome") && level == 0) { world.setBiome(x, z, Biome.VOID); } Material type = Material.valueOf((String) bb.get("type")); byte data = bb.getByte("data"); if (type.equals(Material.WOOL)) { switch (data) { case 1: type = wall_type; data = wall_data; break; case 8: type = floor_type; data = floor_data; break; default: break; } TARDISBlockSetters.setBlock(world, x, y, z, type, data); } } if (row < w) { row++; } if (row == w && level < h) { row = 0; level++; } } } }