use of me.lucko.luckperms.common.storage.PlayerSaveResult in project LuckPerms by lucko.
the class FileUuidCache method addMapping.
/**
* Adds a mapping to the cache
*
* @param uuid the uuid of the player
* @param username the username of the player
*/
public PlayerSaveResult addMapping(UUID uuid, String username) {
// perform the insert
String oldUsername = this.lookupMap.put(uuid, username);
PlayerSaveResult result = PlayerSaveResult.determineBaseResult(username, oldUsername);
Set<UUID> conflicting = new HashSet<>(this.lookupMap.lookupUuid(username));
conflicting.remove(uuid);
if (!conflicting.isEmpty()) {
// remove the mappings for conflicting uuids
for (UUID conflict : conflicting) {
this.lookupMap.remove(conflict);
}
result = result.withOtherUuidsPresent(conflicting);
}
return result;
}
use of me.lucko.luckperms.common.storage.PlayerSaveResult in project LuckPerms by lucko.
the class MongoDao method savePlayerData.
@Override
public PlayerSaveResult savePlayerData(UUID uuid, String username) {
username = username.toLowerCase();
MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid");
// find any existing mapping
String oldUsername = getPlayerName(uuid);
// do the insert
if (!username.equalsIgnoreCase(oldUsername)) {
c.replaceOne(new Document("_id", uuid), new Document("_id", uuid).append("name", username), new UpdateOptions().upsert(true));
}
PlayerSaveResult result = PlayerSaveResult.determineBaseResult(username, oldUsername);
Set<UUID> conflicting = new HashSet<>();
try (MongoCursor<Document> cursor = c.find(new Document("name", username)).iterator()) {
if (cursor.hasNext()) {
conflicting.add(cursor.next().get("_id", UUID.class));
}
}
conflicting.remove(uuid);
if (!conflicting.isEmpty()) {
// remove the mappings for conflicting uuids
c.deleteMany(Filters.and(conflicting.stream().map(u -> Filters.eq("_id", u)).collect(Collectors.toList())));
result = result.withOtherUuidsPresent(conflicting);
}
return result;
}
use of me.lucko.luckperms.common.storage.PlayerSaveResult in project LuckPerms by lucko.
the class SqlDao method savePlayerData.
@Override
public PlayerSaveResult savePlayerData(UUID uuid, String username) throws SQLException {
username = username.toLowerCase();
// find any existing mapping
String oldUsername = getPlayerName(uuid);
// do the insert
if (!username.equalsIgnoreCase(oldUsername)) {
try (Connection c = this.provider.getConnection()) {
if (oldUsername != null) {
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(PLAYER_UPDATE_USERNAME_FOR_UUID))) {
ps.setString(1, username);
ps.setString(2, uuid.toString());
ps.execute();
}
} else {
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(PLAYER_INSERT))) {
ps.setString(1, uuid.toString());
ps.setString(2, username);
ps.setString(3, NodeFactory.DEFAULT_GROUP_NAME);
ps.execute();
}
}
}
}
PlayerSaveResult result = PlayerSaveResult.determineBaseResult(username, oldUsername);
Set<UUID> conflicting = new HashSet<>();
try (Connection c = this.provider.getConnection()) {
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(PLAYER_SELECT_ALL_UUIDS_BY_USERNAME))) {
ps.setString(1, username);
ps.setString(2, uuid.toString());
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
conflicting.add(UUID.fromString(rs.getString("uuid")));
}
}
}
}
if (!conflicting.isEmpty()) {
// remove the mappings for conflicting uuids
try (Connection c = this.provider.getConnection()) {
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(PLAYER_DELETE_ALL_UUIDS_BY_USERNAME))) {
ps.setString(1, username);
ps.setString(2, uuid.toString());
ps.execute();
}
}
result = result.withOtherUuidsPresent(conflicting);
}
return result;
}
use of me.lucko.luckperms.common.storage.PlayerSaveResult in project LuckPerms by lucko.
the class AbstractConnectionListener method loadUser.
public User loadUser(UUID u, String username) {
final long startTime = System.currentTimeMillis();
// register with the housekeeper to avoid accidental unloads
this.plugin.getUserManager().getHouseKeeper().registerUsage(u);
// save uuid data.
PlayerSaveResult saveResult = this.plugin.getStorage().savePlayerData(u, username).join();
if (saveResult.includes(PlayerSaveResult.Status.CLEAN_INSERT)) {
this.plugin.getEventFactory().handleUserFirstLogin(u, username);
}
if (saveResult.includes(PlayerSaveResult.Status.OTHER_UUIDS_PRESENT_FOR_USERNAME)) {
this.plugin.getLogger().warn("LuckPerms already has data for player '" + username + "' - but this data is stored under a different uuid.");
this.plugin.getLogger().warn("'" + username + "' has previously used the unique ids " + saveResult.getOtherUuids() + " but is now connecting with '" + u + "'");
this.plugin.getLogger().warn("This is usually because the server is not authenticating correctly. If you're using BungeeCord, please ensure that IP-Forwarding is setup correctly!");
}
User user = this.plugin.getStorage().noBuffer().loadUser(u, username).join();
if (user == null) {
throw new NullPointerException("User is null");
} else {
// Setup defaults for the user
boolean save = false;
for (AssignmentRule rule : this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_ASSIGNMENTS)) {
if (rule.apply(user)) {
save = true;
}
}
// If they were given a default, persist the new assignments back to the storage.
if (save) {
this.plugin.getStorage().noBuffer().saveUser(user).join();
}
// Does some minimum pre-calculations to (maybe) speed things up later.
user.preCalculateData();
}
final long time = System.currentTimeMillis() - startTime;
if (time >= 1000) {
this.plugin.getLogger().warn("Processing login for " + username + " took " + time + "ms.");
}
return user;
}
Aggregations