fix db saving error

This commit is contained in:
Lennart ten Wolde 2016-02-26 16:34:16 +01:00
parent 2cceb7c764
commit c15f2db284
2 changed files with 12 additions and 1 deletions

View file

@ -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(

View file

@ -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