mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2025-02-05 14:22:45 +00:00
fix db saving error
This commit is contained in:
parent
2cceb7c764
commit
c15f2db284
2 changed files with 12 additions and 1 deletions
|
@ -121,6 +121,7 @@ public class DataManager {
|
|||
}
|
||||
|
||||
public void savePlayer(MarriagePlayer player) {
|
||||
if(player == null || player.getUniqueId() == null) return;
|
||||
Connection connection = supplier.access();
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement(String.format(
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
|||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DatabaseListener implements Listener {
|
||||
private final Cache<UUID, MarriagePlayer> cache = CacheBuilder.newBuilder().expireAfterWrite(30L, TimeUnit.SECONDS).build();
|
||||
|
@ -38,7 +39,16 @@ public class DatabaseListener implements Listener {
|
|||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final UUID userId = event.getPlayer().getUniqueId();
|
||||
core.setMPlayer(userId, cache.getIfPresent(userId));
|
||||
MarriagePlayer player = cache.getIfPresent(userId);
|
||||
if(player != null) {
|
||||
core.setMPlayer(userId, cache.getIfPresent(userId));
|
||||
return;
|
||||
}
|
||||
|
||||
// Something went wrong (unusually long login?)
|
||||
core.getLogger().log(Level.WARNING, "Player " + event.getPlayer().getName() + " was not in cache");
|
||||
core.getLogger().log(Level.INFO, "If this message shows often, report to dev");
|
||||
core.setMPlayer(userId, core.getDataManager().loadPlayer(userId));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
Loading…
Reference in a new issue