private String estimateArtron(String size, String cham) {
   SCHEMATIC s = SCHEMATIC.valueOf(size);
   String[] data = cham.split(":");
   int x = plugin.getUtils().parseInt(data[1]);
   int y = plugin.getUtils().parseInt(data[2]);
   int z = plugin.getUtils().parseInt(data[3]);
   switch (s) {
     case DELUXE:
       return data[0] + ":" + (x + 5) + ":" + y + ":" + (z - 1);
     default:
       return data[0] + ":" + (x - 2) + ":" + y + ":" + (z + 2);
   }
 }
 public boolean eject(Player player) {
   if (!player.hasPermission("tardis.eject")) {
     TARDISMessage.send(player, "NO_PERMS");
     return true;
   }
   // check they are still in the TARDIS world
   if (!plugin.getUtils().inTARDISWorld(player)) {
     TARDISMessage.send(player, "CMD_IN_WORLD");
     return true;
   }
   // must have a TARDIS
   ResultSetTardisID rs = new ResultSetTardisID(plugin);
   if (!rs.fromUUID(player.getUniqueId().toString())) {
     TARDISMessage.send(player, "NOT_A_TIMELORD");
     return false;
   }
   int ownerid = rs.getTardis_id();
   HashMap<String, Object> wheret = new HashMap<String, Object>();
   wheret.put("uuid", player.getUniqueId().toString());
   ResultSetTravellers rst = new ResultSetTravellers(plugin, wheret, false);
   if (!rst.resultSet()) {
     TARDISMessage.send(player, "NOT_IN_TARDIS");
     return false;
   }
   int thisid = rst.getTardis_id();
   // must be timelord of the TARDIS
   if (thisid != ownerid) {
     TARDISMessage.send(player, "CMD_ONLY_TL");
     return false;
   }
   // track the player
   plugin.getTrackerKeeper().getEjecting().put(player.getUniqueId(), thisid);
   return true;
 }
 /**
  * Retrieves an SQL ResultSet from the destinations table. This method builds an SQL query string
  * from the parameters supplied and then executes the query. Use the getters to retrieve the
  * results.
  *
  * @return true or false depending on whether any data matches the query
  */
 public boolean resultSet() {
   PreparedStatement statement = null;
   ResultSet rs = null;
   String wheres = "";
   if (where != null) {
     StringBuilder sbw = new StringBuilder();
     for (Map.Entry<String, Object> entry : where.entrySet()) {
       sbw.append(entry.getKey()).append(" = ? AND ");
     }
     wheres = " WHERE " + sbw.toString().substring(0, sbw.length() - 5);
   }
   String query = "SELECT * FROM next" + wheres;
   try {
     service.testConnection(connection);
     statement = connection.prepareStatement(query);
     if (where != null) {
       int s = 1;
       for (Map.Entry<String, Object> entry : where.entrySet()) {
         if (entry.getValue().getClass().equals(String.class)) {
           statement.setString(s, entry.getValue().toString());
         } else {
           statement.setInt(s, plugin.getUtils().parseInt(entry.getValue().toString()));
         }
         s++;
       }
       where.clear();
     }
     rs = statement.executeQuery();
     if (rs.isBeforeFirst()) {
       while (rs.next()) {
         this.next_id = rs.getInt("next_id");
         this.tardis_id = rs.getInt("tardis_id");
         this.world = plugin.getServer().getWorld(rs.getString("world"));
         this.x = rs.getInt("x");
         this.y = rs.getInt("y");
         this.z = rs.getInt("z");
         this.direction = COMPASS.valueOf(rs.getString("direction"));
         this.submarine = rs.getBoolean("submarine");
       }
     } else {
       return false;
     }
   } catch (SQLException e) {
     plugin.debug("ResultSet error for destinations table! " + e.getMessage());
     return false;
   } finally {
     try {
       if (rs != null) {
         rs.close();
       }
       if (statement != null) {
         statement.close();
       }
     } catch (SQLException e) {
       plugin.debug("Error closing destinations table! " + e.getMessage());
     }
   }
   return this.world != null;
 }
 private String[] estimateRepeaters(String size, String cham) {
   String[] r = new String[4];
   SCHEMATIC s = SCHEMATIC.valueOf(size);
   String[] data = cham.split(":");
   int x = plugin.getUtils().parseInt(data[1]);
   int y = plugin.getUtils().parseInt(data[2]);
   int z = plugin.getUtils().parseInt(data[3]);
   switch (s) {
     case DELUXE:
       r[0] = data[0] + ":" + (x + 2) + ":" + (y + 1) + ":" + (z - 3); // environment
       r[1] = data[0] + ":" + x + ":" + (y + 1) + ":" + (z - 1); // x
       r[2] = data[0] + ":" + (x + 4) + ":" + (y + 1) + ":" + (z - 1); // z
       r[3] = data[0] + ":" + (x + 2) + ":" + (y + 1) + ":" + (z + 1); // y
       break;
     default:
       r[0] = data[0] + ":" + (x - 1) + ":" + y + ":" + (z - 1);
       r[1] = data[0] + ":" + (x - 3) + ":" + y + ":" + (z + 1);
       r[2] = data[0] + ":" + (x + 1) + ":" + y + ":" + (z + 1);
       r[3] = data[0] + ":" + (x - 1) + ":" + y + ":" + (z + 3);
       break;
   }
   return r;
 }
 @SuppressWarnings("deprecation")
 private byte getWoolColour(int id, PRESET p) {
   HashMap<String, Object> where = new HashMap<String, Object>();
   where.put("tardis_id", id);
   where.put("door_type", 0);
   ResultSetDoors rs = new ResultSetDoors(plugin, where, false);
   if (rs.resultSet()) {
     Block b = plugin.getUtils().getLocationFromDB(rs.getDoor_location(), 0.0F, 0.0F).getBlock();
     if (p.equals(PRESET.FLOWER)) {
       return b.getRelative(BlockFace.UP, 3).getData();
     } else {
       for (BlockFace f : plugin.getGeneralKeeper().getFaces()) {
         if (b.getRelative(f).getType().equals(Material.WOOL)) {
           return b.getRelative(f).getData();
         }
       }
     }
   }
   return (byte) 0;
 }
 /** Convert pre-TARDIS v2.3 controls to the new system. */
 public void convertControls() {
   ResultSetTardis rs = new ResultSetTardis(plugin, null, "", true);
   if (rs.resultSet()) {
     int i = 0;
     ArrayList<HashMap<String, String>> data = rs.getData();
     Statement del = null;
     PreparedStatement ps = null;
     try {
       service.testConnection(connection);
       // clear the controls table first - just incase they have reset `conversion_done` in the
       // config
       del = connection.createStatement();
       del.executeUpdate("DELETE FROM controls");
       // insert values from tardis table
       ps =
           connection.prepareStatement(
               "INSERT INTO controls (tardis_id, type, location) VALUES (?,?,?)");
       for (HashMap<String, String> map : data) {
         int id = plugin.getUtils().parseInt(map.get("tardis_id"));
         String tmph;
         if (map.get("handbrake") == null || map.get("handbrake").isEmpty()) {
           tmph = estimateHandbrake(map.get("size"), map.get("chameleon"));
           plugin
               .getConsole()
               .sendMessage(
                   plugin.getPluginName()
                       + ChatColor.RED
                       + "Handbrake location not found, making an educated guess...");
         } else {
           tmph = map.get("handbrake");
         }
         String tmpb;
         if (map.get("button") == null || map.get("button").isEmpty()) {
           tmpb = estimateButton(map.get("size"), map.get("chameleon"));
           plugin
               .getConsole()
               .sendMessage(
                   plugin.getPluginName()
                       + ChatColor.RED
                       + "Button location not found, making an educated guess...");
         } else {
           tmpb = map.get("button");
         }
         String tmpa;
         if (map.get("artron_button") == null || map.get("artron_button").isEmpty()) {
           tmpa = estimateArtron(map.get("size"), map.get("chameleon"));
           plugin
               .getConsole()
               .sendMessage(
                   plugin.getPluginName()
                       + ChatColor.RED
                       + "Artron Button location not found, making an educated guess...");
         } else {
           tmpa = map.get("artron_button");
         }
         String[] tmpr = new String[4];
         if (map.get("repeater0") == null || map.get("repeater0").isEmpty()) {
           tmpr = estimateRepeaters(map.get("size"), map.get("chameleon"));
           plugin
               .getConsole()
               .sendMessage(
                   plugin.getPluginName()
                       + ChatColor.RED
                       + "Repeater locations not found, making an educated guess...");
         } else {
           tmpr[0] = map.get("repeater0");
           tmpr[1] = map.get("repeater1");
           tmpr[2] = map.get("repeater2");
           tmpr[3] = map.get("repeater3");
         }
         String hb = plugin.getUtils().makeLocationStr(tmph);
         String bn = plugin.getUtils().makeLocationStr(tmpb);
         String ab = plugin.getUtils().makeLocationStr(tmpa);
         ps.setInt(1, id);
         ps.setInt(2, 0);
         ps.setString(3, hb);
         ps.addBatch();
         ps.setInt(1, id);
         ps.setInt(2, 1);
         ps.setString(3, bn);
         ps.addBatch();
         ps.setInt(1, id);
         ps.setInt(2, 2);
         ps.setString(3, tmpr[0]);
         ps.addBatch();
         ps.setInt(1, id);
         ps.setInt(2, 3);
         ps.setString(3, tmpr[1]);
         ps.addBatch();
         ps.setInt(1, id);
         ps.setInt(2, 4);
         ps.setString(3, tmpr[2]);
         ps.addBatch();
         ps.setInt(1, id);
         ps.setInt(2, 5);
         ps.setString(3, tmpr[3]);
         ps.addBatch();
         ps.setInt(1, id);
         ps.setInt(2, 6);
         ps.setString(3, ab);
         ps.addBatch();
         connection.setAutoCommit(false);
         ps.executeBatch();
         connection.setAutoCommit(true);
         i++;
       }
     } catch (SQLException e) {
       plugin.debug("Control conversion error: " + e.getMessage());
     } finally {
       if (del != null) {
         try {
           del.close();
         } catch (SQLException e) {
           plugin.debug("Control delete statement close error: " + e.getMessage());
         }
       }
       if (ps != null) {
         try {
           ps.close();
         } catch (SQLException e) {
           plugin.debug("Control prepared statement close error: " + e.getMessage());
         }
       }
     }
     if (i > 0) {
       plugin
           .getConsole()
           .sendMessage(plugin.getPluginName() + "Converted " + i + " control consoles");
       plugin.getConfig().set("conversions.conversion_done", true);
       plugin.saveConfig();
     }
   }
 }
