Skip to content

Commit a28cdca

Browse files
committed
Make "Floodgate" nullable in StoredProfile
The Floodgate field is null in the database, if the player has not been migrated to the new database format. It's a bit cleaner this way than storing the isFloodgateMigrated in a separate field in StoredProfile. One less variable in the already crowded constructor. While this is not memory efficient, this is only temporary, as per TuxCoding#709 (comment) (last sentence).
1 parent 435ea51 commit a28cdca

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public class StoredProfile extends Profile {
3939
private final ReentrantLock saveLock = new ReentrantLock();
4040

4141
private boolean premium;
42-
private boolean floodgate;
42+
private Boolean floodgate;
4343
private String lastIp;
4444
private Instant lastLogin;
4545

46-
public StoredProfile(long rowId, UUID uuid, String playerName, boolean premium, boolean floodgate, String lastIp,
46+
public StoredProfile(long rowId, UUID uuid, String playerName, boolean premium, Boolean floodgate, String lastIp,
4747
Instant lastLogin) {
4848
super(uuid, playerName);
4949

@@ -108,6 +108,10 @@ public synchronized boolean isFloodgate() {
108108
return floodgate;
109109
}
110110

111+
public synchronized boolean isFloodgateMigrated() {
112+
return floodgate != null;
113+
}
114+
111115
public synchronized void setFloodgate(boolean floodgate) {
112116
this.floodgate = floodgate;
113117
}

core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ private Optional<StoredProfile> parseResult(ResultSet resultSet) throws SQLExcep
143143

144144
String name = resultSet.getString("Name");
145145
boolean premium = resultSet.getBoolean("Premium");
146-
boolean floodgate = resultSet.getBoolean("Floodgate");
146+
Boolean floodgate = resultSet.getBoolean("Floodgate");
147+
// if the player wasn't migrated to the new database format
148+
if (resultSet.wasNull()) {
149+
floodgate = null;
150+
}
147151
String lastIp = resultSet.getString("LastIp");
148152
Instant lastLogin = resultSet.getTimestamp("LastLogin").toInstant();
149153
return Optional.of(new StoredProfile(userId, uuid, name, premium, floodgate, lastIp, lastLogin));

0 commit comments

Comments
 (0)