Search in sources :

Example 36 with User

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

the class UserReference method apply.

@Override
public void apply(LuckPermsPlugin plugin, Consumer<User> consumer) {
    User user = plugin.getUserManager().getIfLoaded(this.id);
    if (user == null)
        return;
    consumer.accept(user);
}
Also used : User(me.lucko.luckperms.common.model.User)

Example 37 with User

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

the class DebugCommand method getPlayersData.

private static JObject getPlayersData(LuckPermsPlugin plugin) {
    JObject ret = new JObject();
    Set<UUID> onlinePlayers = plugin.getBootstrap().getOnlinePlayers().collect(Collectors.toSet());
    ret.add("count", onlinePlayers.size());
    JArray playerArray = new JArray();
    for (UUID uuid : onlinePlayers) {
        User user = plugin.getUserManager().getIfLoaded(uuid);
        if (user == null) {
            playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", false));
            continue;
        }
        playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", true).add("username", user.getName().orElse("null")).add("primaryGroup", new JObject().add("type", user.getPrimaryGroup().getClass().getName()).add("value", user.getPrimaryGroup().getValue()).add("storedValue", user.getPrimaryGroup().getStoredValue().orElse("null"))).add("activeContext", () -> {
            JObject obj = new JObject();
            Contexts contexts = plugin.getContextForUser(user).orElse(null);
            if (contexts != null) {
                MetaContexts metaContexts = plugin.getContextManager().formMetaContexts(contexts);
                obj.add("data", new JObject().add("permissions", serializePermissionsData(user.getCachedData().getPermissionData(contexts))).add("meta", serializeMetaData(user.getCachedData().getMetaData(metaContexts)))).add("contextSet", ContextSetJsonSerializer.serializeContextSet(contexts.getContexts())).add("settings", serializeContextsSettings(contexts)).add("metaSettings", serializeMetaContextsSettings(metaContexts));
            }
            return obj;
        }));
    }
    ret.add("players", playerArray);
    return ret;
}
Also used : MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) User(me.lucko.luckperms.common.model.User) JObject(me.lucko.luckperms.common.utils.gson.JObject) UUID(java.util.UUID) Contexts(me.lucko.luckperms.api.Contexts) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) JArray(me.lucko.luckperms.common.utils.gson.JArray)

Example 38 with User

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

the class LogNotify method isIgnoring.

public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
    User user = plugin.getUserManager().getIfLoaded(uuid);
    if (user == null) {
        return false;
    }
    Optional<Node> ret = user.getOwnNodes().stream().filter(n -> n.getPermission().equalsIgnoreCase("luckperms.log.notify.ignoring")).findFirst();
    // if set to false, ignore it, return false
    return ret.map(Node::getValuePrimitive).orElse(false);
}
Also used : SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) Log(me.lucko.luckperms.common.actionlog.Log) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) CommandResult(me.lucko.luckperms.common.command.CommandResult) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) List(java.util.List) Message(me.lucko.luckperms.common.locale.message.Message) Optional(java.util.Optional) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Node(me.lucko.luckperms.api.Node) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) User(me.lucko.luckperms.common.model.User) Node(me.lucko.luckperms.api.Node)

Example 39 with User

use of me.lucko.luckperms.common.model.User 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)

Example 40 with User

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

