2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.admin;
|
2020-11-05 21:17:14 +00:00
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
import dev.morphia.Datastore;
|
|
|
|
import dev.morphia.query.Query;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.Plex;
|
|
|
|
import dev.plex.player.PlexPlayer;
|
|
|
|
import dev.plex.storage.StorageType;
|
2020-11-05 21:17:14 +00:00
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.rank.enums.Rank;
|
2020-11-05 21:17:14 +00:00
|
|
|
|
|
|
|
public class AdminList
|
|
|
|
{
|
|
|
|
|
|
|
|
private final Map<UUID, Admin> admins = Maps.newHashMap();
|
|
|
|
|
|
|
|
public void addToCache(Admin admin)
|
|
|
|
{
|
|
|
|
admins.put(admin.getUuid(), admin);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeFromCache(UUID uuid)
|
|
|
|
{
|
|
|
|
admins.remove(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> getAllAdmins()
|
|
|
|
{
|
|
|
|
List<String> admins = Lists.newArrayList();
|
2021-01-03 07:21:15 +00:00
|
|
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
2020-11-05 21:17:14 +00:00
|
|
|
{
|
|
|
|
Datastore store = Plex.get().getMongoConnection().getDatastore();
|
|
|
|
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
2021-01-03 07:21:15 +00:00
|
|
|
for (PlexPlayer player : query)
|
2020-11-05 21:17:14 +00:00
|
|
|
{
|
|
|
|
if (player.getRankFromString().isAtLeast(Rank.ADMIN))
|
|
|
|
{
|
|
|
|
admins.add(player.getName());
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-05 21:17:14 +00:00
|
|
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
|
|
|
{
|
|
|
|
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?)");
|
|
|
|
statement.setString(1, Rank.ADMIN.name().toLowerCase());
|
|
|
|
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
|
|
|
|
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
|
|
|
|
|
|
|
|
ResultSet set = statement.executeQuery();
|
|
|
|
while (set.next())
|
|
|
|
{
|
|
|
|
admins.add(set.getString("name"));
|
|
|
|
}
|
|
|
|
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
|
|
|
catch (SQLException throwables)
|
|
|
|
{
|
2020-11-05 21:17:14 +00:00
|
|
|
throwables.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return admins;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|