forked from TuxCoding/FastLogin
Optional migration
This commit is contained in:
@@ -142,16 +142,11 @@ public class AuthStorage {
|
||||
|
||||
public void save(PlayerProfile playerProfile) {
|
||||
try (Connection con = dataSource.getConnection()) {
|
||||
UUID uuid = playerProfile.getUuid();
|
||||
String uuid = playerProfile.getId().map(UUIDTypeAdapter::toMojangId).orElse(null);
|
||||
|
||||
if (playerProfile.isSaved()) {
|
||||
try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) {
|
||||
if (uuid == null) {
|
||||
saveStmt.setString(1, null);
|
||||
} else {
|
||||
saveStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid));
|
||||
}
|
||||
|
||||
saveStmt.setString(1, uuid);
|
||||
saveStmt.setString(2, playerProfile.getPlayerName());
|
||||
saveStmt.setBoolean(3, playerProfile.isPremium());
|
||||
saveStmt.setString(4, playerProfile.getLastIp());
|
||||
@@ -161,11 +156,7 @@ public class AuthStorage {
|
||||
}
|
||||
} else {
|
||||
try (PreparedStatement saveStmt = con.prepareStatement(INSERT_PROFILE, RETURN_GENERATED_KEYS)) {
|
||||
if (uuid == null) {
|
||||
saveStmt.setString(1, null);
|
||||
} else {
|
||||
saveStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid));
|
||||
}
|
||||
saveStmt.setString(1, uuid);
|
||||
|
||||
saveStmt.setString(2, playerProfile.getPlayerName());
|
||||
saveStmt.setBoolean(3, playerProfile.isPremium());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.games647.fastlogin.core;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerProfile {
|
||||
@@ -48,11 +49,11 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
//todo: this should be optional
|
||||
public synchronized UUID getUuid() {
|
||||
return uuid;
|
||||
public synchronized Optional<UUID> getId() {
|
||||
return Optional.ofNullable(uuid);
|
||||
}
|
||||
|
||||
public synchronized void setUuid(UUID uuid) {
|
||||
public synchronized void setId(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public synchronized String toString() {
|
||||
return this.getClass().getSimpleName() + '{' +
|
||||
"playerName='" + playerName + '\'' +
|
||||
", rowId=" + rowId +
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ public abstract class ForceLoginManagement<P extends C, C, L extends LoginSessio
|
||||
if (success) {
|
||||
//update only on success to prevent corrupt data
|
||||
if (playerProfile != null) {
|
||||
playerProfile.setUuid(session.getUuid());
|
||||
playerProfile.setId(session.getUuid());
|
||||
playerProfile.setPremium(true);
|
||||
storage.save(playerProfile);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public abstract class ForceLoginManagement<P extends C, C, L extends LoginSessio
|
||||
}
|
||||
} else if (playerProfile != null) {
|
||||
//cracked player
|
||||
playerProfile.setUuid(null);
|
||||
playerProfile.setId(null);
|
||||
playerProfile.setPremium(false);
|
||||
storage.save(playerProfile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user