Added /fldelete <name> to delete profiles from storage (#1283)

* Added `/fldelete <name>` to delete profiles from storage by name

* Implemented requested changes for pull request #1283

* Update delete command's perm default
This commit is contained in:
tbm00
2025-05-26 14:51:21 +02:00
committed by GitHub
parent 063b6a9405
commit 2308d98dcd
5 changed files with 128 additions and 0 deletions
@@ -32,6 +32,8 @@ public interface AuthStorage {
StoredProfile loadProfile(UUID uuid);
int deleteProfile(String name);
void save(StoredProfile playerProfile);
void close();
@@ -65,6 +65,8 @@ public abstract class SQLStorage implements AuthStorage {
+ "` WHERE `Name`=? LIMIT 1";
protected static final String LOAD_BY_UUID = "SELECT * FROM `" + PREMIUM_TABLE
+ "` WHERE `UUID`=? LIMIT 1";
protected static final String DELETE_BY_NAME = "DELETE FROM " + PREMIUM_TABLE
+ " WHERE `Name` = ?";
protected static final String INSERT_PROFILE = "INSERT INTO `" + PREMIUM_TABLE
+ "` (`UUID`, `Name`, `Premium`, `Floodgate`, `LastIp`) " + "VALUES (?, ?, ?, ?, ?) ";
// limit not necessary here, because it's unique
@@ -143,6 +145,25 @@ public abstract class SQLStorage implements AuthStorage {
return null;
}
@Override
public int deleteProfile(String name) {
try (Connection con = dataSource.getConnection();
PreparedStatement deleteStmt = con.prepareStatement(DELETE_BY_NAME)) {
deleteStmt.setString(1, name);
int rowsDeleted = deleteStmt.executeUpdate();
if (rowsDeleted > 0) {
log.info("Deleted {}'s profile data", name);
} else {
log.info("No profile data found for {}", name);
}
return rowsDeleted;
} catch (SQLException sqlEx) {
log.error("Failed to query profile: {}", name, sqlEx);
return 0;
}
}
private Optional<StoredProfile> parseResult(ResultSet resultSet) throws SQLException {
if (resultSet.next()) {
long userId = resultSet.getInt("UserID");