Exemplo n.º 1
0
  @Override
  public ArrayList<Action> getBlockHistory(Block block, WorldManager manager) {
    PreparedStatement ps = null;
    ResultSet rs = null;
    ArrayList<Action> blockList = new ArrayList<Action>();

    try {
      // TODO maybe more customizable actions?
      ps =
          BBDB.prepare(
              "SELECT  bbdata.id, date, player, action, x, y, z, type, data, rbacked, bbworlds.name AS world"
                  + " FROM "
                  + BBDataTable.getInstance().getTableName()
                  + " AS bbdata"
                  + " INNER JOIN "
                  + BBWorldsTable.getInstance().getTableName()
                  + " AS bbworlds"
                  + " ON bbworlds.id = bbdata.world"
                  + " WHERE rbacked = false AND x = ? AND y = ? AND z = ? AND bbdata.world = ? ORDER BY bbdata.id ASC;");

      ps.setInt(1, block.getX());
      ps.setInt(2, block.getY());
      ps.setInt(3, block.getZ());
      ps.setInt(4, manager.getWorld(block.getWorld().getName()));
      rs = ps.executeQuery();
      BBDB.commit();

      while (rs.next()) {
        String data = rs.getString("data");
        Action newBlock =
            ActionProvider.findAndProvide(
                rs.getInt("action"),
                BBUsersTable.getInstance().getUserByID(rs.getInt("player")),
                rs.getString("world"),
                rs.getInt("x"),
                rs.getInt("y"),
                rs.getInt("z"),
                rs.getInt("type"),
                data);
        newBlock.date = rs.getLong("date");
        blockList.add(newBlock);
      }
    } catch (SQLException ex) {
      BBLogging.severe("Find SQL Exception", ex);
    } finally {
      BBDB.cleanup("Find", ps, rs);
    }
    return blockList;
  }
Exemplo n.º 2
0
 protected void setBlockOwnerInsert(int world, int x, int y, int z, int playerID) {
   PreparedStatement stmt = null;
   try {
     stmt =
         BBDB.prepare("INSERT INTO " + getTableName() + " (wldID,x,y,z,usrID) VALUES (?,?,?,?,?)");
     stmt.setInt(1, world);
     stmt.setInt(2, x);
     stmt.setInt(3, y);
     stmt.setInt(4, z);
     stmt.setInt(5, playerID);
     stmt.execute();
   } catch (SQLException e) {
     BBLogging.severe("Error when performing setBlockOwner in OwnersPostgreSQL: ", e);
   } finally {
     BBDB.cleanup("OwnersPostgreSQL.setBlockOwner", stmt, null);
   }
 }
Exemplo n.º 3
0
 protected boolean trySetBlockOwnerUpdate(int world, int x, int y, int z, int playerID) {
   PreparedStatement stmt = null;
   try {
     stmt =
         BBDB.prepare(
             "UPDATE " + getTableName() + " SET usrID=? WHERE wldID=? AND x=? AND y=? AND z=?");
     stmt.setInt(1, playerID);
     stmt.setInt(2, world);
     stmt.setInt(3, x);
     stmt.setInt(4, y);
     stmt.setInt(5, z);
     return stmt.execute();
   } catch (SQLException e) {
     BBLogging.severe("Error when performing setBlockOwner in OwnersPostgreSQL: ", e);
   } finally {
     BBDB.cleanup("OwnersPostgreSQL.setBlockOwner", stmt, null);
   }
   return false;
 }
Exemplo n.º 4
0
 /*
  * (non-Javadoc)
  *
  * @see me.taylorkelly.bigbrother.tablemgrs.OwnersTable#getBlockOwner(int, int, int, int)
  */
 @Override
 protected int getBlockOwner(int world, int x, int y, int z) {
   PreparedStatement stmt = null;
   ResultSet rs = null;
   try {
     stmt =
         BBDB.prepare(
             "SELECT usrID FROM " + getTableName() + " WHERE wldID=? AND x=? AND y=? AND z=?");
     stmt.setInt(1, world);
     stmt.setInt(2, x);
     stmt.setInt(3, y);
     stmt.setInt(4, z);
     rs = stmt.executeQuery();
     if (rs.next()) return rs.getInt("usrID");
   } catch (SQLException e) {
     BBLogging.severe("Error when performing setBlockOwner in OwnersPostgreSQL: ", e);
   } finally {
     BBDB.cleanup("OwnersPostgreSQL.setBlockOwner", stmt, rs);
   }
   return BBPlayerInfo.ENVIRONMENT.getID();
 }