mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Implemented economy log cleanup (#156)
This commit is contained in:
parent
372124b04e
commit
cfff0b9ce2
@ -170,6 +170,13 @@ public class Config {
|
||||
**/
|
||||
public static boolean enableWorldGuardIntegration;
|
||||
|
||||
/**
|
||||
* <p>Sets the time limit for cleaning up the economy log in days</p>
|
||||
*
|
||||
* If this equals to {@code 0}, the economy log will not be cleaned.
|
||||
**/
|
||||
public static int cleanupEconomyLogDays;
|
||||
|
||||
/**
|
||||
* Whether Towny integration should be enabled
|
||||
**/
|
||||
@ -478,6 +485,7 @@ public class Config {
|
||||
enableHologramInteraction = plugin.getConfig().getBoolean("enable-hologram-interaction");
|
||||
enableDebugLog = plugin.getConfig().getBoolean("enable-debug-log");
|
||||
enableEcomomyLog = plugin.getConfig().getBoolean("enable-economy-log");
|
||||
cleanupEconomyLogDays = plugin.getConfig().getInt("cleanup-ecomomy-log-days");
|
||||
enableWorldGuardIntegration = plugin.getConfig().getBoolean("enable-worldguard-integration");
|
||||
enableTownyIntegration = plugin.getConfig().getBoolean("enable-towny-integration");
|
||||
enableAuthMeIntegration = plugin.getConfig().getBoolean("enable-authme-integration");
|
||||
|
@ -155,6 +155,11 @@ public abstract class Database {
|
||||
s4.executeUpdate(queryCreateTablePlayerLogout);
|
||||
s4.close();
|
||||
|
||||
// Clean up economy log
|
||||
if (Config.cleanupEconomyLogDays > 0) {
|
||||
cleanUpEconomy(false);
|
||||
}
|
||||
|
||||
// Count entries in table "shops"
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT * FROM shops");
|
||||
ResultSet rs2 = ps.executeQuery();
|
||||
@ -424,6 +429,52 @@ public abstract class Database {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the economy log to reduce file size
|
||||
* @param async Whether the call should be executed asynchronously
|
||||
*/
|
||||
public void cleanUpEconomy(boolean async) {
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Statement s = null;
|
||||
Statement s2 = null;
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
long time = System.currentTimeMillis();
|
||||
cal.add(Calendar.DATE, -Config.cleanupEconomyLogDays);
|
||||
time -= Config.cleanupEconomyLogDays * 86400000L;
|
||||
String logPurgeLimit = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
|
||||
String queryCleanUpLog = "DELETE FROM shop_log WHERE timestamp < '" + logPurgeLimit + "'";
|
||||
String queryCleanUpPlayers = "DELETE FROM player_logout WHERE time < " + String.valueOf(time);
|
||||
|
||||
try {
|
||||
s = connection.createStatement();
|
||||
s.executeUpdate(queryCleanUpLog);
|
||||
|
||||
s2 = connection.createStatement();
|
||||
s2.executeUpdate(queryCleanUpPlayers);
|
||||
|
||||
plugin.getLogger().info("Cleaned up economy log");
|
||||
plugin.debug("Cleaned up economy log");
|
||||
} catch (final SQLException ex) {
|
||||
plugin.getLogger().severe("Failed to clean up economy log");
|
||||
plugin.debug("Failed to clean up economy log");
|
||||
plugin.debug(ex);
|
||||
} finally {
|
||||
close(s, null);
|
||||
close(s2, null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (async) {
|
||||
runnable.runTaskAsynchronously(plugin);
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the revenue a player got while he was offline
|
||||
* @param player Player whose revenue to get
|
||||
|
@ -40,6 +40,11 @@ enable-hologram-interaction: true
|
||||
# Set whether buys and sells should be logged in the database.
|
||||
enable-economy-log: false
|
||||
|
||||
# Sets the time limit for cleaning up the economy log in days.
|
||||
# All log entries older than this will be deleted on server start.
|
||||
# Set this to 0 in order to disable this feature.
|
||||
cleanup-ecomomy-log-days: 30
|
||||
|
||||
# Set whether a debug log file should be created.
|
||||
# The file may get large! Please enable this setting when reporting bugs.
|
||||
enable-debug-log: false
|
||||
|
Loading…
Reference in New Issue
Block a user