fix mongo support

This commit is contained in:
Taah 2022-04-07 00:37:31 -07:00
parent b7926830f0
commit 9ddf3ceeda
21 changed files with 264 additions and 174 deletions

View File

@ -109,6 +109,7 @@ public class Plex extends JavaPlugin
system = config.getString("system");
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.storage"));
try
{
PlexUtils.testConnections();
@ -126,7 +127,7 @@ public class Plex extends JavaPlugin
Metrics metrics = new Metrics(this, 14143);
PlexLog.log("Enabled Metrics");
if (redisConnection.isEnabled())
if (redisConnection != null && redisConnection.isEnabled())
{
redisConnection.getJedis();
PlexLog.log("Connected to Redis!");
@ -188,7 +189,7 @@ public class Plex extends JavaPlugin
sqlPlayerData.update(plexPlayer);
}
});
if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
{
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!");
redisConnection.getJedis().close();

View File

@ -65,13 +65,13 @@ public class AdminList extends PlexBase
{
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()));
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(?, ?, ?)");
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());
@ -108,7 +108,7 @@ public class AdminList extends PlexBase
{
try (Connection con = plugin.getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?)");
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());

View File

@ -38,7 +38,7 @@ public class MongoPlayerData
public boolean exists(UUID uuid)
{
Query<PlexPlayer> query = datastore.find(PlexPlayer.class)
.filter(Filters.eq("uuid", uuid.toString()));
.filter(Filters.eq("uuid", uuid));
return query.first() != null;
}
@ -57,7 +57,7 @@ public class MongoPlayerData
return PlayerCache.getPlexPlayerMap().get(uuid);
}
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.eq("uuid", uuid.toString()));
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.eq("uuid", uuid));
return query2.first();
}
@ -106,13 +106,16 @@ public class MongoPlayerData
Update<PlexPlayer> updateOps = filter
.update(
UpdateOperators.set("name", player.getName()),
UpdateOperators.set("loginMSG", player.getLoginMessage()),
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("vanished", player.isVanished()),
UpdateOperators.set("commandspy", player.isCommandSpy()));
UpdateOperators.set("punishments", player.getPunishments()),
UpdateOperators.set("notes", player.getNotes()));
updateOps.execute();
}

View File

