From 3bfecbfc4c5284aac5b43d35fe4e3dbc567c7550 Mon Sep 17 00:00:00 2001 From: AppleDash Date: Sun, 22 Jan 2017 12:14:15 -0500 Subject: [PATCH] Try to fix weird MySQL server hangs. --- .../backend/type/EconomyStorageBackendMySQL.java | 12 +++++++++--- .../appledash/saneeconomy/utils/MessageUtils.java | 9 +++++---- .../listeners/EntityDamageListener.java | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java index 7d60b0a..12f160a 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java @@ -12,12 +12,18 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Created by AppleDash on 6/14/2016. * Blackjack is still best pony. */ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching { + private static final Logger LOGGER = Logger.getLogger("EconomyStorageBackendMySQL"); + static { + LOGGER.setLevel(Level.FINEST); + } private final MySQLConnection dbConn; public EconomyStorageBackendMySQL(DatabaseCredentials dbCredentials) { @@ -115,7 +121,7 @@ public synchronized void reloadDatabase() { } @Override - public synchronized void setBalance(final Economable economable, final double newBalance) { + public void setBalance(final Economable economable, final double newBalance) { final double oldBalance = getBalance(economable); balances.put(economable.getUniqueIdentifier(), newBalance); @@ -133,7 +139,7 @@ public synchronized void setBalance(final Economable economable, final double ne }); } - private synchronized void ensureAccountExists(Economable economable, Connection conn) throws SQLException { + private void ensureAccountExists(Economable economable, Connection conn) throws SQLException { if (!accountExists(economable, conn)) { PreparedStatement statement = dbConn.prepareStatement(conn, String.format("INSERT INTO `%s` (unique_identifier, balance) VALUES (?, 0.0)", dbConn.getTable("saneeconomy_balances"))); statement.setString(1, economable.getUniqueIdentifier()); @@ -141,7 +147,7 @@ private synchronized void ensureAccountExists(Economable economable, Connection } } - private synchronized boolean accountExists(Economable economable, Connection conn) throws SQLException { + private boolean accountExists(Economable economable, Connection conn) throws SQLException { PreparedStatement statement = dbConn.prepareStatement(conn, String.format("SELECT 1 FROM `%s` WHERE `unique_identifier` = ?", dbConn.getTable("saneeconomy_balances"))); statement.setString(1, economable.getUniqueIdentifier()); diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/MessageUtils.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/MessageUtils.java index 1fda1c4..686f8fc 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/MessageUtils.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/MessageUtils.java @@ -2,6 +2,7 @@ import com.google.common.base.Strings; import org.appledash.saneeconomy.SaneEconomy; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -23,7 +24,7 @@ public class MessageUtils { * @param fmt String#format format * @param args String#format args */ - public static synchronized void sendMessage(CommandSender target, String fmt, Object... args) { + public static void sendMessage(CommandSender target, String fmt, Object... args) { fmt = _(fmt); String prefix = ChatColor.translateAlternateColorCodes('&', SaneEconomy.getInstance().getConfig().getString("chat.prefix", "")); @@ -36,11 +37,11 @@ public static synchronized void sendMessage(CommandSender target, String fmt, Ob formatted = indexedFormat(fmt, (Object[]) args); } - target.sendMessage(prefix + formatted); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SaneEconomy.getInstance(), () -> target.sendMessage(prefix + formatted)); } - public static synchronized void sendMessage(OfflinePlayer target, String fmt, Object... args) { - if (target.isOnline() && (target instanceof CommandSender)) { + public static void sendMessage(Object target, String fmt, Object... args) { + if ((target instanceof OfflinePlayer) && ((OfflinePlayer) target).isOnline() && (target instanceof CommandSender)) { sendMessage(((CommandSender) target), fmt, (Object[])args); } } diff --git a/SaneEconomyMobKills/src/main/java/org/appledash/saneeconomymobkills/listeners/EntityDamageListener.java b/SaneEconomyMobKills/src/main/java/org/appledash/saneeconomymobkills/listeners/EntityDamageListener.java index 09b0de5..71c8de2 100644 --- a/SaneEconomyMobKills/src/main/java/org/appledash/saneeconomymobkills/listeners/EntityDamageListener.java +++ b/SaneEconomyMobKills/src/main/java/org/appledash/saneeconomymobkills/listeners/EntityDamageListener.java @@ -71,7 +71,7 @@ public void onEntityDeath(EntityDeathEvent evt) { } Map damageDoneToThisEntity = damageDealt.get(entity.getEntityId()); - double totalDmg = sumValues(damageDoneToThisEntity); + double totalDmg = ((LivingEntity) entity).getMaxHealth();//sumValues(damageDoneToThisEntity); for (Map.Entry entry : damageDoneToThisEntity.entrySet()) { double thisDmg = entry.getValue();