Search in sources :

Example 1 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class SpongeConnectionListener method onClientAuth.

@Listener(order = Order.EARLY)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuth(ClientConnectionEvent.Auth e) {
    /* Called when the player first attempts a connection with the server.
           Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) */
    final GameProfile profile = e.getProfile();
    final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId()));
    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName());
    }
    recordConnection(profile.getUniqueId());
    /* Actually process the login for the connection.
           We do this here to delay the login until the data is ready.
           If the login gets cancelled later on, then this will be cleaned up.

           This includes:
           - loading uuid data
           - loading permissions
           - creating a user instance in the UserManager for this connection.
           - setting up cached data. */
    try {
        User user = loadUser(profile.getUniqueId(), username);
        this.plugin.getEventFactory().handleUserLoginProcess(profile.getUniqueId(), username, user);
    } catch (Exception ex) {
        this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
        ex.printStackTrace();
        this.deniedAsyncLogin.add(profile.getUniqueId());
        e.setCancelled(true);
        e.setMessageCancelled(false);
        // noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
Also used : User(me.lucko.luckperms.common.model.User) GameProfile(org.spongepowered.api.profile.GameProfile) Listener(org.spongepowered.api.event.Listener) AbstractConnectionListener(me.lucko.luckperms.common.listener.AbstractConnectionListener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Example 2 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class SpongeConnectionListener method onClientLeave.

@Listener(order = Order.POST)
public void onClientLeave(ClientConnectionEvent.Disconnect e) {
    Player player = e.getTargetEntity();
    // Register with the housekeeper, so the User's instance will stick
    // around for a bit after they disconnect
    this.plugin.getUserManager().getHouseKeeper().registerUsage(player.getUniqueId());
    // force a clear of transient nodes
    this.plugin.getBootstrap().getScheduler().doAsync(() -> {
        User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
        if (user != null) {
            user.clearTransientNodes();
        }
    });
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) User(me.lucko.luckperms.common.model.User) Listener(org.spongepowered.api.event.Listener) AbstractConnectionListener(me.lucko.luckperms.common.listener.AbstractConnectionListener)

Example 3 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class ExpireTemporaryTask method run.

@Override
public void run() {
    boolean groupChanges = false;
    for (Group group : this.plugin.getGroupManager().getAll().values()) {
        if (shouldSkip(group)) {
            continue;
        }
        if (group.auditTemporaryPermissions()) {
            this.plugin.getStorage().saveGroup(group);
            groupChanges = true;
        }
    }
    for (User user : this.plugin.getUserManager().getAll().values()) {
        if (shouldSkip(user)) {
            continue;
        }
        if (user.auditTemporaryPermissions()) {
            this.plugin.getStorage().saveUser(user);
            if (!groupChanges) {
                user.getRefreshBuffer().request();
            }
        }
    }
    if (groupChanges) {
        this.plugin.getUpdateTaskBuffer().request();
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User)

Example 4 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class ConfigurateDao method loadUser.

@Override
public User loadUser(UUID uuid, String username) throws Exception {
    User user = this.plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
    user.getIoLock().lock();
    try {
        ConfigurationNode object = readFile(StorageLocation.USER, uuid.toString());
        if (object != null) {
            String name = object.getNode("name").getString();
            user.getPrimaryGroup().setStoredValue(object.getNode(this instanceof JsonDao ? "primaryGroup" : "primary-group").getString());
            Set<Node> nodes = readNodes(object).stream().map(NodeModel::toNode).collect(Collectors.toSet());
            user.setEnduringNodes(nodes);
            user.setName(name, true);
            boolean save = this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
            if (user.getName().isPresent() && (name == null || !user.getName().get().equalsIgnoreCase(name))) {
                save = true;
            }
            if (save | user.auditTemporaryPermissions()) {
                saveUser(user);
            }
        } else {
            if (this.plugin.getUserManager().shouldSave(user)) {
                user.clearNodes();
                user.getPrimaryGroup().setStoredValue(null);
                this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
            }
        }
    } catch (Exception e) {
        throw reportException(uuid.toString(), e);
    } finally {
        user.getIoLock().unlock();
    }
    user.getRefreshBuffer().requestDirectly();
    return user;
}
Also used : User(me.lucko.luckperms.common.model.User) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) Node(me.lucko.luckperms.api.Node) IOException(java.io.IOException)

Example 5 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class MongoDao method loadUser.

@Override
public User loadUser(UUID uuid, String username) {
    User user = this.plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
    user.getIoLock().lock();
    try {
        MongoCollection<Document> c = this.database.getCollection(this.prefix + "users");
        try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
            if (cursor.hasNext()) {
                // User exists, let's load.
                Document d = cursor.next();
                String name = d.getString("name");
                user.getPrimaryGroup().setStoredValue(d.getString("primaryGroup"));
                Set<Node> nodes = nodesFromDoc(d).stream().map(NodeModel::toNode).collect(Collectors.toSet());
                user.setEnduringNodes(nodes);
                user.setName(name, true);
                boolean save = this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
                if (user.getName().isPresent() && (name == null || !user.getName().get().equalsIgnoreCase(name))) {
                    save = true;
                }
                if (save | user.auditTemporaryPermissions()) {
                    c.replaceOne(new Document("_id", user.getUuid()), userToDoc(user));
                }
            } else {
                if (this.plugin.getUserManager().shouldSave(user)) {
                    user.clearNodes();
                    user.getPrimaryGroup().setStoredValue(null);
                    this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
                }
            }
        }
    } finally {
        user.getIoLock().unlock();
    }
    user.getRefreshBuffer().requestDirectly();
    return user;
}
Also used : User(me.lucko.luckperms.common.model.User) Node(me.lucko.luckperms.api.Node) Document(org.bson.Document)

Aggregations

User (me.lucko.luckperms.common.model.User)67 Group (me.lucko.luckperms.common.model.Group)20 UUID (java.util.UUID)16 Node (me.lucko.luckperms.api.Node)14 Contexts (me.lucko.luckperms.api.Contexts)10 List (java.util.List)9 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)9 Tristate (me.lucko.luckperms.api.Tristate)8 Track (me.lucko.luckperms.common.model.Track)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)7 ProgressLogger (me.lucko.luckperms.common.logging.ProgressLogger)7 Sender (me.lucko.luckperms.common.sender.Sender)7 Map (java.util.Map)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)5 CommandResult (me.lucko.luckperms.common.command.CommandResult)5 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)5