mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-02-11 10:01:26 +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_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_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_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_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=?";
|
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
|
@Override
|
||||||
public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQLException {
|
public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQLException {
|
||||||
username = username.toLowerCase(Locale.ROOT);
|
username = username.toLowerCase(Locale.ROOT);
|
||||||
|
String oldUsername = null;
|
||||||
|
|
||||||
// find any existing mapping
|
try (Connection c = this.connectionFactory.getConnection()) {
|
||||||
String oldUsername = getPlayerName(uniqueId);
|
SqlPlayerData existingPlayerData = selectPlayerData(c, uniqueId);
|
||||||
|
if (existingPlayerData == null) {
|
||||||
// do the insert
|
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) {
|
||||||
if (!username.equals(oldUsername)) {
|
ps.setString(1, uniqueId.toString());
|
||||||
try (Connection c = this.connectionFactory.getConnection()) {
|
ps.setString(2, username);
|
||||||
if (oldUsername != null) {
|
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))) {
|
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_UPDATE_USERNAME_FOR_UUID))) {
|
||||||
ps.setString(1, username);
|
ps.setString(1, username);
|
||||||
ps.setString(2, uniqueId.toString());
|
ps.setString(2, uniqueId.toString());
|
||||||
ps.execute();
|
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