예제 #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;
  }
예제 #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);
   }
 }
예제 #3
0
 @Override
 public void drop() {
   BBLogging.info("Dropping table " + getTableName());
   BBDB.executeUpdate("DROP TABLE IF EXISTS " + getTableName());
   createTable();
   getInstance().knownPlayers.clear();
   getInstance().knownNames.clear();
 }
예제 #4
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;
 }
예제 #5
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();
 }
예제 #6
0
 public static BBUsersTable getInstance() {
   if (instance == null) {
     BBLogging.debug("BBDB.dbms=" + BBDB.dbms.toString());
     if (BBDB.usingDBMS(DBMS.POSTGRES)) {
       instance = new BBUsersPostgreSQL();
     } else {
       instance = new BBUsersMySQL();
     }
     instance.loadCache();
   }
   return instance;
 }
예제 #7
0
  public BBUsersTable() {
    if (BBDB.needsUpdate(BBSettings.dataFolder, getActualTableName(), VERSION)) {
      drop();
    }
    if (!tableExists()) {
      BBLogging.info("Building `" + getTableName() + "` table...");
      createTable();
    } else {
      BBLogging.debug("`" + getTableName() + "` table already exists");
    }

    onLoad();
  }
예제 #8
0
 /*
  * (non-Javadoc)
  *
  * @see me.taylorkelly.bigbrother.tablemgrs.OwnersTable#removeBlockOwner(int, int, int, int)
  */
 @Override
 protected void removeBlockOwner(int wldID, int x, int y, int z) {
   BBDB.executeUpdate(
       "DELETE FROM " + getTableName() + " WHERE wldID=? AND x=? AND y=? AND z=?", wldID, x, y, z);
 }