@EventHandler(priority = EventPriority.MONITOR) public void onJunkBrakeUse(PlayerInteractEvent event) { if (plugin.getGeneralKeeper().isJunkTravelling()) { return; } Block block = event.getClickedBlock(); if (block != null) { Material blockType = block.getType(); final Location controlLoc = block.getLocation(); String c_loc = controlLoc.toString(); HashMap<String, Object> where = new HashMap<String, Object>(); where.put("location", c_loc); if (blockType == Material.LEVER) { // Checks handbrake location against the database. where.put("type", 0); ResultSetControls rsh = new ResultSetControls(plugin, where, false); if (rsh.resultSet()) { int id = rsh.getTardis_id(); // is it the Junk TARDIS? HashMap<String, Object> wherei = new HashMap<String, Object>(); wherei.put("tardis_id", id); ResultSetTardis rs = new ResultSetTardis(plugin, wherei, "", false); if (rs.resultSet() && rs.getPreset().equals(PRESET.JUNK)) { final Player player = event.getPlayer(); if (!player.hasPermission("tardis.junk")) { TARDISMessage.send(player, "JUNK_NO_PERM"); return; } // get the destination getDestination(id, player); if (plugin.getGeneralKeeper().getJunkDestination() != null) { // get the current location Location junkloc = null; Biome biome = null; HashMap<String, Object> wherecl = new HashMap<String, Object>(); wherecl.put("tardis_id", id); ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl); if (rsc.resultSet()) { junkloc = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ()); biome = rsc.getBiome(); } if (junkloc == null) { TARDISMessage.send(player, "JUNK_NOT_FOUND"); return; } // destroy junk TARDIS final TARDISMaterialisationData pdd = new TARDISMaterialisationData(); pdd.setPlayer(player); pdd.setChameleon(false); pdd.setDirection(COMPASS.SOUTH); pdd.setLocation(junkloc); pdd.setDematerialise(true); pdd.setHide(false); pdd.setOutside(false); pdd.setSubmarine(rsc.isSubmarine()); pdd.setTardisID(id); pdd.setBiome(biome); plugin.getPresetDestroyer().destroyPreset(pdd); // fly my pretties plugin.getGeneralKeeper().setJunkTravelling(true); } else { TARDISMessage.send(event.getPlayer(), "JUNK_NO_DEST"); return; } } } } if (blockType == Material.TRIPWIRE_HOOK) { // 4 where.put("type", 4); ResultSetControls rst = new ResultSetControls(plugin, where, false); if (rst.resultSet()) { int id = rst.getTardis_id(); // is it the Junk TARDIS? HashMap<String, Object> wherei = new HashMap<String, Object>(); wherei.put("tardis_id", id); ResultSetTardis rs = new ResultSetTardis(plugin, wherei, "", false); if (rs.resultSet() && rs.getPreset().equals(PRESET.JUNK)) { final Player player = event.getPlayer(); if (!player.hasPermission("tardis.junk")) { TARDISMessage.send(player, "JUNK_NO_PERM"); return; } setSignWorld(id, player.getUniqueId()); } } } if (blockType == Material.STONE_BUTTON) { // 1 where.put("type", 1); ResultSetControls rsh = new ResultSetControls(plugin, where, false); if (rsh.resultSet()) { int id = rsh.getTardis_id(); // is it the Junk TARDIS? HashMap<String, Object> wherei = new HashMap<String, Object>(); wherei.put("tardis_id", id); ResultSetTardis rs = new ResultSetTardis(plugin, wherei, "", false); if (rs.resultSet() && rs.getPreset().equals(PRESET.JUNK)) { final Player player = event.getPlayer(); if (!player.hasPermission("tardis.junk")) { TARDISMessage.send(player, "JUNK_NO_PERM"); return; } setSignCoords(id, 2); } } } if (blockType == Material.WOOD_BUTTON) { // 6 where.put("type", 6); ResultSetControls rsh = new ResultSetControls(plugin, where, false); if (rsh.resultSet()) { int id = rsh.getTardis_id(); // is it the Junk TARDIS? HashMap<String, Object> wherei = new HashMap<String, Object>(); wherei.put("tardis_id", id); ResultSetTardis rs = new ResultSetTardis(plugin, wherei, "", false); if (rs.resultSet() && rs.getPreset().equals(PRESET.JUNK)) { final Player player = event.getPlayer(); if (!player.hasPermission("tardis.junk")) { TARDISMessage.send(player, "JUNK_NO_PERM"); return; } setSignCoords(id, 3); } } } } }
@Override public void run() { int[][] ids; byte[][] datas; // get relative locations int x = tmd.getLocation().getBlockX(), plusx = tmd.getLocation().getBlockX() + 1, minusx = tmd.getLocation().getBlockX() - 1; int y; if (preset.equals(PRESET.SUBMERGED)) { y = tmd.getLocation().getBlockY() - 1; } else { y = tmd.getLocation().getBlockY(); } int z = tmd.getLocation().getBlockZ(), plusz = tmd.getLocation().getBlockZ() + 1, minusz = tmd.getLocation().getBlockZ() - 1; World world = tmd.getLocation().getWorld(); if (i < loops) { i++; // expand placed blocks to a police box switch (i % 3) { case 2: // stained ids = stained_column.getId(); datas = stained_column.getData(); break; case 1: // glass ids = glass_column.getId(); datas = glass_column.getData(); break; default: // preset ids = column.getId(); datas = column.getData(); break; } // first run - play sound if (i == 1) { switch (preset) { case GRAVESTONE: // remove flower int flowerx; int flowery = (tmd.getLocation().getBlockY() + 1); int flowerz; switch (tmd.getDirection()) { case NORTH: flowerx = tmd.getLocation().getBlockX(); flowerz = tmd.getLocation().getBlockZ() + 1; break; case WEST: flowerx = tmd.getLocation().getBlockX() + 1; flowerz = tmd.getLocation().getBlockZ(); break; case SOUTH: flowerx = tmd.getLocation().getBlockX(); flowerz = tmd.getLocation().getBlockZ() - 1; break; default: flowerx = tmd.getLocation().getBlockX() - 1; flowerz = tmd.getLocation().getBlockZ(); break; } plugin.getUtils().setBlock(world, flowerx, flowery, flowerz, 0, (byte) 0); break; case CAKE: plugin.getPresetDestroyer().destroyLamp(tmd.getLocation(), preset); break; default: break; } // only play the sound if the player is outside the TARDIS if (tmd.isOutside()) { HashMap<String, Object> wherep = new HashMap<String, Object>(); wherep.put("uuid", tmd.getPlayer().getUniqueId().toString()); ResultSetPlayerPrefs rsp = new ResultSetPlayerPrefs(plugin, wherep); boolean minecart = false; if (rsp.resultSet()) { minecart = rsp.isMinecartOn(); } if (!minecart) { plugin.getUtils().playTARDISSoundNearby(tmd.getLocation(), "tardis_takeoff"); } else { world.playSound(tmd.getLocation(), Sound.MINECART_INSIDE, 1.0F, 0.0F); } } the_colour = getWoolColour(tmd.getTardisID(), preset); } else { // just change the walls int xx, zz; for (int n = 0; n < 9; n++) { int[] colids = ids[n]; byte[] coldatas = datas[n]; switch (n) { case 0: xx = minusx; zz = minusz; break; case 1: xx = x; zz = minusz; break; case 2: xx = plusx; zz = minusz; break; case 3: xx = plusx; zz = z; break; case 4: xx = plusx; zz = plusz; break; case 5: xx = x; zz = plusz; break; case 6: xx = minusx; zz = plusz; break; case 7: xx = minusx; zz = z; break; default: xx = x; zz = z; break; } for (int yy = 0; yy < 4; yy++) { boolean change = true; if (yy == 0 && n == 9) { Block rail = world.getBlockAt(xx, y, zz); if (rail.getType().equals(Material.RAILS) || rail.getType().equals(Material.POWERED_RAIL)) { change = false; } } switch (colids[yy]) { case 2: case 3: int subi = (preset.equals(PRESET.SUBMERGED)) ? cham_id : colids[yy]; byte subd = (preset.equals(PRESET.SUBMERGED)) ? cham_data : coldatas[yy]; plugin.getUtils().setBlock(world, xx, (y + yy), zz, subi, subd); break; case 35: // wool int chai = (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) ? cham_id : colids[yy]; byte chad = (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) ? cham_data : coldatas[yy]; if (preset.equals(PRESET.PARTY) || (preset.equals(PRESET.FLOWER) && coldatas[yy] == 0)) { chad = the_colour; } plugin.getUtils().setBlock(world, xx, (y + yy), zz, chai, chad); break; case 38: break; case 50: // lamps, glowstone and torches case 89: case 124: int light = (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) ? lamp : colids[yy]; plugin.getUtils().setBlock(world, xx, (y + yy), zz, light, coldatas[yy]); break; case 64: case 68: // except the sign and doors case 71: break; case 95: if (coldatas[yy] == -1) { if (preset.equals(PRESET.PARTY) || (preset.equals(PRESET.FLOWER) && coldatas[yy] == 0)) { chad = the_colour; } else { // if it was a wool / stained glass / stained clay block get the data from that int[] finalids = column.getId()[n]; byte[] finaldatas = column.getData()[n]; if (finalids[yy] == 35 || finalids[yy] == 95 || finalids[yy] == 159 || finalids[yy] == 160 || finalids[yy] == 171) { if (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) { chad = cham_data; } else { chad = finaldatas[yy]; } } else { chad = plugin.getBuildKeeper().getStainedGlassLookup().getStain().get(cham_id); } } plugin.getUtils().setBlock(world, xx, (y + yy), zz, 95, chad); } else { plugin.getUtils().setBlock(world, xx, (y + yy), zz, colids[yy], coldatas[yy]); } break; default: // everything else if (change) { plugin.getUtils().setBlock(world, xx, (y + yy), zz, colids[yy], coldatas[yy]); } break; } } } } } else { plugin.getServer().getScheduler().cancelTask(task); task = 0; new TARDISDeinstaPreset(plugin).instaDestroyPreset(tmd, false, preset); } }