Search in sources :

Example 1 with StorageType

use of me.lucko.luckperms.common.storage.StorageType in project LuckPerms by lucko.

the class SplitStorageDao method applyBulkUpdate.

@Override
public void applyBulkUpdate(BulkUpdate bulkUpdate) throws Exception {
    StorageType userType = this.types.get(SplitStorageType.USER);
    StorageType groupType = this.types.get(SplitStorageType.GROUP);
    this.backing.get(userType).applyBulkUpdate(bulkUpdate);
    // if differs
    if (userType != groupType) {
        this.backing.get(groupType).applyBulkUpdate(bulkUpdate);
    }
}
Also used : StorageType(me.lucko.luckperms.common.storage.StorageType) SplitStorageType(me.lucko.luckperms.common.storage.SplitStorageType)

Example 2 with StorageType

use of me.lucko.luckperms.common.storage.StorageType in project LuckPerms by lucko.

the class DependencyRegistry method resolveStorageDependencies.

public Set<Dependency> resolveStorageDependencies(Set<StorageType> storageTypes) {
    Set<Dependency> dependencies = new LinkedHashSet<>();
    for (StorageType storageType : storageTypes) {
        dependencies.addAll(STORAGE_DEPENDENCIES.get(storageType));
    }
    if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
        dependencies.add(Dependency.COMMONS_POOL_2);
        dependencies.add(Dependency.JEDIS);
    }
    // don't load slf4j if it's already present
    if (slf4jPresent()) {
        dependencies.remove(Dependency.SLF4J_API);
        dependencies.remove(Dependency.SLF4J_SIMPLE);
    }
    // don't load configurate dependencies on sponge
    if (this.plugin.getBootstrap().getType() == PlatformType.SPONGE) {
        dependencies.remove(Dependency.CONFIGURATE_CORE);
        dependencies.remove(Dependency.CONFIGURATE_GSON);
        dependencies.remove(Dependency.CONFIGURATE_YAML);
        dependencies.remove(Dependency.CONFIGURATE_HOCON);
        dependencies.remove(Dependency.HOCON_CONFIG);
    }
    return dependencies;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StorageType(me.lucko.luckperms.common.storage.StorageType)

Example 3 with StorageType

use of me.lucko.luckperms.common.storage.StorageType in project LuckPerms by lucko.

the class AbstractLuckPermsPlugin method enable.

public final void enable() {
    // send the startup banner
    displayBanner(getConsoleSender());
    // load some utilities early
    this.verboseHandler = new VerboseHandler();
    this.permissionVault = new PermissionVault();
    this.logDispatcher = new LogDispatcher(this);
    // load configuration
    getLogger().info("Loading configuration...");
    this.configuration = new AbstractConfiguration(this, provideConfigurationAdapter());
    this.configuration.loadAll();
    // load locale
    this.localeManager = new SimpleLocaleManager();
    this.localeManager.tryLoad(this, new File(getBootstrap().getConfigDirectory(), "lang.yml"));
    // now the configuration is loaded, we can create a storage factory and load initial dependencies
    StorageFactory storageFactory = new StorageFactory(this);
    Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
    this.dependencyManager.loadStorageDependencies(storageTypes);
    // register listeners
    registerPlatformListeners();
    // first, setup the file watcher, if enabled
    if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
        this.fileWatcher = new FileWatcher(this);
        getBootstrap().getScheduler().asyncRepeating(this.fileWatcher, 30L);
    }
    // initialise storage
    this.storage = storageFactory.getInstance(StorageType.H2);
    this.messagingService = provideMessagingFactory().getInstance();
    // setup the update task buffer
    this.updateTaskBuffer = new UpdateTaskBuffer(this);
    // register commands
    registerCommands();
    // load internal managers
    getLogger().info("Loading internal permission managers...");
    this.inheritanceHandler = new InheritanceHandler(this);
    this.cachedStateManager = new CachedStateManager();
    // setup user/group/track manager
    setupManagers();
    // init calculator factory
    this.calculatorFactory = provideCalculatorFactory();
    // setup contextmanager & register common calculators
    setupContextManager();
    getContextManager().registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
    // setup platform hooks
    setupPlatformHooks();
    // register with the LP API
    this.apiProvider = new LuckPermsApiProvider(this);
    this.eventFactory = new EventFactory(this, this.apiProvider);
    ApiRegistrationUtil.registerProvider(this.apiProvider);
    registerApiOnPlatform(this.apiProvider);
    // schedule update tasks
    int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
    if (mins > 0) {
        long ticks = mins * 60 * 20;
        getBootstrap().getScheduler().asyncRepeating(() -> this.updateTaskBuffer.request(), ticks);
    }
    getBootstrap().getScheduler().asyncLater(() -> this.updateTaskBuffer.request(), 40L);
    // run an update instantly.
    getLogger().info("Performing initial data load...");
    try {
        new UpdateTask(this, true).run();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // init housekeeping tasks
    registerHousekeepingTasks();
    // perform any platform-specific final setup tasks
    performFinalSetup();
    getLogger().info("Successfully enabled. (took " + (System.currentTimeMillis() - getBootstrap().getStartupTime()) + "ms)");
}
Also used : UpdateTask(me.lucko.luckperms.common.tasks.UpdateTask) LuckPermsApiProvider(me.lucko.luckperms.common.api.LuckPermsApiProvider) VerboseHandler(me.lucko.luckperms.common.verbose.VerboseHandler) StorageType(me.lucko.luckperms.common.storage.StorageType) PermissionVault(me.lucko.luckperms.common.treeview.PermissionVault) EventFactory(me.lucko.luckperms.common.event.EventFactory) AbstractConfiguration(me.lucko.luckperms.common.config.AbstractConfiguration) CachedStateManager(me.lucko.luckperms.common.caching.handlers.CachedStateManager) InheritanceHandler(me.lucko.luckperms.common.inheritance.InheritanceHandler) SimpleLocaleManager(me.lucko.luckperms.common.locale.SimpleLocaleManager) StorageFactory(me.lucko.luckperms.common.storage.StorageFactory) FileWatcher(me.lucko.luckperms.common.storage.dao.file.FileWatcher) UpdateTaskBuffer(me.lucko.luckperms.common.buffers.UpdateTaskBuffer) LogDispatcher(me.lucko.luckperms.common.actionlog.LogDispatcher) File(java.io.File) LuckPermsCalculator(me.lucko.luckperms.common.contexts.LuckPermsCalculator)

