Bump the version to 1.4-SNAPSHOT

Remove every trace of MongoDB
Fix issue where notes were not being notified on a permissions based system
This commit is contained in:
Taah 2023-08-25 01:30:41 -07:00
parent f97411ce09
commit 175c7db23d
13 changed files with 109 additions and 505 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = "dev.plex"
version = "1.3.1-SNAPSHOT"
version = "1.4-SNAPSHOT"
description = "Plex"
subprojects {

View File

@ -12,12 +12,10 @@ import dev.plex.player.PlexPlayer;
import dev.plex.punishment.PunishmentManager;
import dev.plex.rank.RankManager;
import dev.plex.services.ServiceManager;
import dev.plex.storage.MongoConnection;
import dev.plex.storage.RedisConnection;
import dev.plex.storage.SQLConnection;
import dev.plex.storage.StorageType;
import dev.plex.storage.permission.SQLPermissions;
import dev.plex.storage.player.MongoPlayerData;
import dev.plex.storage.player.SQLPlayerData;
import dev.plex.storage.punishment.SQLNotes;
import dev.plex.storage.punishment.SQLPunishment;
@ -52,12 +50,10 @@ public class Plex extends JavaPlugin
public File modulesFolder;
private StorageType storageType = StorageType.SQLITE;
private SQLConnection sqlConnection;
private MongoConnection mongoConnection;
// private MongoConnection mongoConnection;
private RedisConnection redisConnection;
private PlayerCache playerCache;
private MongoPlayerData mongoPlayerData;
private SQLPlayerData sqlPlayerData;
private SQLPunishment sqlPunishment;
@ -118,7 +114,7 @@ public class Plex extends JavaPlugin
commands.load(false);
sqlConnection = new SQLConnection();
mongoConnection = new MongoConnection();
// mongoConnection = new MongoConnection();
redisConnection = new RedisConnection();
playerCache = new PlayerCache();
@ -167,17 +163,10 @@ public class Plex extends JavaPlugin
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
}
if (storageType == StorageType.MONGODB)
{
mongoPlayerData = new MongoPlayerData();
}
else
{
sqlPlayerData = new SQLPlayerData();
sqlPunishment = new SQLPunishment();
sqlNotes = new SQLNotes();
sqlPermissions = new SQLPermissions();
}
sqlPlayerData = new SQLPlayerData();
sqlPunishment = new SQLPunishment();
sqlNotes = new SQLNotes();
sqlPermissions = new SQLPermissions();
new ListenerHandler();
new CommandHandler();
@ -228,14 +217,7 @@ public class Plex extends JavaPlugin
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
}
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
}
else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer);
}
sqlPlayerData.update(plexPlayer);
});
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
{

View File

@ -62,32 +62,23 @@ public class AdminList implements PlexBase
public List<String> getAllAdmins()
{
List<String> admins = Lists.newArrayList();
if (plugin.getStorageType() == StorageType.MONGODB)
try (Connection con = plugin.getSqlConnection().getCon())
{
Datastore store = plugin.getMongoConnection().getDatastore();
Query<PlexPlayer> query = store.find(PlexPlayer.class);
admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive()).map(PlexPlayer::getName).toList());
}
else
{
try (Connection con = plugin.getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
statement.setString(1, Rank.ADMIN.name().toLowerCase());
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
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"));
}
}
catch (SQLException throwables)
ResultSet set = statement.executeQuery();
while (set.next())
{
throwables.printStackTrace();
admins.add(set.getString("name"));
}
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
return admins;
}
@ -99,53 +90,44 @@ public class AdminList implements PlexBase
public List<PlexPlayer> getAllAdminPlayers()
{
List<PlexPlayer> plexPlayers = Lists.newArrayList();
if (plugin.getStorageType() == StorageType.MONGODB)
try (Connection con = plugin.getSqlConnection().getCon())
{
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())
{
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
statement.setString(1, Rank.ADMIN.name().toLowerCase());
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
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())
ResultSet set = statement.executeQuery();
while (set.next())
{
String uuid = set.getString("uuid");
String name = set.getString("name");
String loginMSG = set.getString("login_msg");
String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase();
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>>()
{
String uuid = set.getString("uuid");
String name = set.getString("name");
String loginMSG = set.getString("login_msg");
String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase();
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>>()
{
}.getType());
}.getType());
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(uuid));
plexPlayer.setName(name);
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setIps(ips);
plexPlayer.setCoins(coins);
plexPlayer.setVanished(vanished);
plexPlayer.setCommandSpy(commandspy);
plexPlayers.add(plexPlayer);
}
}
catch (SQLException throwables)
{
throwables.printStackTrace();
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(uuid));
plexPlayer.setName(name);
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setIps(ips);
plexPlayer.setCoins(coins);
plexPlayer.setVanished(vanished);
plexPlayer.setCommandSpy(commandspy);
plexPlayers.add(plexPlayer);
}
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
return plexPlayers;
}
}

