diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java index 57a957b..a3673cd 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendFlatfile.java @@ -22,7 +22,7 @@ public EconomyStorageBackendFlatfile(File file) { } @Override - public void reloadDatabase() { + public synchronized void reloadDatabase() { if (!file.exists()) { return; } 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 972402c..8a33e2e 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 @@ -97,7 +97,7 @@ private boolean checkTableExists(String tableName) { } @Override - public void reloadDatabase() { + public synchronized void reloadDatabase() { createTables(); try (Connection conn = dbConn.openConnection()) { PreparedStatement ps = conn.prepareStatement("SELECT * FROM `saneeconomy_balances`"); diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/listeners/JoinQuitListener.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/listeners/JoinQuitListener.java index 49a1691..234e4d5 100644 --- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/listeners/JoinQuitListener.java +++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/listeners/JoinQuitListener.java @@ -10,6 +10,7 @@ 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 void onPlayerJoin(PlayerJoinEvent evt) { 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. + } }