mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-11-27 21:15:37 +01:00
Make logEconomy asynchronous (#21)
This commit is contained in:
parent
ff7248aba4
commit
e94463ccbe
@ -318,8 +318,14 @@ public abstract class Database {
|
|||||||
* @param price Price (buyprice or sellprice, depends on {@code type})
|
* @param price Price (buyprice or sellprice, depends on {@code type})
|
||||||
* @param type Whether the player bought or sold something
|
* @param type Whether the player bought or sold something
|
||||||
*/
|
*/
|
||||||
public void logEconomy(Player executor, ItemStack product, OfflinePlayer vendor, ShopType shopType, Location location, double price, ShopBuySellEvent.Type type) {
|
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) {
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
|
boolean debugLogEnabled = plugin.getShopChestConfig().enable_debug_log;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ps = connection.prepareStatement("INSERT INTO shop_log (timestamp,executor,product,vendor,world,x,y,z,price,type) VALUES(?,?,?,?,?,?,?,?,?,?)");
|
ps = connection.prepareStatement("INSERT INTO shop_log (timestamp,executor,product,vendor,world,x,y,z,price,type) VALUES(?,?,?,?,?,?,?,?,?,?)");
|
||||||
@ -335,17 +341,33 @@ public abstract class Database {
|
|||||||
ps.setDouble(9, price);
|
ps.setDouble(9, price);
|
||||||
ps.setString(10, type.toString());
|
ps.setString(10, type.toString());
|
||||||
|
|
||||||
plugin.debug("Logged economy transaction to database");
|
|
||||||
|
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
} catch (SQLException ex) {
|
|
||||||
|
if (debugLogEnabled) {
|
||||||
|
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
plugin.debug("Logged economy transaction to database");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (final SQLException ex) {
|
||||||
plugin.getLogger().severe("Failed to access database");
|
plugin.getLogger().severe("Failed to access database");
|
||||||
|
if (debugLogEnabled) {
|
||||||
|
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
plugin.debug("Failed to log economy transaction to database");
|
plugin.debug("Failed to log economy transaction to database");
|
||||||
plugin.debug(ex);
|
plugin.debug(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
close(ps, null);
|
close(ps, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a {@link PreparedStatement} and a {@link ResultSet}
|
* Closes a {@link PreparedStatement} and a {@link ResultSet}
|
||||||
|
Loading…
Reference in New Issue
Block a user