View File

@ -20,26 +20,12 @@ public class DataUtils
*/
public static boolean hasPlayedBefore(UUID uuid)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().exists(uuid);
}
else
{
return Plex.get().getSqlPlayerData().exists(uuid);
}
return Plex.get().getSqlPlayerData().exists(uuid);
}
public static boolean hasPlayedBefore(String username)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().exists(username);
}
else
{
return Plex.get().getSqlPlayerData().exists(username);
}
return Plex.get().getSqlPlayerData().exists(username);
}
/**
@ -61,14 +47,7 @@ public class DataUtils
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
}
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByUUID(uuid);
}
else
{
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
}
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
}
public static PlexPlayer getPlayer(String username)
@ -84,14 +63,7 @@ public class DataUtils
return plexPlayer.get();
}
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByName(username);
}
else
{
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
}
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
}
/**
@ -109,14 +81,7 @@ public class DataUtils
return player;
}
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByIP(ip);
}
else
{
return Plex.get().getSqlPlayerData().getByIP(ip);
}
return Plex.get().getSqlPlayerData().getByIP(ip);
}
/**
@ -127,14 +92,7 @@ public class DataUtils
*/
public static void update(PlexPlayer plexPlayer)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
Plex.get().getMongoPlayerData().update(plexPlayer);
}
else
{
Plex.get().getSqlPlayerData().update(plexPlayer);
}
Plex.get().getSqlPlayerData().update(plexPlayer);
}
/**
@ -145,16 +103,7 @@ public class DataUtils
*/
public static void insert(PlexPlayer plexPlayer)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
Plex.get().getMongoPlayerData().save(plexPlayer);
}
else
{
Plex.get().getSqlPlayerData().insert(plexPlayer);
}
Plex.get().getSqlPlayerData().insert(plexPlayer);
}
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
}

View File

