Make database reload on player join.

This commit is contained in:
AppleDash 2016-11-24 05:16:08 -05:00
parent 8c8c171d3a
commit a144667971
3 changed files with 8 additions and 2 deletions

View File

@ -22,7 +22,7 @@ public class EconomyStorageBackendFlatfile extends EconomyStorageBackendCaching
}
@Override
public void reloadDatabase() {
public synchronized void reloadDatabase() {
if (!file.exists()) {
return;
}

View File

@ -97,7 +97,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
}
@Override
public void reloadDatabase() {
public synchronized void reloadDatabase() {
createTables();
try (Connection conn = dbConn.openConnection()) {
PreparedStatement ps = conn.prepareStatement("SELECT * FROM `saneeconomy_balances`");

View File

@ -10,6 +10,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerJoinEvent;
/**
@ -42,4 +43,9 @@ public class JoinQuitListener implements Listener {
MessageUtils.sendMessage(player, "An update is available! The currently-installed version is %s, but the newest available is %s. Please go to %s to update!", plugin.getDescription().getVersion(), plugin.getVersionChecker().getNewestVersion(), GithubVersionChecker.DOWNLOAD_URL);
}
}
@EventHandler
public void onPlayerLogin(AsyncPlayerPreLoginEvent evt) {
plugin.getEconomyManager().getBackend().reloadDatabase(); // TODO: If servers start to lag when lots of people join, this is why.
}
}