mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
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:
parent
f97411ce09
commit
175c7db23d
@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.plex"
|
group = "dev.plex"
|
||||||
version = "1.3.1-SNAPSHOT"
|
version = "1.4-SNAPSHOT"
|
||||||
description = "Plex"
|
description = "Plex"
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
@ -12,12 +12,10 @@ import dev.plex.player.PlexPlayer;
|
|||||||
import dev.plex.punishment.PunishmentManager;
|
import dev.plex.punishment.PunishmentManager;
|
||||||
import dev.plex.rank.RankManager;
|
import dev.plex.rank.RankManager;
|
||||||
import dev.plex.services.ServiceManager;
|
import dev.plex.services.ServiceManager;
|
||||||
import dev.plex.storage.MongoConnection;
|
|
||||||
import dev.plex.storage.RedisConnection;
|
import dev.plex.storage.RedisConnection;
|
||||||
import dev.plex.storage.SQLConnection;
|
import dev.plex.storage.SQLConnection;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import dev.plex.storage.permission.SQLPermissions;
|
import dev.plex.storage.permission.SQLPermissions;
|
||||||
import dev.plex.storage.player.MongoPlayerData;
|
|
||||||
import dev.plex.storage.player.SQLPlayerData;
|
import dev.plex.storage.player.SQLPlayerData;
|
||||||
import dev.plex.storage.punishment.SQLNotes;
|
import dev.plex.storage.punishment.SQLNotes;
|
||||||
import dev.plex.storage.punishment.SQLPunishment;
|
import dev.plex.storage.punishment.SQLPunishment;
|
||||||
@ -52,12 +50,10 @@ public class Plex extends JavaPlugin
|
|||||||
public File modulesFolder;
|
public File modulesFolder;
|
||||||
private StorageType storageType = StorageType.SQLITE;
|
private StorageType storageType = StorageType.SQLITE;
|
||||||
private SQLConnection sqlConnection;
|
private SQLConnection sqlConnection;
|
||||||
private MongoConnection mongoConnection;
|
// private MongoConnection mongoConnection;
|
||||||
private RedisConnection redisConnection;
|
private RedisConnection redisConnection;
|
||||||
|
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
private MongoPlayerData mongoPlayerData;
|
|
||||||
private SQLPlayerData sqlPlayerData;
|
private SQLPlayerData sqlPlayerData;
|
||||||
|
|
||||||
private SQLPunishment sqlPunishment;
|
private SQLPunishment sqlPunishment;
|
||||||
@ -118,7 +114,7 @@ public class Plex extends JavaPlugin
|
|||||||
commands.load(false);
|
commands.load(false);
|
||||||
|
|
||||||
sqlConnection = new SQLConnection();
|
sqlConnection = new SQLConnection();
|
||||||
mongoConnection = new MongoConnection();
|
// mongoConnection = new MongoConnection();
|
||||||
redisConnection = new RedisConnection();
|
redisConnection = new RedisConnection();
|
||||||
|
|
||||||
playerCache = new PlayerCache();
|
playerCache = new PlayerCache();
|
||||||
@ -167,17 +163,10 @@ public class Plex extends JavaPlugin
|
|||||||
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storageType == StorageType.MONGODB)
|
sqlPlayerData = new SQLPlayerData();
|
||||||
{
|
sqlPunishment = new SQLPunishment();
|
||||||
mongoPlayerData = new MongoPlayerData();
|
sqlNotes = new SQLNotes();
|
||||||
}
|
sqlPermissions = new SQLPermissions();
|
||||||
else
|
|
||||||
{
|
|
||||||
sqlPlayerData = new SQLPlayerData();
|
|
||||||
sqlPunishment = new SQLPunishment();
|
|
||||||
sqlNotes = new SQLNotes();
|
|
||||||
sqlPermissions = new SQLPermissions();
|
|
||||||
}
|
|
||||||
|
|
||||||
new ListenerHandler();
|
new ListenerHandler();
|
||||||
new CommandHandler();
|
new CommandHandler();
|
||||||
@ -228,14 +217,7 @@ public class Plex extends JavaPlugin
|
|||||||
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
|
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mongoPlayerData != null) //back to mongo checking
|
sqlPlayerData.update(plexPlayer);
|
||||||
{
|
|
||||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
|
||||||
}
|
|
||||||
else if (sqlPlayerData != null) //sql checking
|
|
||||||
{
|
|
||||||
sqlPlayerData.update(plexPlayer);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
|
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
|
||||||
{
|
{
|
||||||
|
@ -62,32 +62,23 @@ public class AdminList implements PlexBase
|
|||||||
public List<String> getAllAdmins()
|
public List<String> getAllAdmins()
|
||||||
{
|
{
|
||||||
List<String> admins = Lists.newArrayList();
|
List<String> admins = Lists.newArrayList();
|
||||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
try (Connection con = plugin.getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
|
||||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
statement.setString(1, Rank.ADMIN.name().toLowerCase());
|
||||||
admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive()).map(PlexPlayer::getName).toList());
|
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
|
||||||
}
|
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
|
||||||
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());
|
|
||||||
|
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
while (set.next())
|
while (set.next())
|
||||||
{
|
|
||||||
admins.add(set.getString("name"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
admins.add(set.getString("name"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
return admins;
|
return admins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,53 +90,44 @@ public class AdminList implements PlexBase
|
|||||||
public List<PlexPlayer> getAllAdminPlayers()
|
public List<PlexPlayer> getAllAdminPlayers()
|
||||||
{
|
{
|
||||||
List<PlexPlayer> plexPlayers = Lists.newArrayList();
|
List<PlexPlayer> plexPlayers = Lists.newArrayList();
|
||||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
try (Connection con = plugin.getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
|
||||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
statement.setString(1, Rank.ADMIN.name().toLowerCase());
|
||||||
return query.stream().toList().stream().filter(player -> plugin.getRankManager().isAdmin(player)).collect(Collectors.toList());
|
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
|
||||||
}
|
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
|
||||||
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());
|
|
||||||
|
|
||||||
ResultSet set = statement.executeQuery();
|
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");
|
||||||
|
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");
|
}.getType());
|
||||||
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());
|
|
||||||
|
|
||||||
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||||
plexPlayer.setName(name);
|
plexPlayer.setName(name);
|
||||||
plexPlayer.setLoginMessage(loginMSG);
|
plexPlayer.setLoginMessage(loginMSG);
|
||||||
plexPlayer.setPrefix(prefix);
|
plexPlayer.setPrefix(prefix);
|
||||||
plexPlayer.setRank(rankName);
|
plexPlayer.setRank(rankName);
|
||||||
plexPlayer.setIps(ips);
|
plexPlayer.setIps(ips);
|
||||||
plexPlayer.setCoins(coins);
|
plexPlayer.setCoins(coins);
|
||||||
plexPlayer.setVanished(vanished);
|
plexPlayer.setVanished(vanished);
|
||||||
plexPlayer.setCommandSpy(commandspy);
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
plexPlayers.add(plexPlayer);
|
plexPlayers.add(plexPlayer);
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
|
||||||
throwables.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
return plexPlayers;
|
return plexPlayers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,26 +20,12 @@ public class DataUtils
|
|||||||
*/
|
*/
|
||||||
public static boolean hasPlayedBefore(UUID uuid)
|
public static boolean hasPlayedBefore(UUID uuid)
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
return Plex.get().getSqlPlayerData().exists(uuid);
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().exists(uuid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().exists(uuid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasPlayedBefore(String username)
|
public static boolean hasPlayedBefore(String username)
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
return Plex.get().getSqlPlayerData().exists(username);
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().exists(username);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().exists(username);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,14 +47,7 @@ public class DataUtils
|
|||||||
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
|
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().getByUUID(uuid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlexPlayer getPlayer(String username)
|
public static PlexPlayer getPlayer(String username)
|
||||||
@ -84,14 +63,7 @@ public class DataUtils
|
|||||||
return plexPlayer.get();
|
return plexPlayer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().getByName(username);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,14 +81,7 @@ public class DataUtils
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
return Plex.get().getSqlPlayerData().getByIP(ip);
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().getByIP(ip);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().getByIP(ip);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,14 +92,7 @@ public class DataUtils
|
|||||||
*/
|
*/
|
||||||
public static void update(PlexPlayer plexPlayer)
|
public static void update(PlexPlayer plexPlayer)
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
Plex.get().getSqlPlayerData().update(plexPlayer);
|
||||||
{
|
|
||||||
Plex.get().getMongoPlayerData().update(plexPlayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Plex.get().getSqlPlayerData().update(plexPlayer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,16 +103,7 @@ public class DataUtils
|
|||||||
*/
|
*/
|
||||||
public static void insert(PlexPlayer plexPlayer)
|
public static void insert(PlexPlayer plexPlayer)
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||||
{
|
|
||||||
Plex.get().getMongoPlayerData().save(plexPlayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,27 +49,15 @@ public class NotesCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
case "list":
|
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)
|
if (notes.size() == 0)
|
||||||
{
|
{
|
||||||
return messageComponent("noNotes");
|
send(sender, messageComponent("noNotes"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
readNotes(sender, plexPlayer, notes);
|
readNotes(sender, plexPlayer, notes);
|
||||||
}
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case "add":
|
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)));
|
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||||
plexPlayer.getNotes().add(note);
|
plexPlayer.getNotes().add(note);
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
plugin.getSqlNotes().addNote(note);
|
||||||
{
|
|
||||||
plugin.getSqlNotes().addNote(note);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
}
|
|
||||||
return messageComponent("noteAdded");
|
return messageComponent("noteAdded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,59 +90,32 @@ public class NotesCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
return messageComponent("unableToParseNumber", args[2]);
|
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;
|
if (note.getId() == id)
|
||||||
for (Note note : notes)
|
|
||||||
{
|
{
|
||||||
if (note.getId() == id)
|
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
|
||||||
{
|
send(sender, messageComponent("removedNote", id)));
|
||||||
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
|
deleted = true;
|
||||||
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;
|
return null;
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
{
|
{
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
int count = plexPlayer.getNotes().size();
|
||||||
{
|
plexPlayer.getNotes().clear();
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
DataUtils.update(plexPlayer);
|
||||||
{
|
return messageComponent("clearedNotes", count);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
@ -82,28 +82,17 @@ public class PlayerListener<T> extends PlexListener
|
|||||||
|
|
||||||
PermissionsUtil.setupPermissions(player);
|
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();
|
String plural = notes.size() == 1 ? "note." : "notes.";
|
||||||
}
|
if (!notes.isEmpty())
|
||||||
|
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
|
||||||
{
|
{
|
||||||
String plural = notes.size() == 1 ? "note." : "notes.";
|
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD), "plex.notes.notify");
|
||||||
if (!notes.isEmpty())
|
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD), "plex.notes.notify");
|
||||||
{
|
}
|
||||||
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));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// saving the player's data
|
// saving the player's data
|
||||||
|
@ -91,10 +91,7 @@ public class PlexPlayer
|
|||||||
if (loadExtraData)
|
if (loadExtraData)
|
||||||
{
|
{
|
||||||
this.loadPunishments();
|
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()
|
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()
|
public void loadNotes()
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
Plex.get().getSqlNotes().getNotes(this.getUuid());
|
||||||
{
|
|
||||||
Plex.get().getSqlNotes().getNotes(this.getUuid());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toJSON()
|
public String toJSON()
|
||||||
|
@ -102,17 +102,7 @@ public class PunishmentManager implements PlexBase
|
|||||||
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
|
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
|
||||||
{
|
{
|
||||||
plexPlayer.getPunishments().add(punishment);
|
plexPlayer.getPunishments().add(punishment);
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
Plex.get().getSqlPunishment().insertPunishment(punishment);
|
||||||
{
|
|
||||||
CompletableFuture.runAsync(() ->
|
|
||||||
{
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Plex.get().getSqlPunishment().insertPunishment(punishment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotEmpty(File file)
|
private boolean isNotEmpty(File file)
|
||||||
@ -160,27 +150,16 @@ public class PunishmentManager implements PlexBase
|
|||||||
|
|
||||||
public CompletableFuture<List<Punishment>> getActiveBans()
|
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(() ->
|
//PlexLog.debug("Received Punishments");
|
||||||
{
|
List<Punishment> punishmentList = punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
|
||||||
List<PlexPlayer> players = Plex.get().getMongoPlayerData().getPlayers();
|
//PlexLog.debug("Completing with {0} punishments", punishmentList.size());
|
||||||
return players.stream().map(PlexPlayer::getPunishments).flatMap(Collection::stream).filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
|
future.complete(punishmentList);
|
||||||
});
|
});
|
||||||
}
|
return future;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unban(Punishment punishment)
|
public void unban(Punishment punishment)
|
||||||
@ -190,20 +169,7 @@ public class PunishmentManager implements PlexBase
|
|||||||
|
|
||||||
public CompletableFuture<Void> unban(UUID uuid)
|
public CompletableFuture<Void> unban(UUID uuid)
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
return Plex.get().getSqlPunishment().removeBan(uuid);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doPunishment(PlexPlayer player, Punishment punishment)
|
private void doPunishment(PlexPlayer player, Punishment punishment)
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,5 +2,5 @@ package dev.plex.storage;
|
|||||||
|
|
||||||
public enum StorageType
|
public enum StorageType
|
||||||
{
|
{
|
||||||
MONGODB, MARIADB, SQLITE
|
MARIADB, SQLITE
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -90,18 +90,12 @@ public class PlexUtils implements PlexBase
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
if (Plex.get().getMongoConnection().getDatastore() != null)
|
PlexLog.error("Unable to connect to the SQL Server");
|
||||||
{
|
|
||||||
PlexLog.log("Successfully enabled MongoDB!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Plex.get().getMongoConnection().getDatastore() != null)
|
PlexLog.error("Unable to initialize hikari data source!");
|
||||||
{
|
|
||||||
PlexLog.log("Successfully enabled MongoDB!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,9 +235,9 @@ public class PlexUtils implements PlexBase
|
|||||||
Bukkit.broadcast(component);
|
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);
|
pl.sendMessage(component);
|
||||||
});
|
});
|
||||||
|
@ -43,7 +43,7 @@ loginmessages:
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
central:
|
central:
|
||||||
storage: sqlite # Use mariadb, mongodb, or sqlite here
|
storage: sqlite # Use mariadb, or sqlite here
|
||||||
user: ""
|
user: ""
|
||||||
password: ""
|
password: ""
|
||||||
hostname: 127.0.0.1
|
hostname: 127.0.0.1
|
||||||
|
Loading…
Reference in New Issue
Block a user