Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Try to fix weird MySQL server hangs.
Browse files Browse the repository at this point in the history
  • Loading branch information
AppleDash committed Jan 22, 2017
1 parent 742997c commit 3bfecbf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -133,15 +139,15 @@ 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());
statement.executeUpdate();
}
}

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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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", ""));
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onEntityDeath(EntityDeathEvent evt) {
}

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();
Expand Down

0 comments on commit 3bfecbf

Please sign in to comment.