Try to fix weird MySQL server hangs.

This commit is contained in:
AppleDash 2017-01-22 12:14:15 -05:00
parent 742997cd3d
commit 3bfecbfc4c
3 changed files with 15 additions and 8 deletions

View File

@ -12,12 +12,18 @@ import java.sql.SQLException;
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 class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
}
@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 class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
});
}
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 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
}
}
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());

View File

@ -2,6 +2,7 @@ package org.appledash.saneeconomy.utils;
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 class MessageUtils {
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);
}
}

View File

@ -71,7 +71,7 @@ public class EntityDamageListener implements Listener {
}
Map<UUID, Double> damageDoneToThisEntity = damageDealt.get(entity.getEntityId());
double totalDmg = sumValues(damageDoneToThisEntity);
double totalDmg = ((LivingEntity) entity).getMaxHealth();//sumValues(damageDoneToThisEntity);
for (Map.Entry<UUID, Double> entry : damageDoneToThisEntity.entrySet()) {
double thisDmg = entry.getValue();