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

Commit

Permalink
Make database reload on player join.
Browse files Browse the repository at this point in the history
  • Loading branch information
AppleDash committed Nov 24, 2016
1 parent 8c8c171 commit a144667
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public EconomyStorageBackendFlatfile(File file) {
}

@Override
public void reloadDatabase() {
public synchronized void reloadDatabase() {
if (!file.exists()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.
}
}

0 comments on commit a144667

Please sign in to comment.