Пример #1
0
  public static boolean isClaimed(Chunk chunk) {
    int chunkX = chunk.getX();
    int chunkZ = chunk.getZ();

    try {
      java.sql.PreparedStatement s =
          QuartzKingdoms.DBKing.prepareStatement("SELECT * FROM Chunks WHERE X=? AND Z=?;");
      s.setInt(1, chunk.getX());
      s.setInt(2, chunk.getZ());
      ResultSet res = s.executeQuery();
      if (res.next()) {
        return true;
      } else {
        return false;
      }
    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    }
  }
Пример #2
0
  public static Kingdom getKingdomOwner(Chunk chunk) {
    int chunkX = chunk.getX();
    int chunkZ = chunk.getZ();

    try {
      java.sql.PreparedStatement s =
          QuartzKingdoms.DBKing.prepareStatement("SELECT * FROM Chunks WHERE X=? AND Z=?;");
      s.setInt(1, chunk.getX());
      s.setInt(2, chunk.getZ());
      ResultSet res = s.executeQuery();
      if (res.next()) {
        int kingdomID = res.getInt("kingdom_id");
        return new Kingdom(kingdomID);
      } else {
        return null;
      }
    } catch (SQLException e) {
      e.printStackTrace();
      return null;
    }
  }
Пример #3
0
  public static boolean unClaimChunk(Kingdom kingdom, Player player) {
    Chunk chunk = player.getLocation().getChunk();

    if (isClaimed(chunk)) {
      try {
        java.sql.PreparedStatement s =
            QuartzKingdoms.DBKing.prepareStatement(
                "DELETE FROM Chunks WHERE X=? AND Z=? AND kingdom_id=?;");
        s.setInt(1, chunk.getX());
        s.setInt(2, chunk.getZ());
        s.setInt(3, kingdom.getID());
        s.executeUpdate();
        return true;
      } catch (SQLException e) {
        KUtil.printException("Failed to delete chunks from database", e);
        return false;
      }
    } else {
      return false;
    }
  }
Пример #4
0
  public static boolean claimChunk(Kingdom kingdom, Player player) {
    Chunk chunk = player.getLocation().getChunk();

    if (!isClaimed(chunk)) {
      // claim chunk
      try {
        java.sql.PreparedStatement s =
            QuartzKingdoms.DBKing.prepareStatement(
                "INSERT INTO Chunks (kingdom_id, X, Z) VALUES (?, ?, ?);");
        s.setInt(1, kingdom.getID());
        s.setInt(2, chunk.getX());
        s.setInt(3, chunk.getZ());
        s.executeUpdate();
        return true;
      } catch (SQLException e) {
        e.printStackTrace();
        return false;
      }
    } else {
      return false;
    }
  }