From 37f89728ff2523277a670564fe7741b569ad34a3 Mon Sep 17 00:00:00 2001 From: Daniel Boston Date: Sat, 23 Jan 2016 15:46:13 -0500 Subject: [PATCH] Adding soft deletion Signed-off-by: Daniel Boston --- .gitignore | 1 + config.yml | 1 + plugin.yml | 6 +- pom.xml | 3 +- .../JukeAlert/manager/ConfigManager.java | 6 ++ .../JukeAlert/storage/JukeAlertLogger.java | 61 ++++++++++++++----- 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 42ba098b..c3bc88a5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.jar !citadel.jar *~ +/target/ diff --git a/config.yml b/config.yml index d93bcc59..1d724edc 100644 --- a/config.yml +++ b/config.yml @@ -14,5 +14,6 @@ settings: allowTriggeringLevers: false togglerestartgroupcheck: false displayOwnerOnSnitchBreak: true + softDelete: true mercury: broadcastallservers: false \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 10319773..8ea60b36 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ -name: JukeAlert +name: ${project.name} main: com.untamedears.JukeAlert.JukeAlert -version: 1.3.5 +version: ${project.version} depend: [Citadel, NameLayer] softdepend: [vanishnopacket, ItemExchange, Mercury] description: JukeAlert provides an easy-to-use means by which one can record player activity within an 11 block radius. Anything someone does while within eleven blocks of a jukebox you've reinforced will be logged on it, and can be read by looking at the jukebox and typing '/jainfo'. @@ -66,4 +66,4 @@ permissions: default: true jukealert.vanish: description: Ability to avoid snitches. - default: op \ No newline at end of file + default: op diff --git a/pom.xml b/pom.xml index 6e374d5c..6c803497 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.untamedears JukeAlert jar - 1.3.63 + 1.3.7 JukeAlert https://github.com/Civcraft/JukeAlert/ @@ -28,6 +28,7 @@ *.yml LICENSE.txt + true diff --git a/src/com/untamedears/JukeAlert/manager/ConfigManager.java b/src/com/untamedears/JukeAlert/manager/ConfigManager.java index c67a2d22..fa9aad4d 100755 --- a/src/com/untamedears/JukeAlert/manager/ConfigManager.java +++ b/src/com/untamedears/JukeAlert/manager/ConfigManager.java @@ -42,6 +42,7 @@ public class ConfigManager private boolean enableInvisibility; private boolean toggleRestartCheckGroup; private boolean displayOwnerOnBreak; + private boolean softDelete; private boolean broadcastAllServers; @@ -114,6 +115,7 @@ private void load() enableInvisibility = loadBoolean("settings.enableinvisiblity", false); toggleRestartCheckGroup = loadBoolean("settings.togglerestartgroupcheck", false); displayOwnerOnBreak = loadBoolean("settings.displayOwnerOnSnitchBreak", true); + softDelete = loadBoolean("settings.softDelete", true); broadcastAllServers = loadBoolean("mercury.broadcastallservers", false); @@ -367,6 +369,10 @@ public boolean isDisplayOwnerOnBreak() { return displayOwnerOnBreak; } + public boolean isSoftDelete() { + return softDelete; + } + public boolean getToggleRestartCheckGroup(){ return toggleRestartCheckGroup; } diff --git a/src/com/untamedears/JukeAlert/storage/JukeAlertLogger.java b/src/com/untamedears/JukeAlert/storage/JukeAlertLogger.java index c32cd4ed..6949dfa5 100644 --- a/src/com/untamedears/JukeAlert/storage/JukeAlertLogger.java +++ b/src/com/untamedears/JukeAlert/storage/JukeAlertLogger.java @@ -62,9 +62,11 @@ public class JukeAlertLogger { private PreparedStatement getSnitchLogStmt; private PreparedStatement getSnitchLogGroupStmt; private PreparedStatement getSnitchListStmt; + private PreparedStatement softDeleteSnitchLogStmt; private PreparedStatement deleteSnitchLogStmt; private PreparedStatement insertSnitchLogStmt; private PreparedStatement insertNewSnitchStmt; + private PreparedStatement softDeleteSnitchStmt; private PreparedStatement deleteSnitchStmt; private PreparedStatement updateGroupStmt; private PreparedStatement updateCuboidVolumeStmt; @@ -87,6 +89,7 @@ public class JukeAlertLogger { private final int maxEntryLifetimeDays; private final int daysFromLastAdminVisitForLoggedSnitchCulling; private final int daysFromLastAdminVisitForNonLoggedSnitchCulling; + private final boolean softDelete; private final String host; private final String dbname; private final String username; @@ -113,6 +116,7 @@ public JukeAlertLogger() { daysFromLastAdminVisitForLoggedSnitchCulling = configManager.getDaysFromLastAdminVisitForLoggedSnitchCulling(); daysFromLastAdminVisitForNonLoggedSnitchCulling = configManager.getDaysFromLastAdminVisitForNonLoggedSnitchCulling(); + softDelete = configManager.isSoftDelete(); logsPerPage = configManager.getLogsPerPage(); snitchsTbl = prefix + "snitchs"; @@ -204,6 +208,9 @@ private void genTables() { db.silentExecute(String.format("UPDATE %s SET allow_triggering_lever = 0 WHERE allow_triggering_lever IS NULL;", snitchsTbl)); db.silentExecute(String.format("ALTER TABLE %s MODIFY COLUMN allow_triggering_lever bit NOT NULL;", snitchsTbl)); + db.silentExecute(String.format("ALTER TABLE %s ADD COLUMN (soft_delete BOOL NOT NULL DEFAULT 0);", snitchsTbl)); + db.silentExecute(String.format("ALTER TABLE %s ADD COLUMN (soft_delete BOOL NOT NULL DEFAULT 0);", snitchDetailsTbl)); + try { this.plugin.getLogger().log(Level.INFO, "Adding the log_hour column"); @@ -362,6 +369,7 @@ private void genTables() { + " {0} s \n" + " INNER JOIN GroupNames filter \n" + " ON filter.groupname = s.snitch_group \n" + + " WHERE s.soft_delete = 0 \n" + " ORDER BY CASE \n" + " WHEN \n" + " (s.snitch_should_log = 1 AND daysFromLastAdminVisitForLoggedSnitchCulling >= 1) \n" @@ -400,10 +408,10 @@ public PreparedStatement getNewUpdateSnitchSemiOwnerVisitStmt() { private void initializeStatements() { getAllSnitchesStmt = db.prepareStatement(String.format( - "SELECT * FROM %s", snitchsTbl)); + "SELECT * FROM %s WHERE soft_delete = 0", snitchsTbl)); getAllSnitchesByWorldStmt = db.prepareStatement(String.format( - "SELECT * FROM %s WHERE snitch_world = ?", snitchsTbl)); + "SELECT * FROM %s WHERE snitch_world = ? AND soft_delete = 0", snitchsTbl)); getLastSnitchID = db.prepareStatement(String.format( "SHOW TABLE STATUS LIKE '%s'", snitchsTbl)); @@ -412,13 +420,13 @@ private void initializeStatements() { // LIMIT ?,? means offset followed by max rows to return getSnitchLogStmt = db.prepareStatement(String.format( "SELECT * FROM %s" - + " WHERE snitch_id=? ORDER BY snitch_log_time DESC LIMIT ?,?", + + " WHERE snitch_id=? AND soft_delete = 0 ORDER BY snitch_log_time DESC LIMIT ?,?", snitchDetailsTbl)); getSnitchLogGroupStmt = db.prepareStatement(MessageFormat.format( "SELECT {0}.snitch_name, {1}.*" + " FROM {1} INNER JOIN {0} ON {0}.snitch_id = {1}.snitch_id" - + " WHERE {0}.snitch_group=? ORDER BY {1}.snitch_log_time DESC LIMIT ?,{2}", + + " WHERE {0}.snitch_group=? AND {0}.soft_delete = 0 AND {1}.soft_delete = 0 ORDER BY {1}.snitch_log_time DESC LIMIT ?,{2}", snitchsTbl, snitchDetailsTbl, logsPerPage)); getSnitchListStmt = db.prepareStatement(MessageFormat.format( @@ -429,7 +437,7 @@ private void initializeStatements() { // statement to get the ID of a snitch in the main snitchsTbl based on a Location (x,y,z, world) getSnitchIdFromLocationStmt = db.prepareStatement(String.format("SELECT snitch_id FROM %s" - + " WHERE snitch_x=? AND snitch_y=? AND snitch_z=? AND snitch_world=?", snitchsTbl)); + + " WHERE snitch_x=? AND snitch_y=? AND snitch_z=? AND snitch_world=? AND soft_delete = 0", snitchsTbl)); // statement to insert a log entry into the snitchesDetailsTable insertSnitchLogStmt = db.prepareStatement(String.format( @@ -449,11 +457,21 @@ private void initializeStatements() { "DELETE FROM %s WHERE snitch_id=?", snitchDetailsTbl)); + // + softDeleteSnitchLogStmt = db.prepareStatement(String.format( + "UPDATE %s SET soft_delete = 1 WHERE snitch_id=?", + snitchDetailsTbl)); + // deleteSnitchStmt = db.prepareStatement(String.format( "DELETE FROM %s WHERE snitch_world=? AND snitch_x=? AND snitch_y=? AND snitch_z=?", snitchsTbl)); + // + softDeleteSnitchStmt = db.prepareStatement(String.format( + "UPDATE %s SET soft_delete = 1 WHERE snitch_world=? AND snitch_x=? AND snitch_y=? AND snitch_z=?", + snitchsTbl)); + // updateGroupStmt = db.prepareStatement(String.format( "UPDATE %s SET snitch_group=? WHERE snitch_world=? AND snitch_x=? AND snitch_y=? AND snitch_z=?", @@ -485,7 +503,7 @@ private void initializeStatements() { // getAllSnitchIdsStmt = db.prepareStatement(String.format( - "SELECT snitch_id FROM %s;", snitchsTbl)); + "SELECT snitch_id FROM %s WHERE soft_delete = 0;", snitchsTbl)); // cullSnitchEntriesStmt = db.prepareStatement(MessageFormat.format( @@ -786,8 +804,13 @@ public Boolean deleteSnitchInfo(Location loc) { public Boolean deleteSnitchInfo(int snitchId) { try { - deleteSnitchLogStmt.setInt(1, snitchId); - deleteSnitchLogStmt.execute(); + if (this.softDelete) { + softDeleteSnitchLogStmt.setInt(1, snitchId); + softDeleteSnitchLogStmt.execute(); + } else { + deleteSnitchLogStmt.setInt(1, snitchId); + deleteSnitchLogStmt.execute(); + } return true; } catch (SQLException ex) { this.plugin.getLogger().log(Level.SEVERE, "Could not delete Snitch Details from the snitchesDetail table using the snitch id " + snitchId, ex); @@ -1077,12 +1100,22 @@ public void logSnitchBreak(final String world, final int x, final int y, final i public void run() { try { jukeinfobatch.flush(); - synchronized (deleteSnitchStmt) { - deleteSnitchStmt.setString(1, world); - deleteSnitchStmt.setInt(2, (int) Math.floor(x)); - deleteSnitchStmt.setInt(3, (int) Math.floor(y)); - deleteSnitchStmt.setInt(4, (int) Math.floor(z)); - deleteSnitchStmt.execute(); + if (softDelete) { + synchronized (softDeleteSnitchStmt) { + softDeleteSnitchStmt.setString(1, world); + softDeleteSnitchStmt.setInt(2, (int) Math.floor(x)); + softDeleteSnitchStmt.setInt(3, (int) Math.floor(y)); + softDeleteSnitchStmt.setInt(4, (int) Math.floor(z)); + softDeleteSnitchStmt.execute(); + } + } else { + synchronized (deleteSnitchStmt) { + deleteSnitchStmt.setString(1, world); + deleteSnitchStmt.setInt(2, (int) Math.floor(x)); + deleteSnitchStmt.setInt(3, (int) Math.floor(y)); + deleteSnitchStmt.setInt(4, (int) Math.floor(z)); + deleteSnitchStmt.execute(); + } } } catch (SQLException ex) { Logger.getLogger(JukeAlertLogger.class.getName()).log(Level.SEVERE, null, ex);