Ejemplo n.º 1
0
 public static void loadBlocks(Chunk chunk) {
   ResultSet r = null;
   try {
     r =
         (new SQLQuery(
                 "select l.world,l.x,l.y,l.z,b.dayPlaced,b.id from £.locations l, £.nonnatural b where l.id=b.location and l.chunkx="
                     + chunk.getX()
                     + " and l.chunkz="
                     + chunk.getZ()
                     + ";",
                 msqlc))
             .excecuteQuery();
   } catch (MySQLSyntaxErrorException e1) {
     e1.printStackTrace();
   }
   try {
     while (r.next()) {
       GregorianCalendar g = new GregorianCalendar();
       g.setTime(r.getDate(5));
       BlockManager.loadBlock(
           (new Location(Bukkit.getWorld(r.getString(1)), r.getInt(2), r.getInt(3), r.getInt(4)))
               .getBlock(),
           g,
           r.getInt(6));
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
 public static void saveBlocks(Chunk c) {
   Set<Entry<Location, PlacedBlock>> i = BlockManager.getPlacedBlocksIterator();
   for (Entry<Location, PlacedBlock> lpb : i) {
     PlacedBlock b = lpb.getValue();
     if (!b.getBlock().getChunk().equals(c)) return;
     if (b.isInDB()) {
       if (Utility.daysFromToday(b.getDayPlaced()) > 6) b.mark();
       if (b.isMarked()) {
         ResultSet r = null;
         try {
           r =
               (new SQLQuery(
                       "select location from £.nonnatural where id=" + b.getIdDB() + ";", msqlc))
                   .excecuteQuery();
         } catch (MySQLSyntaxErrorException e1) {
           e1.printStackTrace();
         }
         try {
           while (r.next()) {
             (new SQLQuery("delete from £.locations where id=" + r.getInt(1) + ";", msqlc))
                 .excecuteUpdate();
             (new SQLQuery("delete from £.nonnatural where id=" + b.getIdDB() + ";", msqlc))
                 .excecuteUpdate();
           }
         } catch (SQLException e) {
           e.printStackTrace();
         }
       }
     } else {
       Location l = b.getBlock().getLocation();
       String s =
           "insert into £.locations(world,chunkx,chunkz,x,y,z) values('"
               + l.getWorld().getName().toString()
               + "',"
               + c.getX()
               + ","
               + c.getZ()
               + ","
               + l.getBlockX()
               + ","
               + l.getBlockY()
               + ","
               + l.getBlockZ()
               + ");";
       (new SQLQuery(s, msqlc)).excecuteUpdate();
       ResultSet r = null;
       try {
         r = (new SQLQuery("select max(id) from £.locations;", msqlc)).excecuteQuery();
       } catch (MySQLSyntaxErrorException e1) {
         e1.printStackTrace();
       }
       try {
         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         while (r.next()) {
           (new SQLQuery(
                   "insert into £.nonnatural(location,dayPlaced) values("
                       + r.getInt(1)
                       + ",'"
                       + df.format(b.getDayPlaced().getTime())
                       + "');",
                   msqlc))
               .excecuteUpdate();
         }
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }