private Block getControlBlock(int id, int type) { Block b = null; HashMap<String, Object> where = new HashMap<String, Object>(); where.put("tardis_id", id); where.put("type", type); ResultSetControls rs = new ResultSetControls(plugin, where, false); if (rs.resultSet()) { Location l = plugin.getLocationUtils().getLocationFromBukkitString(rs.getLocation()); b = l.getBlock(); } return b; }
@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); } } } } }