@ -49,27 +49,15 @@ public class NotesCMD extends PlexCommand
{
case "list":
{
if (plugin.getStorageType() != StorageType.MONGODB)
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
if (notes.size() == 0)
{
send(sender, messageComponent("noNotes"));
return;
}
readNotes(sender, plexPlayer, notes);
});
}
else
{
List<Note> notes = plexPlayer.getNotes();
if (notes.size() == 0)
{
return messageComponent("noNotes");
send(sender, messageComponent("noNotes"));
return;
}
readNotes(sender, plexPlayer, notes);
}
});
return null;
}
case "add":
@ -83,14 +71,7 @@ public class NotesCMD extends PlexCommand
{
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
plexPlayer.getNotes().add(note);
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().addNote(note);
}
else
{
DataUtils.update(plexPlayer);
}
plugin.getSqlNotes().addNote(note);
return messageComponent("noteAdded");
}
}
@ -109,59 +90,32 @@ public class NotesCMD extends PlexCommand
{
return messageComponent("unableToParseNumber", args[2]);
}
if (plugin.getStorageType() != StorageType.MONGODB)
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
boolean deleted = false;
for (Note note : notes)
{
boolean deleted = false;
for (Note note : notes)
if (note.getId() == id)
{
if (note.getId() == id)
{
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
send(sender, messageComponent("removedNote", id)));
deleted = true;
}
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
send(sender, messageComponent("removedNote", id)));
deleted = true;
}
if (!deleted)
{
send(sender, messageComponent("noteNotFound"));
}
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
});
}
else
{
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
{
return messageComponent("removedNote", id);
}
return messageComponent("noteNotFound");
}
if (!deleted)
{
send(sender, messageComponent("noteNotFound"));
}
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
});
return null;
}
case "clear":
{
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
for (Note note : notes)
{
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
}
plexPlayer.getNotes().clear();
send(sender, messageComponent("clearedNotes", notes.size()));
});
}
else
{
int count = plexPlayer.getNotes().size();
plexPlayer.getNotes().clear();
DataUtils.update(plexPlayer);
return messageComponent("clearedNotes", count);
}
return null;
int count = plexPlayer.getNotes().size();
plexPlayer.getNotes().clear();
DataUtils.update(plexPlayer);
return messageComponent("clearedNotes", count);
}
default:
{

View File

@ -82,28 +82,17 @@ public class PlayerListener<T> extends PlexListener
PermissionsUtil.setupPermissions(player);
if (plugin.getStorageType() != StorageType.MONGODB)
{
plexPlayer.loadNotes();
}
plexPlayer.loadNotes();
if (plugin.getStorageType() == StorageType.MONGODB)
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
plexPlayer.loadPunishments();
}
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
String plural = notes.size() == 1 ? "note." : "notes.";
if (!notes.isEmpty())
{
String plural = notes.size() == 1 ? "note." : "notes.";
if (!notes.isEmpty())
{
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD));
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD));
}
});
}
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD), "plex.notes.notify");
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD), "plex.notes.notify");
}
});
}
// saving the player's data

View File

@ -91,10 +91,7 @@ public class PlexPlayer
if (loadExtraData)
{
this.loadPunishments();
if (Plex.get().getStorageType() != StorageType.MONGODB)
{
this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
}
// this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
}
}
@ -130,18 +127,12 @@ public class PlexPlayer
public void loadPunishments()
{
if (Plex.get().getStorageType() != StorageType.MONGODB)
{
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
}
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
}
public void loadNotes()
{
if (Plex.get().getStorageType() != StorageType.MONGODB)
{
Plex.get().getSqlNotes().getNotes(this.getUuid());
}
Plex.get().getSqlNotes().getNotes(this.getUuid());
}
public String toJSON()

View File

@ -102,17 +102,7 @@ public class PunishmentManager implements PlexBase
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
{
plexPlayer.getPunishments().add(punishment);
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
CompletableFuture.runAsync(() ->
{
DataUtils.update(plexPlayer);
});
}
else
{
Plex.get().getSqlPunishment().insertPunishment(punishment);
}
Plex.get().getSqlPunishment().insertPunishment(punishment);
}
private boolean isNotEmpty(File file)
@ -160,27 +150,16 @@ public class PunishmentManager implements PlexBase
public CompletableFuture<List<Punishment>> getActiveBans()
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
//PlexLog.debug("Checking active bans mysql");
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
Plex.get().getSqlPunishment().getPunishments().whenComplete((punishments, throwable) ->
{
return CompletableFuture.supplyAsync(() ->
{
List<PlexPlayer> players = Plex.get().getMongoPlayerData().getPlayers();
return players.stream().map(PlexPlayer::getPunishments).flatMap(Collection::stream).filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
});
}
else
{
//PlexLog.debug("Checking active bans mysql");
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
Plex.get().getSqlPunishment().getPunishments().whenComplete((punishments, throwable) ->
{
//PlexLog.debug("Received Punishments");
List<Punishment> punishmentList = punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
//PlexLog.debug("Completing with {0} punishments", punishmentList.size());
future.complete(punishmentList);
});
return future;
}
//PlexLog.debug("Received Punishments");
List<Punishment> punishmentList = punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
//PlexLog.debug("Completing with {0} punishments", punishmentList.size());
future.complete(punishmentList);
});
return future;
}
public void unban(Punishment punishment)
@ -190,20 +169,7 @@ public class PunishmentManager implements PlexBase
public CompletableFuture<Void> unban(UUID uuid)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return CompletableFuture.runAsync(() ->
{
PlexPlayer plexPlayer = DataUtils.getPlayer(uuid);
plexPlayer.setPunishments(plexPlayer.getPunishments().stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN)
.peek(punishment -> punishment.setActive(false)).collect(Collectors.toList()));
DataUtils.update(plexPlayer);
});
}
else
{
return Plex.get().getSqlPunishment().removeBan(uuid);
}
return Plex.get().getSqlPunishment().removeBan(uuid);
}
private void doPunishment(PlexPlayer player, Punishment punishment)

