diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 8b192fb19..60a49fe01 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -258,34 +258,7 @@ public class FlatFile implements DataSource { @Override public void purgeRecords(Collection toPurge) { - BufferedReader br = null; - BufferedWriter bw = null; - ArrayList lines = new ArrayList<>(); - - try { - br = new BufferedReader(new FileReader(source)); - bw = new BufferedWriter(new FileWriter(source)); - String line; - while ((line = br.readLine()) != null) { - String[] args = line.split(":"); - if (args.length >= 4) { - if (toPurge.contains(args[0])) { - lines.add(line); - continue; - } - } - } - - for (String l : lines) { - bw.write(l + "\n"); - } - } catch (IOException ex) { - ConsoleLogger.warning(ex.getMessage()); - return; - } finally { - silentClose(br); - silentClose(bw); - } + throw new UnsupportedOperationException("Flat file no longer supported"); } @Override diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 6678c60a7..9a31c73cf 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -698,7 +698,7 @@ public class MySQL implements DataSource { String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { for (String name : toPurge) { - pst.setString(1, name); + pst.setString(1, name.toLowerCase()); pst.executeUpdate(); } } catch (SQLException ex) { diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index b8307ff6b..083195fa6 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -322,7 +322,7 @@ public class SQLite implements DataSource { String delete = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;"; try (PreparedStatement deletePst = con.prepareStatement(delete)) { for (String name : toPurge) { - deletePst.setString(1, name); + deletePst.setString(1, name.toLowerCase()); deletePst.executeUpdate(); } } catch (SQLException ex) { diff --git a/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java index b94748166..7fbccdd4a 100644 --- a/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/AbstractDataSourceIntegrationTest.java @@ -369,4 +369,17 @@ public abstract class AbstractDataSourceIntegrationTest { assertThat(dataSource.getLoggedPlayers(), empty()); } + @Test + public void shouldPerformPurgeOperation() { + // given + List names = Arrays.asList("Bobby", "USER", "DoesnotExist"); + DataSource dataSource = getDataSource(); + + // when + dataSource.purgeRecords(names); + + // then + assertThat(dataSource.getAllAuths(), empty()); + } + }