From a8f589c1b745a1950b321185376d146e8ada5863 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 15 Aug 2017 11:43:54 +0200 Subject: [PATCH] Added config option to disable economy logging --- .../de/epiceric/shopchest/config/Config.java | 4 ++ .../de/epiceric/shopchest/sql/Database.java | 60 ++++++++++--------- src/main/resources/config.yml | 3 + 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index add3172..7b170d4 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -113,6 +113,9 @@ public class Config { /** Whether the debug log file should be created **/ public boolean enable_debug_log; + /** Whether buys and sells should be logged in the database **/ + public boolean enable_ecomomy_log; + /** Whether WorldGuard integration should be enabled **/ public boolean enable_worldguard_integration; @@ -365,6 +368,7 @@ public class Config { enable_quality_mode = plugin.getConfig().getBoolean("enable-quality-mode"); enable_hologram_interaction = plugin.getConfig().getBoolean("enable-hologram-interaction"); enable_debug_log = plugin.getConfig().getBoolean("enable-debug-log"); + enable_ecomomy_log = plugin.getConfig().getBoolean("enable-economy-log"); enable_worldguard_integration = plugin.getConfig().getBoolean("enable-worldguard-integration"); enable_towny_integration = plugin.getConfig().getBoolean("enable-towny-integration"); enable_authme_integration = plugin.getConfig().getBoolean("enable-authme-integration"); diff --git a/src/main/java/de/epiceric/shopchest/sql/Database.java b/src/main/java/de/epiceric/shopchest/sql/Database.java index 918479c..6b48d92 100644 --- a/src/main/java/de/epiceric/shopchest/sql/Database.java +++ b/src/main/java/de/epiceric/shopchest/sql/Database.java @@ -368,38 +368,42 @@ public abstract class Database { * @param callback Callback that - if succeeded - returns {@code null} */ public void logEconomy(final Player executor, final ItemStack product, final OfflinePlayer vendor, final ShopType shopType, final Location location, final double price, final ShopBuySellEvent.Type type, final Callback callback) { - new BukkitRunnable() { - @Override - public void run() { - PreparedStatement ps = null; + if (plugin.getShopChestConfig().enable_ecomomy_log) { + new BukkitRunnable() { + @Override + public void run() { + PreparedStatement ps = null; - try { - ps = connection.prepareStatement("INSERT INTO shop_log (timestamp,executor,product,vendor,world,x,y,z,price,type) VALUES(?,?,?,?,?,?,?,?,?,?)"); + try { + ps = connection.prepareStatement("INSERT INTO shop_log (timestamp,executor,product,vendor,world,x,y,z,price,type) VALUES(?,?,?,?,?,?,?,?,?,?)"); - ps.setString(1, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime())); - ps.setString(2, executor.getUniqueId().toString() + " (" + executor.getName() + ")"); - ps.setString(3, product.getAmount() + " x " + LanguageUtils.getItemName(product)); - ps.setString(4, vendor.getUniqueId().toString() + " (" + vendor.getName() + ")" + (shopType == ShopType.ADMIN ? " (ADMIN)" : "")); - ps.setString(5, location.getWorld().getName()); - ps.setInt(6, location.getBlockX()); - ps.setInt(7, location.getBlockY()); - ps.setInt(8, location.getBlockZ()); - ps.setDouble(9, price); - ps.setString(10, type.toString()); - ps.executeUpdate(); + ps.setString(1, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime())); + ps.setString(2, executor.getUniqueId().toString() + " (" + executor.getName() + ")"); + ps.setString(3, product.getAmount() + " x " + LanguageUtils.getItemName(product)); + ps.setString(4, vendor.getUniqueId().toString() + " (" + vendor.getName() + ")" + (shopType == ShopType.ADMIN ? " (ADMIN)" : "")); + ps.setString(5, location.getWorld().getName()); + ps.setInt(6, location.getBlockX()); + ps.setInt(7, location.getBlockY()); + ps.setInt(8, location.getBlockZ()); + ps.setDouble(9, price); + ps.setString(10, type.toString()); + ps.executeUpdate(); - if (callback != null) callback.callSyncResult(null); - plugin.debug("Logged economy transaction to database"); - } catch (final SQLException ex) { - if (callback != null) callback.callSyncError(ex); - plugin.getLogger().severe("Failed to access database"); - plugin.debug("Failed to log economy transaction to database"); - plugin.debug(ex); - } finally { - close(ps, null); + if (callback != null) callback.callSyncResult(null); + plugin.debug("Logged economy transaction to database"); + } catch (final SQLException ex) { + if (callback != null) callback.callSyncError(ex); + plugin.getLogger().severe("Failed to access database"); + plugin.debug("Failed to log economy transaction to database"); + plugin.debug(ex); + } finally { + close(ps, null); + } } - } - }.runTaskAsynchronously(plugin); + }.runTaskAsynchronously(plugin); + } else { + if (callback != null) callback.callSyncResult(null); + } } /** diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 18fdbfa..bb6011a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -33,6 +33,9 @@ shop-info-item: "STICK" # are the vendor or have permission. enable-hologram-interaction: true +# Set whether buys and sells should be logged in the database. +enable-economy-log: false + # 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