View File

@ -1,56 +0,0 @@
package dev.plex.storage;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import dev.morphia.Datastore;
import dev.morphia.Morphia;
import dev.morphia.mapping.MapperOptions;
import dev.plex.PlexBase;
import dev.plex.player.PlexPlayer;
import dev.plex.storage.codec.ZonedDateTimeCodec;
import dev.plex.util.PlexLog;
import org.bson.codecs.configuration.CodecRegistries;
public class MongoConnection implements PlexBase
{
// USE MORPHIA API FOR MONGO <3
public Datastore getDatastore()
{
if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("mongodb"))
{
return null;
}
String host = plugin.config.getString("data.central.hostname");
int port = plugin.config.getInt("data.central.port");
String username = plugin.config.getString("data.central.user");
String password = plugin.config.getString("data.central.password");
String database = plugin.config.getString("data.central.db");
String connectionString;
if (username != null && password != null && !username.isEmpty() && !password.isEmpty())
{
if (database != null && !database.isEmpty())
{
connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database + "&uuidRepresentation=STANDARD";
}
else
{
connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?uuidRepresentation=STANDARD";
}
}
else
{
connectionString = "mongodb://" + host + ":" + port + "/?uuidRepresentation=STANDARD";
}
PlexLog.debug("Using mongo connection string: " + connectionString);
MongoClient client = MongoClients.create(MongoClientSettings.builder().codecRegistry(CodecRegistries.fromRegistries(MongoClientSettings.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(new ZonedDateTimeCodec()))).applyConnectionString(new ConnectionString(connectionString)).build());
Datastore datastore = Morphia.createDatastore(client, database == null ? "admin" : database, MapperOptions.DEFAULT);
datastore.getMapper().map(PlexPlayer.class);
datastore.ensureIndexes();
plugin.setStorageType(StorageType.MONGODB);
return datastore;
}
}

View File

@ -2,5 +2,5 @@ package dev.plex.storage;
public enum StorageType
{
MONGODB, MARIADB, SQLITE
MARIADB, SQLITE
}

View File