@ -17,8 +17,8 @@ import java.util.UUID;
public class SQLPlayerData
{
private final String SELECT = "SELECT * FROM `players` WHERE uuid=?";
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=?, vanished=?, commandspy=? WHERE uuid=?";
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`, `vanished`, `commandspy`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, adminActive=?, ips=?, coins=?, vanished=?, commandspy=? WHERE uuid=?";
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `adminActive`, `ips`, `coins`, `vanished`, `commandspy`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
/**
* Checks if a player exists in the SQL database
@ -68,6 +68,7 @@ public class SQLPlayerData
String loginMSG = set.getString("login_msg");
String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase();
boolean adminActive = set.getBoolean("adminActive");
long coins = set.getLong("coins");
boolean vanished = set.getBoolean("vanished");
boolean commandspy = set.getBoolean("commandspy");
@ -78,6 +79,7 @@ public class SQLPlayerData
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setAdminActive(adminActive);
plexPlayer.setIps(ips);
plexPlayer.setCoins(coins);
plexPlayer.setVanished(vanished);
@ -110,6 +112,7 @@ public class SQLPlayerData
String loginMSG = set.getString("login_msg");
String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase();
boolean adminActive = set.getBoolean("adminActive");
long coins = set.getLong("coins");
boolean vanished = set.getBoolean("vanished");
boolean commandspy = set.getBoolean("commandspy");
@ -120,6 +123,7 @@ public class SQLPlayerData
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setAdminActive(adminActive);
plexPlayer.setIps(ips);
plexPlayer.setCoins(coins);
plexPlayer.setVanished(vanished);
@ -165,6 +169,7 @@ public class SQLPlayerData
String loginMSG = set.getString("login_msg");
String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase();
boolean adminActive = set.getBoolean("adminActive");
long coins = set.getLong("coins");
boolean vanished = set.getBoolean("vanished");
boolean commandspy = set.getBoolean("commandspy");
@ -176,6 +181,7 @@ public class SQLPlayerData
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setAdminActive(adminActive);
plexPlayer.setIps(ips);
plexPlayer.setCoins(coins);
plexPlayer.setVanished(vanished);
@ -205,11 +211,12 @@ public class SQLPlayerData
statement.setString(2, player.getLoginMessage());
statement.setString(3, player.getPrefix());
statement.setString(4, player.getRank().toLowerCase());
statement.setString(5, new Gson().toJson(player.getIps()));
statement.setLong(6, player.getCoins());
statement.setBoolean(7, player.isVanished());
statement.setBoolean(8, player.isCommandSpy());
statement.setString(9, player.getUuid().toString());
statement.setBoolean(5, player.isAdminActive());
statement.setString(6, new Gson().toJson(player.getIps()));
statement.setLong(7, player.getCoins());
statement.setBoolean(8, player.isVanished());
statement.setBoolean(9, player.isCommandSpy());
statement.setString(10, player.getUuid().toString());
statement.executeUpdate();
}
catch (SQLException throwables)
@ -234,10 +241,11 @@ public class SQLPlayerData
statement.setString(3, player.getLoginMessage());
statement.setString(4, player.getPrefix());
statement.setString(5, player.getRank().toLowerCase());
statement.setString(6, new Gson().toJson(player.getIps()));
statement.setLong(7, player.getCoins());
statement.setBoolean(8, player.isVanished());
statement.setBoolean(9, player.isCommandSpy());
statement.setBoolean(6, player.isAdminActive());
statement.setString(7, new Gson().toJson(player.getIps()));
statement.setLong(8, player.getCoins());
statement.setBoolean(9, player.isVanished());
statement.setBoolean(10, player.isCommandSpy());
statement.execute();
}
catch (SQLException throwables)

View File

@ -5,18 +5,12 @@ import dev.plex.cache.DataUtils;
import dev.plex.cache.player.PlayerCache;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
import dev.plex.command.exception.ConsoleOnlyException;
import dev.plex.command.exception.PlayerNotBannedException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.exception.*;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -25,15 +19,14 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.UUID;
/**
* Superclass for all commands
*/
@ -129,20 +122,25 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
{
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
return true;
} else
{
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
{
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
return true;
}
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (!player.hasPermission(perms.permission()))
{
send(sender, messageComponent("noPermissionNode", perms.permission()));
return true;
}
}
else
} else
{
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
@ -156,8 +154,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{
send(sender, component);
}
}
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
} catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
{
send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage()));
}
@ -181,8 +178,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return true;
}
}
}
else if (params.aliases().split(",").length < 1)
} else if (params.aliases().split(",").length < 1)
{
return getName().equalsIgnoreCase(label);
}
@ -263,8 +259,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
}
if (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
{
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (!player.hasPermission(permission))
{
@ -283,9 +282,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
PlexPlayer plexPlayer = getPlexPlayer(player);
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
return plexPlayer.getRankFromString().isAtLeast(rank);
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
return player.hasPermission(permission);
}
@ -324,9 +322,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
PlexPlayer plexPlayer = getPlexPlayer(player);
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
return plexPlayer.getRankFromString().isAtLeast(rank);
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
return player.hasPermission(permission);
}

View File

@ -14,6 +14,7 @@ import dev.plex.event.AdminRemoveEvent;
import dev.plex.event.AdminSetRankEvent;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.List;
@ -55,6 +56,11 @@ public class AdminCMD extends PlexCommand
UUID targetUUID = PlexUtils.getFromName(args[1]);
if (targetUUID != null)
{
PlexLog.debug("Admin Adding UUID: " + targetUUID);
}
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
{
throw new PlayerNotFoundException();

View File

@ -39,7 +39,7 @@ public class AdminChatCMD extends PlexCommand
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}

View File

@ -9,15 +9,15 @@ import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
import java.util.List;
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
public class FreezeCMD extends PlexCommand
@ -43,7 +43,7 @@ public class FreezeCMD extends PlexCommand
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()) && getPlexPlayer(player).isAdminActive())
{
return messageComponent("higherRankThanYou");
}

View File

@ -7,13 +7,8 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.extra.Note;
import dev.plex.rank.enums.Rank;
import dev.plex.storage.StorageType;
import dev.plex.util.PlexUtils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@ -24,6 +19,13 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.notes")
public class NotesCMD extends PlexCommand
@ -44,6 +46,8 @@ public class NotesCMD extends PlexCommand
switch (args[1].toLowerCase())
{
case "list":
{
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
@ -62,6 +66,23 @@ public class NotesCMD extends PlexCommand
}
send(sender, noteList.get());
});
} else
{
List<Note> notes = plexPlayer.getNotes();
if (notes.size() == 0)
{
return mmString("<red>This player has no notes!");
}
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
for (Note note : notes)
{
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
noteLine = noteLine.append(Component.text(note.getNote())).color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true);
noteList.set(noteList.get().append(Component.newline()));
noteList.set(noteList.get().append(noteLine));
}
send(sender, noteList.get());
}
return null;
}
case "add":
@ -75,7 +96,13 @@ public class NotesCMD extends PlexCommand
{
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), LocalDateTime.now());
plexPlayer.getNotes().add(note);
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().addNote(note);
} else
{
DataUtils.update(plexPlayer);
}
return Component.text("Note added.").color(NamedTextColor.GREEN);
}
}
@ -85,11 +112,12 @@ public class NotesCMD extends PlexCommand
try
{
id = Integer.parseInt(args[2]);
}
catch (NumberFormatException ignored)
} catch (NumberFormatException ignored)
{
return Component.text("Invalid number: " + args[2]).color(NamedTextColor.RED);
}
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
for (Note note : notes)
@ -98,15 +126,25 @@ public class NotesCMD extends PlexCommand
{
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
send(sender, Component.text("Removed note with ID: " + id).color(NamedTextColor.GREEN)));
}
else
} else
{
send(sender, mmString("<red>A note with this ID could not be found"));
}
}
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
});
} else
{
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
{
return Component.text("Removed note with ID: " + id).color(NamedTextColor.GREEN);
}
return mmString("<red>A note with this ID could not be found");
}
}
case "clear":
{
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
@ -114,8 +152,15 @@ public class NotesCMD extends PlexCommand
{
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
}
plexPlayer.getNotes().clear();
send(sender, Component.text("Cleared " + notes.size() + " note(s).").color(NamedTextColor.GREEN));
});
} else {
int count = plexPlayer.getNotes().size();
plexPlayer.getNotes().clear();
DataUtils.update(plexPlayer);
return Component.text("Cleared " + count + " note(s).").color(NamedTextColor.GREEN);
}
return null;
}
default:

View File

@ -52,7 +52,7 @@ public class TempbanCMD extends PlexCommand
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()) && plexPlayer.isAdminActive())
{
return messageComponent("higherRankThanYou");
}

View File

@ -18,17 +18,25 @@ public class AdminListener extends PlexListener
{
String userSender = event.getSender().getName();
PlexPlayer target = event.getPlexPlayer();
if (!target.getRank().isEmpty())
{
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
} else {
target.setRank(Rank.ADMIN.name());
DataUtils.update(target);
PlexUtils.broadcast(messageComponent("newAdminAdded", userSender, target.getName()));
}
target.setAdminActive(true);
DataUtils.update(target);
}
@EventHandler
public void onAdminRemove(AdminRemoveEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = event.getPlexPlayer();
target.setRank("");
// target.setRank("");
target.setAdminActive(false);
DataUtils.update(target);
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
}

View File

@ -4,11 +4,9 @@ import dev.plex.cache.DataUtils;
import dev.plex.cache.player.PlayerCache;
import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer;
import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -19,6 +17,9 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Arrays;
import java.util.List;
public class PlayerListener extends PlexListener
{
// setting up a player's data
@ -32,8 +33,7 @@ public class PlayerListener extends PlexListener
{
player.setOp(true);
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
player.setOp(false);
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
@ -46,8 +46,7 @@ public class PlayerListener extends PlexListener
plexPlayer.setName(player.getName()); // set the name of the player
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); // set the arraylist of ips
DataUtils.insert(plexPlayer); // insert data in some wack db
}
else
} else
{
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
List<String> ips = plexPlayer.getIps();
@ -79,10 +78,14 @@ public class PlayerListener extends PlexListener
PlexUtils.broadcast(MiniMessage.miniMessage().deserialize("<aqua>" + player.getName() + " is " + loginMessage));
}
plexPlayer.loadNotes().whenComplete((notes, throwable) -> {
if (plugin.getStorageType() != StorageType.MONGODB)
{
plexPlayer.loadNotes().whenComplete((notes, throwable) ->
{
//TODO: Send note messages to admins
});
}
}
// saving the player's data
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -132,7 +132,7 @@ public class WorldListener extends PlexListener
switch (title)
{
case DEV -> {
hasAccess = PlexUtils.DEVELOPERS.contains(player.getUuid());
hasAccess = PlexUtils.DEVELOPERS.contains(player.getUuid().toString());
}
case MASTER_BUILDER -> {
hasAccess = Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName());
@ -149,7 +149,7 @@ public class WorldListener extends PlexListener
{
String rankString = required.split("\\.")[1];
Rank rank = Rank.valueOf(rankString.toUpperCase(Locale.ROOT));
hasAccess = player.getRankFromString().isAtLeast(rank);
hasAccess = rank.isAtLeast(Rank.ADMIN) ? player.isAdminActive() && player.getRankFromString().isAtLeast(rank) : player.getRankFromString().isAtLeast(rank);
}
}
return hasAccess;

View File

@ -42,7 +42,7 @@ public class PlexPlayer
@Indexed
private String name;
private Player player;
private transient Player player;
private String loginMessage;
private String prefix;
@ -55,6 +55,8 @@ public class PlexPlayer
private transient boolean muted;
private transient boolean lockedUp;
private boolean adminActive;
private long coins;
private String rank;

View File

@ -1,6 +1,7 @@
package dev.plex.punishment;
import com.google.gson.GsonBuilder;
import dev.morphia.annotations.Entity;
import dev.plex.Plex;
import dev.plex.util.MojangUtils;
import dev.plex.util.PlexUtils;
@ -15,6 +16,7 @@ import net.kyori.adventure.text.Component;
@Getter
@Setter
@Entity
public class Punishment
{
private static final String banUrl = Plex.get().config.getString("banning.ban_url");

View File

@ -1,6 +1,7 @@
package dev.plex.punishment.extra;
import com.google.gson.GsonBuilder;
import dev.morphia.annotations.Entity;
import dev.plex.util.adapter.LocalDateTimeSerializer;
import lombok.Data;
@ -8,6 +9,7 @@ import java.time.LocalDateTime;
import java.util.UUID;
@Data
@Entity
public class Note
{
private final UUID uuid;

View File

@ -101,7 +101,7 @@ public class RankManager
{
return Title.OWNER.getPrefix();
}
if (PlexUtils.DEVELOPERS.contains(player.getUuid())) // don't remove or we will front door ur mother
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
{
return Title.DEV.getPrefix();
}
@ -126,7 +126,7 @@ public class RankManager
{
return Title.OWNER.getLoginMessage();
}
if (PlexUtils.DEVELOPERS.contains(player.getUuid())) // don't remove or we will front door ur mother
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
{
return Title.DEV.getLoginMessage();
}
@ -147,7 +147,7 @@ public class RankManager
{
return Title.OWNER.getColor();
}
if (PlexUtils.DEVELOPERS.contains(player.getUuid())) // don't remove or we will front door ur mother
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
{
return Title.DEV.getColor();
}
@ -164,11 +164,11 @@ public class RankManager
public boolean isAdmin(PlexPlayer plexPlayer)
{
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN);
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive();
}
public boolean isSeniorAdmin(PlexPlayer plexPlayer)
{
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.SENIOR_ADMIN);
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.SENIOR_ADMIN) && plexPlayer.isAdminActive();
}
}

View File

@ -1,5 +1,6 @@
package dev.plex.storage;
import com.mongodb.*;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import dev.morphia.Datastore;
@ -7,6 +8,7 @@ import dev.morphia.Morphia;
import dev.morphia.mapping.MapperOptions;
import dev.plex.PlexBase;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
public class MongoConnection extends PlexBase
{
@ -24,9 +26,22 @@ public class MongoConnection extends PlexBase
String password = plugin.config.getString("data.central.password");
String database = plugin.config.getString("data.central.db");
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
String connectionString;
if (username != null && password != null && !username.isEmpty() && !password.isEmpty())
{
if (database != null && !database.isEmpty())
{
connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
} else {
connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/";
}
} else {
connectionString = "mongodb://" + host + ":" + port + "/";
}
connectionString += "?uuidRepresentation=STANDARD";
PlexLog.debug("Using mongo connection string: " + connectionString);
MongoClient client = MongoClients.create(connectionString);
Datastore datastore = Morphia.createDatastore(client, database, MapperOptions.DEFAULT);
Datastore datastore = Morphia.createDatastore(client, database == null ? "admin" : database, MapperOptions.DEFAULT);
datastore.getMapper().map(PlexPlayer.class);
datastore.ensureIndexes();
plugin.setStorageType(StorageType.MONGODB);

View File

@ -4,16 +4,24 @@ import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import dev.plex.Plex;
import dev.plex.PlexBase;
import lombok.Getter;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
@Getter
public class SQLConnection extends PlexBase
{
private HikariDataSource dataSource;
public SQLConnection()
{
if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("sqlite") && !plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
{
return;
}
String host = plugin.config.getString("data.central.hostname");
int port = plugin.config.getInt("data.central.port");
String username = plugin.config.getString("data.central.user");
@ -37,8 +45,7 @@ public class SQLConnection extends PlexBase
{
dataSource.setJdbcUrl("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
plugin.setStorageType(StorageType.SQLITE);
}
else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
} else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
{
Class.forName("org.mariadb.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mariadb://" + host + ":" + port + "/" + database);
@ -46,8 +53,7 @@ public class SQLConnection extends PlexBase
dataSource.setPassword(password);
Plex.get().setStorageType(StorageType.MARIADB);
}
}
catch (ClassNotFoundException throwables)
} catch (ClassNotFoundException throwables)
{
throwables.printStackTrace();
}
@ -60,6 +66,7 @@ public class SQLConnection extends PlexBase
"`login_msg` VARCHAR(2000), " +
"`prefix` VARCHAR(2000), " +
"`rank` VARCHAR(20), " +
"`adminActive` BOOLEAN," +
"`ips` VARCHAR(2000), " +
"`coins` BIGINT, " +
"`vanished` BOOLEAN, " +
@ -83,8 +90,7 @@ public class SQLConnection extends PlexBase
"`note` VARCHAR(2000), " +
"`timestamp` BIGINT" +
");").execute();
}
catch (SQLException throwables)
} catch (SQLException throwables)
{
throwables.printStackTrace();
}
@ -92,11 +98,14 @@ public class SQLConnection extends PlexBase
public Connection getCon()
{
if (this.dataSource == null)
{
return null;
}
try
{
return dataSource.getConnection();
}
catch (SQLException e)
} catch (SQLException e)
{
e.printStackTrace();
}

View File

@ -6,6 +6,20 @@ import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.config.Config;
import dev.plex.storage.StorageType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommandYamlParser;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -16,38 +30,9 @@ import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommandYamlParser;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class PlexUtils extends PlexBase
{
@ -86,19 +71,26 @@ public class PlexUtils extends PlexBase
}
public static void testConnections()
{
if (Plex.get().getSqlConnection().getDataSource() != null)
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
if (Plex.get().getStorageType() == StorageType.MARIADB)
{
PlexLog.log("Successfully enabled MySQL!");
}
else if (Plex.get().getStorageType() == StorageType.SQLITE)
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
{
PlexLog.log("Successfully enabled SQLite!");
}
} catch (SQLException e)
{
if (Plex.get().getMongoConnection().getDatastore() != null)
{
PlexLog.log("Successfully enabled MongoDB!");
}
catch (SQLException e)
}
} else
{
if (Plex.get().getMongoConnection().getDatastore() != null)
{
@ -209,12 +201,10 @@ public class PlexUtils extends PlexBase
if (config.getString(path) == null)
{
color = def;
}
else if (ChatColor.getByChar(config.getString(path)) == null)
} else if (ChatColor.getByChar(config.getString(path)) == null)
{
color = def;
}
else
} else
{
color = ChatColor.getByChar(config.getString(path));
}
@ -266,8 +256,7 @@ public class PlexUtils extends PlexBase
{
world.setGameRule(rule, value);
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
}
else
} else
{
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
}
@ -319,8 +308,7 @@ public class PlexUtils extends PlexBase
in.close();
connection.disconnect();
return new JSONParser().parse(content.toString());
}
catch (IOException | ParseException ex)
} catch (IOException | ParseException ex)
{
return null;
}
@ -353,14 +341,12 @@ public class PlexUtils extends PlexBase
{
Class<?> clazz = Class.forName(info.getName());
classes.add(clazz);
}
catch (ClassNotFoundException ex)
} catch (ClassNotFoundException ex)
{
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
}
});
}
catch (IOException ex)
} catch (IOException ex)
{
PlexLog.error("Something went wrong while fetching classes from " + packageName);
throw new RuntimeException(ex);

View File

@ -78,6 +78,9 @@ consoleMustDefinePlayer: "<red>You must define a player since you are running th
newAdminAdded: "<aqua>{0} - Adding {1} to the admin list"
# 0 - The command sender
# 1 - The player
adminReadded: "<aqua>{0} - Re-adding {1} to the admin list as rank: {2}"
# 0 - The command sender
# 1 - The player
adminRemoved: "<red>{0} - Removing {1} from the admin list"
# 0 - The command sender
# 1 - The player