mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 00:46:40 +00:00
Fix NPE in unban command
This commit is contained in:
@ -25,7 +25,8 @@ import java.util.stream.Collectors;
|
||||
* @see Admin
|
||||
*/
|
||||
|
||||
public class AdminList extends PlexBase {
|
||||
public class AdminList extends PlexBase
|
||||
{
|
||||
/**
|
||||
* Key/Value storage, where the key is the unique ID of the admin
|
||||
*/
|
||||
@ -36,7 +37,8 @@ public class AdminList extends PlexBase {
|
||||
*
|
||||
* @param admin The admin object
|
||||
*/
|
||||
public void addToCache(Admin admin) {
|
||||
public void addToCache(Admin admin)
|
||||
{
|
||||
admins.put(admin.getUuid(), admin);
|
||||
}
|
||||
|
||||
@ -46,7 +48,8 @@ public class AdminList extends PlexBase {
|
||||
* @param uuid The unique ID of the admin
|
||||
* @see UUID
|
||||
*/
|
||||
public void removeFromCache(UUID uuid) {
|
||||
public void removeFromCache(UUID uuid)
|
||||
{
|
||||
admins.remove(uuid);
|
||||
}
|
||||
|
||||
@ -55,24 +58,32 @@ public class AdminList extends PlexBase {
|
||||
*
|
||||
* @return An array list of the names of every admin
|
||||
*/
|
||||
public List<String> getAllAdmins() {
|
||||
public List<String> getAllAdmins()
|
||||
{
|
||||
List<String> admins = Lists.newArrayList();
|
||||
if (plugin.getStorageType() == StorageType.MONGODB) {
|
||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
||||
admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN)).map(PlexPlayer::getName).collect(Collectors.toList()));
|
||||
} else {
|
||||
try (Connection con = plugin.getSqlConnection().getCon()) {
|
||||
}
|
||||
else
|
||||
{
|
||||
try (Connection con = plugin.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()) {
|
||||
while (set.next())
|
||||
{
|
||||
admins.add(set.getString("name"));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -84,21 +95,27 @@ public class AdminList extends PlexBase {
|
||||
*
|
||||
* @return An array list of the names of every admin
|
||||
*/
|
||||
public List<PlexPlayer> getAllAdminPlayers() {
|
||||
public List<PlexPlayer> getAllAdminPlayers()
|
||||
{
|
||||
List<PlexPlayer> plexPlayers = Lists.newArrayList();
|
||||
if (plugin.getStorageType() == StorageType.MONGODB) {
|
||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
||||
return query.stream().toList().stream().filter(player -> plugin.getRankManager().isAdmin(player)).collect(Collectors.toList());
|
||||
} else {
|
||||
try (Connection con = plugin.getSqlConnection().getCon()) {
|
||||
}
|
||||
else
|
||||
{
|
||||
try (Connection con = plugin.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()) {
|
||||
while (set.next())
|
||||
{
|
||||
String uuid = set.getString("uuid");
|
||||
String name = set.getString("name");
|
||||
String loginMSG = set.getString("login_msg");
|
||||
@ -107,7 +124,8 @@ public class AdminList extends PlexBase {
|
||||
long coins = set.getLong("coins");
|
||||
boolean vanished = set.getBoolean("vanished");
|
||||
boolean commandspy = set.getBoolean("commandspy");
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>() {
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||
{
|
||||
}.getType());
|
||||
|
||||
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||
@ -121,7 +139,9 @@ public class AdminList extends PlexBase {
|
||||
plexPlayer.setCommandSpy(commandspy);
|
||||
plexPlayers.add(plexPlayer);
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user