@ -1,147 +0,0 @@
package dev.plex.storage.player;
import dev.morphia.Datastore;
import dev.morphia.query.Query;
import dev.morphia.query.Update;
import dev.morphia.query.filters.Filters;
import dev.morphia.query.updates.UpdateOperators;
import dev.plex.Plex;
import dev.plex.player.PlexPlayer;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
/**
* Mongo fetching utilities for players
*/
public class MongoPlayerData
{
/**
* The datastore object / database
*/
private final Datastore datastore;
/**
* Creates an instance of the player data
*/
public MongoPlayerData()
{
this.datastore = Plex.get().getMongoConnection().getDatastore();
}
/**
* Checks whether the player exists in mongo's database
*
* @param uuid The unique ID of the player
* @return true if the player was found
*/
public boolean exists(UUID uuid)
{
Query<PlexPlayer> query = datastore.find(PlexPlayer.class)
.filter(Filters.eq("uuid", uuid));
return query.first() != null;
}
public boolean exists(String username)
{
Query<PlexPlayer> query = datastore.find(PlexPlayer.class)
.filter(Filters.regex("name").caseInsensitive().pattern(username));
return query.first() != null;
}
/**
* Gets the player from cache or from mongo's database
*
* @param uuid The unique ID of the player
* @return a PlexPlayer object
* @see PlexPlayer
*/
public PlexPlayer getByUUID(UUID uuid)
{
if (Plex.get().getPlayerCache().getPlexPlayerMap().containsKey(uuid))
{
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
}
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.eq("uuid", uuid));
return query2.first();
}
public PlexPlayer getByName(String username)
{
PlexPlayer player = Plex.get().getPlayerCache().getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getName().equalsIgnoreCase(username)).findFirst().orElse(null);
if (player != null)
{
return player;
}
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.regex("name").caseInsensitive().pattern(username));
return query2.first();
}
/**
* Gets the player from cache or from mongo's database
*
* @param ip The IP address of the player.
* @return a PlexPlayer object
* @see PlexPlayer
*/
public PlexPlayer getByIP(String ip)
{
PlexPlayer player = Plex.get().getPlayerCache().getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
if (player != null)
{
return player;
}
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.in("ips", Collections.singleton(ip)));
return query2.first();
}
/**
* Updates a player's information in the mongo database
*
* @param player The PlexPlayer object
* @see PlexPlayer
*/
public void update(PlexPlayer player)
{
Query<PlexPlayer> filter = datastore.find(PlexPlayer.class)
.filter(Filters.eq("uuid", player.getUuid()));
Update<PlexPlayer> updateOps = filter.update(
UpdateOperators.set("name", player.getName()),
UpdateOperators.set("loginMessage", player.getLoginMessage()),
UpdateOperators.set("prefix", player.getPrefix()),
UpdateOperators.set("vanished", player.isVanished()),
UpdateOperators.set("commandSpy", player.isCommandSpy()),
UpdateOperators.set("adminActive", player.isAdminActive()),
UpdateOperators.set("rank", player.getRank().toLowerCase()),
UpdateOperators.set("ips", player.getIps()),
UpdateOperators.set("coins", player.getCoins()),
UpdateOperators.set("punishments", player.getPunishments()),
UpdateOperators.set("notes", player.getNotes()));
updateOps.execute();
}
public List<PlexPlayer> getPlayers()
{
return datastore.find(PlexPlayer.class).stream().toList();
}
/**
* Saves the player's information in the database
*
* @param plexPlayer The PlexPlayer object
* @see PlexPlayer
*/
public void save(PlexPlayer plexPlayer)
{
datastore.save(plexPlayer);
}
}

View File

@ -90,18 +90,12 @@ public class PlexUtils implements PlexBase
}
catch (SQLException e)
{
if (Plex.get().getMongoConnection().getDatastore() != null)
{
PlexLog.log("Successfully enabled MongoDB!");
}
PlexLog.error("Unable to connect to the SQL Server");
}
}
else
{
if (Plex.get().getMongoConnection().getDatastore() != null)
{
PlexLog.log("Successfully enabled MongoDB!");
}
PlexLog.error("Unable to initialize hikari data source!");
}
}
@ -241,9 +235,9 @@ public class PlexUtils implements PlexBase
Bukkit.broadcast(component);
}
public static void broadcastToAdmins(Component component)
public static void broadcastToAdmins(Component component, String permission)
{
Bukkit.getOnlinePlayers().stream().filter(pl -> plugin.getPlayerCache().getPlexPlayer(pl.getUniqueId()).isAdminActive()).forEach(pl ->
Bukkit.getOnlinePlayers().stream().filter(pl -> plugin.getPlayerCache().getPlexPlayer(pl.getUniqueId()).isAdminActive() || pl.hasPermission(permission)).forEach(pl ->
{
pl.sendMessage(component);
});

View File

@ -43,7 +43,7 @@ loginmessages:
data:
central:
storage: sqlite # Use mariadb, mongodb, or sqlite here
storage: sqlite # Use mariadb, or sqlite here
user: ""
password: ""
hostname: 127.0.0.1