Example 4 with StorageType

use of me.lucko.luckperms.common.storage.StorageType in project LuckPerms by lucko.

the class MigrationPowerfulPerms method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
    ProgressLogger log = new ProgressLogger("PowerfulPerms");
    log.addListener(plugin.getConsoleSender());
    log.addListener(sender);
    log.log("Starting.");
    if (!Bukkit.getPluginManager().isPluginEnabled("PowerfulPerms")) {
        log.logError("Plugin not loaded.");
        return CommandResult.STATE_ERROR;
    }
    String method = plugin.getConfiguration().get(ConfigKeys.STORAGE_METHOD);
    StorageType type = StorageType.parse(method);
    if (type == null || type != StorageType.MYSQL) {
        // We need to load the Hikari/MySQL stuff.
        plugin.getDependencyManager().loadStorageDependencies(ImmutableSet.of(StorageType.MYSQL));
    }
    String address = args.get(0);
    String database = args.get(1);
    String username = args.get(2);
    String password = args.get(3);
    String dbTable = args.get(4);
    // Find a list of UUIDs
    log.log("Getting a list of UUIDs to migrate.");
    Set<UUID> uuids = new HashSet<>();
    try (HikariSupplier hikari = new HikariSupplier(address, database, username, password)) {
        hikari.setup("powerfulperms-migrator-pool");
        try (Connection c = hikari.getConnection()) {
            DatabaseMetaData meta = c.getMetaData();
            try (ResultSet rs = meta.getTables(null, null, dbTable, null)) {
                if (!rs.next()) {
                    log.log("Error - Couldn't find table.");
                    return CommandResult.FAILURE;
                }
            }
        }
        try (Connection c = hikari.getConnection()) {
            try (PreparedStatement ps = c.prepareStatement("SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=?")) {
                ps.setString(1, dbTable);
                try (ResultSet rs = ps.executeQuery()) {
                    log.log("Found table: " + dbTable);
                    while (rs.next()) {
                        log.log("" + rs.getString("COLUMN_NAME") + " - " + rs.getString("COLUMN_TYPE"));
                    }
                }
            }
            try (PreparedStatement ps = c.prepareStatement("SELECT `uuid` FROM " + dbTable)) {
                try (ResultSet rs = ps.executeQuery()) {
                    while (rs.next()) {
                        uuids.add(UUID.fromString(rs.getString("uuid")));
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (uuids.isEmpty()) {
        log.logError("Unable to find any UUIDs to migrate.");
        return CommandResult.FAILURE;
    }
    log.log("Found " + uuids.size() + " uuids. Starting migration.");
    PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) Bukkit.getPluginManager().getPlugin("PowerfulPerms");
    PermissionManager pm = ppPlugin.getPermissionManager();
    Collection<Group> groups = pm.getGroups().values();
    AtomicInteger maxWeight = new AtomicInteger(0);
    // Groups first.
    log.log("Starting group migration.");
    AtomicInteger groupCount = new AtomicInteger(0);
    Iterators.iterate(groups, g -> {
        maxWeight.set(Math.max(maxWeight.get(), g.getRank()));
        String groupName = MigrationUtils.standardizeName(g.getName());
        me.lucko.luckperms.common.model.Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
        MigrationUtils.setGroupWeight(group, g.getRank());
        for (Permission p : g.getOwnPermissions()) {
            applyPerm(group, p);
        }
        for (Group parent : g.getParents()) {
            group.setPermission(NodeFactory.buildGroupNode(parent.getName().toLowerCase()).build());
        }
        // server --> prefix afaik
        for (Map.Entry<String, String> prefix : g.getPrefixes().entrySet()) {
            if (prefix.getValue().isEmpty())
                continue;
            String server = prefix.getKey().toLowerCase();
            if (prefix.getKey().equals("*") || prefix.getKey().equals("all")) {
                server = null;
            }
            if (server != null) {
                group.setPermission(NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).setServer(server).build());
            } else {
                group.setPermission(NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).build());
            }
        }
        for (Map.Entry<String, String> suffix : g.getSuffixes().entrySet()) {
            if (suffix.getValue().isEmpty())
                continue;
            String server = suffix.getKey().toLowerCase();
            if (suffix.getKey().equals("*") || suffix.getKey().equals("all")) {
                server = null;
            }
            if (server != null) {
                group.setPermission(NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).setServer(server).build());
            } else {
                group.setPermission(NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).build());
            }
        }
        plugin.getStorage().saveGroup(group);
        log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
    });
    log.log("Migrated " + groupCount.get() + " groups");
    // Migrate all users
    log.log("Starting user migration.");
    AtomicInteger userCount = new AtomicInteger(0);
    // Increment the max weight from the group migrations. All user meta should override.
    maxWeight.addAndGet(5);
    // Migrate all users and their groups
    Iterators.iterate(uuids, uuid -> {
        // Create a LuckPerms user for the UUID
        User user = plugin.getStorage().loadUser(uuid, null).join();
        List<Permission> permissions = joinFuture(pm.getPlayerOwnPermissions(uuid));
        for (Permission p : permissions) {
            applyPerm(user, p);
        }
        // server --> list of groups
        Map<String, List<CachedGroup>> parents = joinFuture(pm.getPlayerOwnGroups(uuid));
        for (Map.Entry<String, List<CachedGroup>> parent : parents.entrySet()) {
            String server = parent.getKey().toLowerCase();
            if (parent.getKey().equals("*") || parent.getKey().equals("all")) {
                server = null;
            }
            for (CachedGroup group : parent.getValue()) {
                applyGroup(pm, user, group, server);
            }
        }
        String prefix = joinFuture(pm.getPlayerOwnPrefix(uuid));
        String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
        if (prefix != null && !prefix.isEmpty()) {
            user.setPermission(NodeFactory.buildPrefixNode(maxWeight.get(), prefix).build());
        }
        if (suffix != null && !suffix.isEmpty()) {
            user.setPermission(NodeFactory.buildSuffixNode(maxWeight.get(), suffix).build());
        }
        Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid));
        if (primaryGroup != null && primaryGroup.getName() != null) {
            String primary = primaryGroup.getName().toLowerCase();
            if (!primary.equals(NodeFactory.DEFAULT_GROUP_NAME)) {
                user.setPermission(NodeFactory.buildGroupNode(primary).build());
                user.getPrimaryGroup().setStoredValue(primary);
            }
        }
        plugin.getUserManager().cleanup(user);
        plugin.getStorage().saveUser(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 : CachedGroup(com.github.gustav9797.PowerfulPermsAPI.CachedGroup) Group(com.github.gustav9797.PowerfulPermsAPI.Group) User(me.lucko.luckperms.common.model.User) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) ResultSet(java.sql.ResultSet) Permission(com.github.gustav9797.PowerfulPermsAPI.Permission) List(java.util.List) UUID(java.util.UUID) HashSet(java.util.HashSet) StorageType(me.lucko.luckperms.common.storage.StorageType) PermissionManager(com.github.gustav9797.PowerfulPermsAPI.PermissionManager) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) CachedGroup(com.github.gustav9797.PowerfulPermsAPI.CachedGroup) DatabaseMetaData(java.sql.DatabaseMetaData) SQLException(java.sql.SQLException) ExecutionException(java.util.concurrent.ExecutionException) PowerfulPermsPlugin(com.github.gustav9797.PowerfulPermsAPI.PowerfulPermsPlugin) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map)

Aggregations

StorageType (me.lucko.luckperms.common.storage.StorageType)4 CachedGroup (com.github.gustav9797.PowerfulPermsAPI.CachedGroup)1 Group (com.github.gustav9797.PowerfulPermsAPI.Group)1 Permission (com.github.gustav9797.PowerfulPermsAPI.Permission)1 PermissionManager (com.github.gustav9797.PowerfulPermsAPI.PermissionManager)1 PowerfulPermsPlugin (com.github.gustav9797.PowerfulPermsAPI.PowerfulPermsPlugin)1 File (java.io.File)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LogDispatcher (me.lucko.luckperms.common.actionlog.LogDispatcher)1