示例#7
0
 public void flickSwitch(UUID uuid, boolean on) {
   HashMap<String, Object> whereb = new HashMap<String, Object>();
   whereb.put("uuid", uuid.toString());
   ResultSetTardis rs = new ResultSetTardis(plugin, whereb, "", false);
   if (rs.resultSet()) {
     SCHEMATIC schm = rs.getSchematic();
     if (no_beacon.contains(schm)) {
       // doesn't have a beacon!
       return;
     }
     // toggle beacon
     String beacon = rs.getBeacon();
     String[] beaconData;
     int plusy = 0;
     if (beacon.isEmpty()) {
       // get the location from the TARDIS size and the creeper location
       switch (schm) {
         case REDSTONE:
           plusy = 14;
           break;
         case ELEVENTH:
           plusy = 22;
           break;
         case DELUXE:
           plusy = 23;
           break;
         case BIGGER:
         case ARS:
           plusy = 12;
           break;
         default: // BUDGET, STEAMPUNK, WAR, CUSTOM?
           plusy = 11;
           break;
       }
       String creeper = rs.getCreeper();
       beaconData = creeper.split(":");
     } else {
       beaconData = beacon.split(":");
     }
     World w = plugin.getServer().getWorld(beaconData[0]);
     boolean stuffed = (beaconData[1].contains(".5"));
     int bx, bz;
     // get rid of decimal places due to incorrectly copied values from creeper field...
     if (stuffed) {
       bx = (int) plugin.getUtils().parseFloat(beaconData[1]) * 1;
       bz = (int) plugin.getUtils().parseFloat(beaconData[3]) * 1;
     } else {
       bx = plugin.getUtils().parseInt(beaconData[1]);
       bz = plugin.getUtils().parseInt(beaconData[3]);
     }
     int by = (int) plugin.getUtils().parseFloat(beaconData[2]) * 1 + plusy;
     if (beacon.isEmpty() || stuffed) {
       // update the tardis table so we don't have to do this again
       String beacon_loc = beaconData[0] + ":" + bx + ":" + by + ":" + bz;
       HashMap<String, Object> set = new HashMap<String, Object>();
       set.put("beacon", beacon_loc);
       HashMap<String, Object> where = new HashMap<String, Object>();
       where.put("tardis_id", rs.getTardis_id());
       new QueryFactory(plugin).doUpdate("tardis", set, where);
     }
     Location bl = new Location(w, bx, by, bz);
     Block b = bl.getBlock();
     while (!b.getChunk().isLoaded()) {
       b.getChunk().load();
     }
     b.setType((on) ? Material.GLASS : Material.BEDROCK);
   }
 }
 @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);
   }
 }
 @SuppressWarnings("deprecation")
 public boolean doRemoteComeHere(Player player, UUID uuid) {
   Location eyeLocation =
       player.getTargetBlock(plugin.getGeneralKeeper().getTransparent(), 50).getLocation();
   if (!plugin.getConfig().getBoolean("travel.include_default_world")
       && plugin.getConfig().getBoolean("creation.default_world")
       && eyeLocation
           .getWorld()
           .getName()
           .equals(plugin.getConfig().getString("creation.default_world_name"))) {
     TARDISMessage.send(player, "NO_WORLD_TRAVEL");
     return true;
   }
   if (!plugin
       .getPluginRespect()
       .getRespect(eyeLocation, new Parameters(player, FLAG.getDefaultFlags()))) {
     return true;
   }
   if (!plugin.getTardisArea().areaCheckInExisting(eyeLocation)) {
     TARDISMessage.send(
         player,
         "AREA_NO_COMEHERE",
         ChatColor.AQUA + "/tardisremote [player] travel area [area name]");
     return true;
   }
   Material m = player.getTargetBlock(plugin.getGeneralKeeper().getTransparent(), 50).getType();
   if (m != Material.SNOW) {
     int yplusone = eyeLocation.getBlockY();
     eyeLocation.setY(yplusone + 1);
   }
   // check the world is not excluded
   String world = eyeLocation.getWorld().getName();
   if (!plugin.getConfig().getBoolean("worlds." + world)) {
     TARDISMessage.send(player, "NO_PB_IN_WORLD");
     return true;
   }
   // check the remote player is a Time Lord
   HashMap<String, Object> where = new HashMap<String, Object>();
   where.put("uuid", uuid.toString());
   ResultSetTardis rs = new ResultSetTardis(plugin, where, "", false, 0);
   if (!rs.resultSet()) {
     TARDISMessage.send(player, "PLAYER_NO_TARDIS");
     return true;
   }
   Tardis tardis = rs.getTardis();
   final int id = tardis.getTardis_id();
   // check they are not in the tardis
   HashMap<String, Object> wherettrav = new HashMap<String, Object>();
   wherettrav.put("uuid", player.getUniqueId().toString());
   wherettrav.put("tardis_id", id);
   ResultSetTravellers rst = new ResultSetTravellers(plugin, wherettrav, false);
   if (rst.resultSet()) {
     TARDISMessage.send(player, "NO_PB_IN_TARDIS");
     return true;
   }
   if (plugin.getTrackerKeeper().getInVortex().contains(id)) {
     TARDISMessage.send(player, "NOT_WHILE_MAT");
     return true;
   }
   boolean chamtmp = false;
   if (plugin.getConfig().getBoolean("travel.chameleon")) {
     chamtmp = tardis.isChamele_on();
   }
   boolean hidden = tardis.isHidden();
   // get current police box location
   HashMap<String, Object> wherecl = new HashMap<String, Object>();
   wherecl.put("tardis_id", id);
   ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl);
   if (!rsc.resultSet()) {
     hidden = true;
   }
   COMPASS d = rsc.getDirection();
   COMPASS player_d = COMPASS.valueOf(TARDISStaticUtils.getPlayersDirection(player, false));
   Biome biome = rsc.getBiome();
   TARDISTimeTravel tt = new TARDISTimeTravel(plugin);
   int count;
   boolean sub = false;
   Block b = eyeLocation.getBlock();
   if (b.getRelative(BlockFace.UP).getType().equals(Material.WATER)
       || b.getRelative(BlockFace.UP).getType().equals(Material.STATIONARY_WATER)) {
     count = (tt.isSafeSubmarine(eyeLocation, player_d)) ? 0 : 1;
     if (count == 0) {
       sub = true;
     }
   } else {
     int[] start_loc = tt.getStartLocation(eyeLocation, player_d);
     // safeLocation(int startx, int starty, int startz, int resetx, int resetz, World w, COMPASS
     // player_d)
     count =
         tt.safeLocation(
             start_loc[0],
             eyeLocation.getBlockY(),
             start_loc[2],
             start_loc[1],
             start_loc[3],
             eyeLocation.getWorld(),
             player_d);
   }
   if (plugin.getPM().isPluginEnabled("Lockette")) {
     Lockette Lockette = (Lockette) plugin.getPM().getPlugin("Lockette");
     if (Lockette.isProtected(eyeLocation.getBlock())) {
       count = 1;
     }
   }
   if (count > 0) {
     TARDISMessage.send(player, "WOULD_GRIEF_BLOCKS");
     return true;
   }
   boolean cham = chamtmp;
   final QueryFactory qf = new QueryFactory(plugin);
   Location oldSave = null;
   HashMap<String, Object> bid = new HashMap<String, Object>();
   bid.put("tardis_id", id);
   HashMap<String, Object> bset = new HashMap<String, Object>();
   if (rsc.getWorld() != null) {
     oldSave = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ());
     // set fast return location
     bset.put("world", rsc.getWorld().getName());
     bset.put("x", rsc.getX());
     bset.put("y", rsc.getY());
     bset.put("z", rsc.getZ());
     bset.put("direction", d.toString());
     bset.put("submarine", rsc.isSubmarine());
   } else {
     // set fast return location
     bset.put("world", eyeLocation.getWorld().getName());
     bset.put("x", eyeLocation.getX());
     bset.put("y", eyeLocation.getY());
     bset.put("z", eyeLocation.getZ());
     bset.put("submarine", (sub) ? 1 : 0);
   }
   qf.doUpdate("back", bset, bid);
   HashMap<String, Object> tid = new HashMap<String, Object>();
   tid.put("tardis_id", id);
   HashMap<String, Object> set = new HashMap<String, Object>();
   set.put("world", eyeLocation.getWorld().getName());
   set.put("x", eyeLocation.getBlockX());
   set.put("y", eyeLocation.getBlockY());
   set.put("z", eyeLocation.getBlockZ());
   set.put("direction", player_d.toString());
   set.put("submarine", (sub) ? 1 : 0);
   if (hidden) {
     HashMap<String, Object> sett = new HashMap<String, Object>();
     sett.put("hidden", 0);
     HashMap<String, Object> ttid = new HashMap<String, Object>();
     ttid.put("tardis_id", id);
     qf.doUpdate("tardis", sett, ttid);
     // restore biome
     plugin.getUtils().restoreBiome(oldSave, biome);
   }
   qf.doUpdate("current", set, tid);
   TARDISMessage.send(player, "TARDIS_COMING");
   //        boolean mat = plugin.getConfig().getBoolean("police_box.materialise");
   //        long delay = (mat) ? 1L : 180L;
   long delay = 1L;
   plugin.getTrackerKeeper().getInVortex().add(id);
   final boolean hid = hidden;
   if (!plugin.getTrackerKeeper().getDestinationVortex().containsKey(id)) {
     final DestroyData dd = new DestroyData(plugin, player.getUniqueId().toString());
     dd.setChameleon(cham);
     dd.setDirection(d);
     dd.setLocation(oldSave);
     dd.setPlayer(player);
     dd.setHide(false);
     dd.setOutside(true);
     dd.setSubmarine(rsc.isSubmarine());
     dd.setTardisID(id);
     dd.setBiome(biome);
     plugin
         .getServer()
         .getScheduler()
         .scheduleSyncDelayedTask(
             plugin,
             new Runnable() {
               @Override
               public void run() {
                 if (!hid) {
                   plugin.getTrackerKeeper().getDematerialising().add(id);
                   plugin.getPresetDestroyer().destroyPreset(dd);
                 } else {
                   plugin.getPresetDestroyer().removeBlockProtection(id, qf);
                 }
               }
             },
             delay);
   }
   final BuildData bd = new BuildData(plugin, player.getUniqueId().toString());
   bd.setChameleon(cham);
   bd.setDirection(player_d);
   bd.setLocation(eyeLocation);
   bd.setMalfunction(false);
   bd.setOutside(true);
   bd.setPlayer(player);
   bd.setRebuild(false);
   bd.setSubmarine(sub);
   bd.setTardisID(id);
   plugin
       .getServer()
       .getScheduler()
       .scheduleSyncDelayedTask(
           plugin,
           new Runnable() {
             @Override
             public void run() {
               plugin.getPresetBuilder().buildPreset(bd);
             }
           },
           delay * 2);
   plugin.getTrackerKeeper().getHasDestination().remove(id);
   if (plugin.getTrackerKeeper().getRescue().containsKey(id)) {
     plugin.getTrackerKeeper().getRescue().remove(id);
   }
   return true;
 }