the class MigrationGroupManager method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
    ProgressLogger log = new ProgressLogger("GroupManager");
    log.addListener(plugin.getConsoleSender());
    log.addListener(sender);
    log.log("Starting.");
    if (!args.get(0).equalsIgnoreCase("true") && !args.get(0).equalsIgnoreCase("false")) {
        log.logError("Was expecting true/false, but got " + args.get(0) + " instead.");
        return CommandResult.STATE_ERROR;
    }
    final boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0));
    final Function<String, String> worldMappingFunc = s -> migrateAsGlobal ? null : s;
    if (!Bukkit.getPluginManager().isPluginEnabled("GroupManager")) {
        log.logError("Plugin not loaded.");
        return CommandResult.STATE_ERROR;
    }
    List<String> worlds = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList());
    GroupManager gm = (GroupManager) Bukkit.getPluginManager().getPlugin("GroupManager");
    // Migrate Global Groups
    log.log("Starting global group migration.");
    GlobalGroups gg = GroupManager.getGlobalGroups();
    AtomicInteger globalGroupCount = new AtomicInteger(0);
    Iterators.iterate(gg.getGroupList(), g -> {
        String groupName = MigrationUtils.standardizeName(g.getName());
        Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
        for (String node : g.getPermissionList()) {
            if (node.isEmpty())
                continue;
            group.setPermission(MigrationUtils.parseNode(node, true).build());
        }
        for (String s : g.getInherits()) {
            if (s.isEmpty())
                continue;
            group.setPermission(NodeFactory.make(NodeFactory.groupNode(MigrationUtils.standardizeName(s))));
        }
        plugin.getStorage().saveGroup(group);
        log.logAllProgress("Migrated {} groups so far.", globalGroupCount.incrementAndGet());
    });
    log.log("Migrated " + globalGroupCount.get() + " global groups");
    // Collect data
    Map<UUID, Set<Node>> users = new HashMap<>();
    Map<UUID, String> primaryGroups = new HashMap<>();
    Map<String, Set<Node>> groups = new HashMap<>();
    WorldsHolder wh = gm.getWorldsHolder();
    // Collect data for all users and groups.
    log.log("Collecting user and group data.");
    Iterators.iterate(worlds, String::toLowerCase, world -> {
        log.log("Querying world " + world);
        WorldDataHolder wdh = wh.getWorldData(world);
        AtomicInteger groupWorldCount = new AtomicInteger(0);
        Iterators.iterate(wdh.getGroupList(), group -> {
            String groupName = MigrationUtils.standardizeName(group.getName());
            groups.putIfAbsent(groupName, new HashSet<>());
            for (String node : group.getPermissionList()) {
                if (node.isEmpty())
                    continue;
                groups.get(groupName).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
            }
            for (String s : group.getInherits()) {
                if (s.isEmpty())
                    continue;
                groups.get(groupName).add(NodeFactory.make(NodeFactory.groupNode(MigrationUtils.standardizeName(s)), true, null, worldMappingFunc.apply(world)));
            }
            String[] metaKeys = group.getVariables().getVarKeyList();
            for (String key : metaKeys) {
                String value = group.getVariables().getVarString(key);
                key = key.toLowerCase();
                if (key.isEmpty() || value.isEmpty())
                    continue;
                if (key.equals("build"))
                    continue;
                if (key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY)) {
                    ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
                    groups.get(groupName).add(NodeFactory.buildChatMetaNode(type, 50, value).setWorld(worldMappingFunc.apply(world)).build());
                } else {
                    groups.get(groupName).add(NodeFactory.buildMetaNode(key, value).setWorld(worldMappingFunc.apply(world)).build());
                }
            }
            log.logAllProgress("Migrated {} groups so far in world " + world, groupWorldCount.incrementAndGet());
        });
        log.log("Migrated " + groupWorldCount.get() + " groups in world " + world);
        AtomicInteger userWorldCount = new AtomicInteger(0);
        Iterators.iterate(wdh.getUserList(), user -> {
            UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getUUID());
            if (uuid == null) {
                return;
            }
            users.putIfAbsent(uuid, new HashSet<>());
            for (String node : user.getPermissionList()) {
                if (node.isEmpty())
                    continue;
                users.get(uuid).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
            }
            // Collect sub groups
            String finalWorld = worldMappingFunc.apply(world);
            users.get(uuid).addAll(user.subGroupListStringCopy().stream().filter(n -> !n.isEmpty()).map(n -> NodeFactory.groupNode(MigrationUtils.standardizeName(n))).map(n -> NodeFactory.make(n, true, null, finalWorld)).collect(Collectors.toSet()));
            // Get primary group
            primaryGroups.put(uuid, MigrationUtils.standardizeName(user.getGroupName()));
            String[] metaKeys = user.getVariables().getVarKeyList();
            for (String key : metaKeys) {
                String value = user.getVariables().getVarString(key);
                key = key.toLowerCase();
                if (key.isEmpty() || value.isEmpty())
                    continue;
                if (key.equals("build"))
                    continue;
                if (key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY)) {
                    ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
                    users.get(uuid).add(NodeFactory.buildChatMetaNode(type, 100, value).setWorld(worldMappingFunc.apply(world)).build());
                } else {
                    users.get(uuid).add(NodeFactory.buildMetaNode(key, value).setWorld(worldMappingFunc.apply(world)).build());
                }
            }
            log.logProgress("Migrated {} users so far in world " + world, userWorldCount.incrementAndGet());
        });
        log.log("Migrated " + userWorldCount.get() + " users in world " + world);
    });
    log.log("All data has now been processed, now starting the import process.");
    log.log("Found a total of " + users.size() + " users and " + groups.size() + " groups.");
    log.log("Starting group migration.");
    AtomicInteger groupCount = new AtomicInteger(0);
    Iterators.iterate(groups.entrySet(), e -> {
        Group group = plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
        for (Node node : e.getValue()) {
            group.setPermission(node);
        }
        plugin.getStorage().saveGroup(group);
        log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
    });
    log.log("Migrated " + groupCount.get() + " groups");
    log.log("Starting user migration.");
    AtomicInteger userCount = new AtomicInteger(0);
    Iterators.iterate(users.entrySet(), e -> {
        User user = plugin.getStorage().loadUser(e.getKey(), null).join();
        for (Node node : e.getValue()) {
            user.setPermission(node);
        }
        String primaryGroup = primaryGroups.get(e.getKey());
        if (primaryGroup != null && !primaryGroup.isEmpty()) {
            user.setPermission(NodeFactory.buildGroupNode(primaryGroup).build());
            user.getPrimaryGroup().setStoredValue(primaryGroup);
            user.unsetPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build());
        }
        plugin.getStorage().saveUser(user);
        plugin.getUserManager().cleanup(user);
        log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
    });
    log.log("Migrated " + userCount.get() + " users.");
    log.log("Success! Migration complete.");
    return CommandResult.SUCCESS;
}
Also used : SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HashMap(java.util.HashMap) GlobalGroups(org.anjocaido.groupmanager.GlobalGroups) Function(java.util.function.Function) HashSet(java.util.HashSet) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WorldsHolder(org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder) World(org.bukkit.World) Map(java.util.Map) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Bukkit(org.bukkit.Bukkit) CreationCause(me.lucko.luckperms.api.event.cause.CreationCause) MigrationUtils(me.lucko.luckperms.common.commands.migration.MigrationUtils) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Iterators(me.lucko.luckperms.common.utils.Iterators) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) GroupManager(org.anjocaido.groupmanager.GroupManager) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) WorldDataHolder(org.anjocaido.groupmanager.dataholder.WorldDataHolder) Group(me.lucko.luckperms.common.model.Group) HashSet(java.util.HashSet) Set(java.util.Set) User(me.lucko.luckperms.common.model.User) WorldsHolder(org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder) HashMap(java.util.HashMap) Node(me.lucko.luckperms.api.Node) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) World(org.bukkit.World) GroupManager(org.anjocaido.groupmanager.GroupManager) WorldDataHolder(org.anjocaido.groupmanager.dataholder.WorldDataHolder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GlobalGroups(org.anjocaido.groupmanager.GlobalGroups) UUID(java.util.UUID)

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