Minimize Registerdate on networks

On networks register date is not available so plan_users register date
was set as the first login date Plan sees the player. This lead to
confusion when Plan was installed and old players were counted as
new players by Plan since it had not seen them before.

Code was changed to reduce confusion by updating the register date
in plan_users to smallest possible value if register date exists on a
bukkit server.
This commit is contained in:
Rsl1122 2019-11-10 09:51:16 +02:00
parent 717181eca9
commit 32ccc6ac7f
3 changed files with 43 additions and 1 deletions

View File

@ -202,6 +202,19 @@ public class DataStoreQueries {
};
}
public static Executable updateMainRegisterDate(UUID playerUUID, long registered) {
String sql = "UPDATE " + UsersTable.TABLE_NAME +
" SET " + UsersTable.REGISTERED + "=?" +
WHERE + UsersTable.USER_UUID + "=?";
return new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setLong(1, registered);
statement.setString(2, playerUUID.toString());
}
};
}
/**
* Store Ping data of a player on a server.
*

View File

@ -102,4 +102,25 @@ public class PlayerFetchQueries {
}
};
}
public static Query<Optional<Long>> fetchRegisterDate(UUID playerUUID) {
String sql = SELECT + UsersTable.REGISTERED +
FROM + UsersTable.TABLE_NAME +
WHERE + UsersTable.USER_UUID + "=? LIMIT 1";
return new QueryStatement<Optional<Long>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
}
@Override
public Optional<Long> processResults(ResultSet set) throws SQLException {
if (set.next()) {
return Optional.of(set.getLong(UsersTable.REGISTERED));
}
return Optional.empty();
}
};
}
}

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.storage.database.transactions.events;
import com.djrapitops.plan.storage.database.queries.DataStoreQueries;
import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries;
import java.util.Optional;
import java.util.UUID;
import java.util.function.LongSupplier;
@ -39,8 +40,15 @@ public class PlayerServerRegisterTransaction extends PlayerRegisterTransaction {
@Override
protected void performOperations() {
super.performOperations();
long registerDate = registered.getAsLong();
if (!query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID))) {
execute(DataStoreQueries.registerUserInfo(playerUUID, registered.getAsLong(), serverUUID));
execute(DataStoreQueries.registerUserInfo(playerUUID, registerDate, serverUUID));
}
// Updates register date to smallest possible value.
Optional<Long> foundRegisterDate = query(PlayerFetchQueries.fetchRegisterDate(playerUUID));
if (foundRegisterDate.isPresent() && foundRegisterDate.get() < registerDate) {
execute(DataStoreQueries.updateMainRegisterDate(playerUUID, registerDate));
}
}
}