public boolean build(Player p, int tips, int id) { if (!plugin.getConfig().getBoolean("allow.zero_room")) { TARDISMessage.send(p, "ZERO_DISABLED"); return true; } TARDISInteriorPostioning tintpos = new TARDISInteriorPostioning(plugin); int slot = tips; if (tips == -1) { slot = tintpos.getFreeSlot(); // uodate TARDIS table with new slot number QueryFactory qf = new QueryFactory(plugin); HashMap<String, Object> set = new HashMap<String, Object>(); set.put("tips", slot); HashMap<String, Object> where = new HashMap<String, Object>(); where.put("tardis_id", id); qf.doUpdate("tardis", set, where); } TARDISTIPSData pos = tintpos.getTIPSData(slot); int x = pos.getCentreX(); int y = 64; int z = pos.getCentreZ(); World w = plugin.getServer().getWorld("TARDIS_Zero_room"); if (w == null) { TARDISMessage.send(p, "ZERO_NOT_FOUND"); return true; } Location l = new Location(w, x, y, z); TARDISRoomBuilder builder = new TARDISRoomBuilder(plugin, "ZERO", l, COMPASS.SOUTH, p); if (builder.build()) { UUID uuid = p.getUniqueId(); // ok, room growing was successful, so take their energy! int amount = plugin.getRoomsConfig().getInt("rooms.ZERO.cost"); QueryFactory qf = new QueryFactory(plugin); HashMap<String, Object> set = new HashMap<String, Object>(); set.put("uuid", p.getUniqueId().toString()); qf.alterEnergyLevel("tardis", -amount, set, p); // remove blocks from condenser table if rooms_require_blocks is true if (plugin.getConfig().getBoolean("growth.rooms_require_blocks")) { TARDISCondenserData c_data = plugin.getGeneralKeeper().getRoomCondenserData().get(uuid); for (Map.Entry<String, Integer> entry : c_data.getBlockIDCount().entrySet()) { HashMap<String, Object> wherec = new HashMap<String, Object>(); wherec.put("tardis_id", c_data.getTardis_id()); wherec.put("block_data", entry.getKey()); qf.alterCondenserBlockCount(entry.getValue(), wherec); } plugin.getGeneralKeeper().getRoomCondenserData().remove(uuid); } // are we doing an achievement? if (plugin.getAchievementConfig().getBoolean("rooms.enabled")) { TARDISAchievementFactory taf = new TARDISAchievementFactory( plugin, p, "rooms", plugin.getBuildKeeper().getSeeds().size()); taf.doAchievement("ZERO"); } } return true; }
/** * Calculate the position data for a TIPS slot. * * @param slot the slot position in the grid (a number between 0, 399 inclusive) * @return a TIPS Data container */ public TARDISTIPSData getTIPSData(int slot) { TARDISTIPSData data = new TARDISTIPSData(); int factorX = 0; int factorZ = 0; int subtract = 0; if (slot > 399 && slot < 800) { factorX = 20480; subtract = 400; } if (slot > 799 && slot < 1200) { factorZ = 20480; subtract = 800; } if (slot > 1199 && slot < 1600) { factorX = 20480; factorZ = 20480; subtract = 1200; } int row = (slot - subtract) / 20; int col = (slot - subtract) % 20; data.setMinX((row * 1024) + factorX); data.setCentreX((row * 1024 + 496) + factorX); data.setMaxX((row * 1024 + 1023) + factorX); data.setMinZ((col * 1024) + factorZ); data.setCentreZ((col * 1024 + 496) + factorZ); data.setMaxZ((col * 1024 + 1023) + factorZ); data.setSlot(slot); return data; }
public void reclaimChunks(World w, TARDISTIPSData data) { // get starting chunk Location l = new Location(w, data.getMinX(), 0, data.getMinZ()); Chunk chunk = w.getChunkAt(l); int sx = chunk.getX(); int sz = chunk.getZ(); for (int x = 0; x < 64; x++) { for (int z = 0; z < 64; z++) { int cx = sx + x; int cz = sz + z; w.regenerateChunk(cx, cz); w.getChunkAt(cx, cz).unload(true, false); } } }
/** * Calculate the position data for the Junk TARDIS TIPS slot. * * @return a TIPS Data container */ public TARDISTIPSData getTIPSJunkData() { TARDISTIPSData data = new TARDISTIPSData(); int row = -1; int col = -1; data.setMinX((row * 1024)); data.setCentreX((row * 1024 + 496)); data.setMaxX((row * 1024 + 1023)); data.setMinZ((col * 1024)); data.setCentreZ((col * 1024 + 496)); data.setMaxZ((col * 1024 + 1023)); data.setSlot(-999); return data; }