示例#10
0
 /**
  * Retrieves an SQL ResultSet from the controls table. This method builds an SQL query string from
  * the parameters supplied and then executes the query. Use the getters to retrieve the results.
  *
  * @return true or false depending on whether any data matches the query
  */
 public boolean resultSet() {
   PreparedStatement statement = null;
   ResultSet rs = null;
   String wheres = "";
   if (where != null) {
     StringBuilder sbw = new StringBuilder();
     for (Map.Entry<String, Object> entry : where.entrySet()) {
       sbw.append(entry.getKey()).append(" = ? AND ");
     }
     wheres = " WHERE " + sbw.toString().substring(0, sbw.length() - 5);
   }
   String query = "SELECT * FROM controls" + wheres;
   try {
     service.testConnection(connection);
     statement = connection.prepareStatement(query);
     if (where != null) {
       int s = 1;
       for (Map.Entry<String, Object> entry : where.entrySet()) {
         if (entry.getValue().getClass().equals(String.class)) {
           statement.setString(s, entry.getValue().toString());
         } else {
           statement.setInt(s, plugin.getUtils().parseInt(entry.getValue().toString()));
         }
         s++;
       }
       where.clear();
     }
     rs = statement.executeQuery();
     if (rs.isBeforeFirst()) {
       while (rs.next()) {
         if (multiple) {
           HashMap<String, String> row = new HashMap<String, String>();
           ResultSetMetaData rsmd = rs.getMetaData();
           int columns = rsmd.getColumnCount();
           for (int i = 1; i < columns + 1; i++) {
             row.put(rsmd.getColumnName(i).toLowerCase(Locale.ENGLISH), rs.getString(i));
           }
           data.add(row);
         }
         this.c_id = rs.getInt("c_id");
         this.tardis_id = rs.getInt("tardis_id");
         this.type = rs.getInt("type");
         this.location = rs.getString("location");
         this.secondary = rs.getInt("secondary");
       }
     } else {
       return false;
     }
   } catch (SQLException e) {
     plugin.debug("ResultSet error for controls table! " + e.getMessage());
     return false;
   } finally {
     try {
       if (rs != null) {
         rs.close();
       }
       if (statement != null) {
         statement.close();
       }
     } catch (SQLException e) {
       plugin.debug("Error closing controls table! " + e.getMessage());
     }
   }
   return true;
 }