mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-02-06 07:31:23 +01:00
Fix sql insert player query (#3225)
This commit is contained in:
parent
6e07d6ad36
commit
e227d96cbf
@ -98,7 +98,7 @@ public class SqlStorage implements StorageImplementation {
|
||||
private static final String PLAYER_DELETE = "DELETE FROM '{prefix}players' WHERE uuid=?";
|
||||
private static final String PLAYER_SELECT_ALL_UUIDS_BY_USERNAME = "SELECT uuid FROM '{prefix}players' WHERE username=? AND NOT uuid=?";
|
||||
private static final String PLAYER_DELETE_ALL_UUIDS_BY_USERNAME = "DELETE FROM '{prefix}players' WHERE username=? AND NOT uuid=?";
|
||||
private static final String PLAYER_SELECT_BY_UUID = "SELECT username, primary_group FROM '{prefix}players' WHERE uuid=?";
|
||||
private static final String PLAYER_SELECT_BY_UUID = "SELECT username, primary_group FROM '{prefix}players' WHERE uuid=? LIMIT 1";
|
||||
private static final String PLAYER_SELECT_PRIMARY_GROUP_BY_UUID = "SELECT primary_group FROM '{prefix}players' WHERE uuid=? LIMIT 1";
|
||||
private static final String PLAYER_UPDATE_PRIMARY_GROUP_BY_UUID = "UPDATE '{prefix}players' SET primary_group=? WHERE uuid=?";
|
||||
|
||||
@ -607,26 +607,25 @@ public class SqlStorage implements StorageImplementation {
|
||||
@Override
|
||||
public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQLException {
|
||||
username = username.toLowerCase(Locale.ROOT);
|
||||
String oldUsername = null;
|
||||
|
||||
// find any existing mapping
|
||||
String oldUsername = getPlayerName(uniqueId);
|
||||
|
||||
// do the insert
|
||||
if (!username.equals(oldUsername)) {
|
||||
try (Connection c = this.connectionFactory.getConnection()) {
|
||||
if (oldUsername != null) {
|
||||
try (Connection c = this.connectionFactory.getConnection()) {
|
||||
SqlPlayerData existingPlayerData = selectPlayerData(c, uniqueId);
|
||||
if (existingPlayerData == null) {
|
||||
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) {
|
||||
ps.setString(1, uniqueId.toString());
|
||||
ps.setString(2, username);
|
||||
ps.setString(3, GroupManager.DEFAULT_GROUP_NAME);
|
||||
ps.execute();
|
||||
}
|
||||
} else {
|
||||
oldUsername = existingPlayerData.username;
|
||||
if (!username.equals(oldUsername)) {
|
||||
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_UPDATE_USERNAME_FOR_UUID))) {
|
||||
ps.setString(1, username);
|
||||
ps.setString(2, uniqueId.toString());
|
||||
ps.execute();
|
||||
}
|
||||
} else {
|
||||
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) {
|
||||
ps.setString(1, uniqueId.toString());
|
||||
ps.setString(2, username);
|
||||
ps.setString(3, GroupManager.DEFAULT_GROUP_NAME);
|
||||
ps.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user