Search in sources :

Example 1 with TrackManager

use of me.lucko.luckperms.common.managers.track.TrackManager in project LuckPerms by lucko.

the class SqlDao method loadAllTracks.

@Override
public void loadAllTracks() throws SQLException {
    List<String> tracks = new ArrayList<>();
    try (Connection c = this.provider.getConnection()) {
        try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(TRACK_SELECT_ALL))) {
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    tracks.add(rs.getString("name").toLowerCase());
                }
            }
        }
    }
    boolean success = true;
    for (String t : tracks) {
        try {
            loadTrack(t);
        } catch (Exception e) {
            e.printStackTrace();
            success = false;
        }
    }
    if (!success) {
        throw new RuntimeException("Exception occurred whilst loading a track");
    }
    TrackManager<?> tm = this.plugin.getTrackManager();
    tm.getAll().values().stream().filter(t -> !tracks.contains(t.getName())).forEach(tm::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