Search in sources :

Example 1 with GroupManager

use of me.lucko.luckperms.common.managers.group.GroupManager in project LuckPerms by lucko.

the class SqlDao method loadAllGroups.

@Override
public void loadAllGroups() throws SQLException {
    List<String> groups = new ArrayList<>();
    try (Connection c = this.provider.getConnection()) {
        try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(GROUP_SELECT_ALL))) {
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    groups.add(rs.getString("name").toLowerCase());
                }
            }
        }
    }
    boolean success = true;
    for (String g : groups) {
        try {
            loadGroup(g);
        } catch (Exception e) {
            e.printStackTrace();
            success = false;
        }
    }
    if (!success) {
        throw new RuntimeException("Exception occurred whilst loading a group");
    }
    GroupManager<?> gm = this.plugin.getGroupManager();
    gm.getAll().values().stream().filter(g -> !groups.contains(g.getName())).forEach(gm::unload);
}
Also used : LogEntry(me.lucko.luckperms.api.LogEntry) AbstractDao(me.lucko.luckperms.common.storage.dao.AbstractDao) TypeToken(com.google.gson.reflect.TypeToken) Connection(java.sql.Connection) UserIdentifier(me.lucko.luckperms.common.references.UserIdentifier) AbstractConnectionFactory(me.lucko.luckperms.common.storage.dao.sql.connection.AbstractConnectionFactory) BulkUpdate(me.lucko.luckperms.common.bulkupdate.BulkUpdate) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PlayerSaveResult(me.lucko.luckperms.common.storage.PlayerSaveResult) NodeModel(me.lucko.luckperms.common.node.NodeModel) SQLException(java.sql.SQLException) Gson(com.google.gson.Gson) ResultSet(java.sql.ResultSet) Map(java.util.Map) PostgreConnectionFactory(me.lucko.luckperms.common.storage.dao.sql.connection.hikari.PostgreConnectionFactory) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) HeldPermission(me.lucko.luckperms.api.HeldPermission) ExtendedLogEntry(me.lucko.luckperms.common.actionlog.ExtendedLogEntry) GroupManager(me.lucko.luckperms.common.managers.group.GroupManager) NodeHeldPermission(me.lucko.luckperms.common.node.NodeHeldPermission) Set(java.util.Set) Log(me.lucko.luckperms.common.actionlog.Log) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) UUID(java.util.UUID) ContextSetJsonSerializer(me.lucko.luckperms.common.contexts.ContextSetJsonSerializer) PreparedStatement(java.sql.PreparedStatement) Maps(com.google.common.collect.Maps) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) TrackManager(me.lucko.luckperms.common.managers.track.TrackManager) Type(java.lang.reflect.Type) SQLiteConnectionFactory(me.lucko.luckperms.common.storage.dao.sql.connection.file.SQLiteConnectionFactory) Statement(java.sql.Statement) Group(me.lucko.luckperms.common.model.Group) Optional(java.util.Optional) Node(me.lucko.luckperms.api.Node) BufferedReader(java.io.BufferedReader) User(me.lucko.luckperms.common.model.User) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Aggregations

Maps (com.google.common.collect.Maps)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Type (java.lang.reflect.Type)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1