Search in sources :

Example 1 with AssignmentRule

use of me.lucko.luckperms.common.assignments.AssignmentRule 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;
}
Also used : PlayerSaveResult(me.lucko.luckperms.common.storage.PlayerSaveResult) User(me.lucko.luckperms.common.model.User) AssignmentRule(me.lucko.luckperms.common.assignments.AssignmentRule)

Aggregations

AssignmentRule (me.lucko.luckperms.common.assignments.AssignmentRule)1 User (me.lucko.luckperms.common.model.User)1 PlayerSaveResult (me.lucko.luckperms.common.storage.PlayerSaveResult)1