mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-06-29 01:10:52 +00:00
fix db saving error
This commit is contained in:
parent
2cceb7c764
commit
c15f2db284
|
@ -121,6 +121,7 @@ public class DataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void savePlayer(MarriagePlayer player) {
|
public void savePlayer(MarriagePlayer player) {
|
||||||
|
if(player == null || player.getUniqueId() == null) return;
|
||||||
Connection connection = supplier.access();
|
Connection connection = supplier.access();
|
||||||
try {
|
try {
|
||||||
PreparedStatement ps = connection.prepareStatement(String.format(
|
PreparedStatement ps = connection.prepareStatement(String.format(
|
||||||
|
|
|
@ -19,6 +19,7 @@ import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class DatabaseListener implements Listener {
|
public class DatabaseListener implements Listener {
|
||||||
private final Cache<UUID, MarriagePlayer> cache = CacheBuilder.newBuilder().expireAfterWrite(30L, TimeUnit.SECONDS).build();
|
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)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
final UUID userId = event.getPlayer().getUniqueId();
|
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
|
@EventHandler
|
||||||
|
|
Loading…
Reference in a new issue