mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
commit
91e09d982d
@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "dev.plex"
|
||||
version = "1.3.1-SNAPSHOT"
|
||||
version = "1.4-SNAPSHOT"
|
||||
description = "Plex"
|
||||
|
||||
subprojects {
|
||||
|
@ -7,11 +7,11 @@ dependencies {
|
||||
annotationProcessor "org.projectlombok:lombok:1.18.28"
|
||||
library "org.json:json:20230618"
|
||||
library "commons-io:commons-io:2.13.0"
|
||||
library "dev.morphia.morphia:morphia-core:2.4.1"
|
||||
library "redis.clients:jedis:5.0.0-beta2"
|
||||
library "org.mariadb.jdbc:mariadb-java-client:3.1.4"
|
||||
library "com.zaxxer:HikariCP:5.0.1"
|
||||
library "org.apache.maven.resolver:maven-resolver-transport-http:1.9.15"
|
||||
library "org.jetbrains:annotations:24.0.1"
|
||||
compileOnly "dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT"
|
||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
|
||||
exclude group: "org.bukkit", module: "bukkit"
|
||||
@ -59,6 +59,10 @@ paper {
|
||||
required = false
|
||||
load = 'BEFORE'
|
||||
}
|
||||
'SlimeWorldManager' {
|
||||
required = false
|
||||
load = 'AFTER'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dev.plex;
|
||||
|
||||
import dev.plex.admin.Admin;
|
||||
import dev.plex.admin.AdminList;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.config.Config;
|
||||
@ -10,34 +9,29 @@ import dev.plex.handlers.ListenerHandler;
|
||||
import dev.plex.module.ModuleManager;
|
||||
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;
|
||||
import dev.plex.util.BuildInfo;
|
||||
import dev.plex.util.BungeeUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.UpdateChecker;
|
||||
import dev.plex.util.*;
|
||||
import dev.plex.util.redis.MessageUtil;
|
||||
import dev.plex.util.sql.SQLUtil;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import java.io.File;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
@ -52,26 +46,19 @@ 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;
|
||||
private SQLNotes sqlNotes;
|
||||
private SQLPermissions sqlPermissions;
|
||||
|
||||
private ModuleManager moduleManager;
|
||||
private RankManager rankManager;
|
||||
private ServiceManager serviceManager;
|
||||
private PunishmentManager punishmentManager;
|
||||
|
||||
private AdminList adminList;
|
||||
private UpdateChecker updateChecker;
|
||||
private String system;
|
||||
|
||||
private Permission permissions;
|
||||
private Chat chat;
|
||||
@ -118,13 +105,11 @@ public class Plex extends JavaPlugin
|
||||
commands.load(false);
|
||||
|
||||
sqlConnection = new SQLConnection();
|
||||
mongoConnection = new MongoConnection();
|
||||
// mongoConnection = new MongoConnection();
|
||||
redisConnection = new RedisConnection();
|
||||
|
||||
playerCache = new PlayerCache();
|
||||
|
||||
system = config.getString("system");
|
||||
|
||||
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db"));
|
||||
try
|
||||
{
|
||||
@ -137,16 +122,13 @@ public class Plex extends JavaPlugin
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (system.equals("permissions"))
|
||||
{
|
||||
if (!getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions alongside a permissions plugin, we recommend LuckPerms!");
|
||||
}
|
||||
|
||||
permissions = setupPermissions();
|
||||
chat = setupChat();
|
||||
}
|
||||
|
||||
updateChecker = new UpdateChecker();
|
||||
PlexLog.log("Update checking enabled");
|
||||
@ -167,27 +149,13 @@ 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();
|
||||
}
|
||||
|
||||
new ListenerHandler();
|
||||
new CommandHandler();
|
||||
|
||||
rankManager = new RankManager();
|
||||
rankManager.generateDefaultRanks();
|
||||
rankManager.importDefaultRanks();
|
||||
adminList = new AdminList();
|
||||
PlexLog.log("Rank Manager initialized");
|
||||
|
||||
punishmentManager = new PunishmentManager();
|
||||
punishmentManager.mergeIndefiniteBans();
|
||||
PlexLog.log("Punishment System initialized");
|
||||
@ -222,20 +190,7 @@ public class Plex extends JavaPlugin
|
||||
Bukkit.getOnlinePlayers().forEach(player ->
|
||||
{
|
||||
PlexPlayer plexPlayer = playerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
||||
|
||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
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);
|
||||
}
|
||||
});
|
||||
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
|
||||
{
|
||||
@ -264,13 +219,6 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
playerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
Admin admin = new Admin(plexPlayer.getUuid());
|
||||
admin.setRank(plexPlayer.getRankFromString());
|
||||
|
||||
plugin.getAdminList().addToCache(admin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
package dev.plex.admin;
|
||||
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Admin object to handle cached admins
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class Admin
|
||||
{
|
||||
/**
|
||||
* Gets the unique ID of an admin (immutable)
|
||||
*/
|
||||
@Setter(AccessLevel.NONE)
|
||||
private UUID uuid;
|
||||
|
||||
/**
|
||||
* Gets the rank of the admin
|
||||
* <br>
|
||||
* Contains a #setRank and #getRank by lombok
|
||||
*/
|
||||
private Rank rank;
|
||||
|
||||
/**
|
||||
* Returns if the admin has command spy or not
|
||||
* <br>
|
||||
* Contains a #isCommandSpy and #setCommandSpy by Lombok
|
||||
*/
|
||||
private boolean commandSpy = false;
|
||||
|
||||
/**
|
||||
* Returns if the admin has admin chat toggled or not
|
||||
* <br>
|
||||
* Contains a #isAdminChat and #setAdminChat by Lombok
|
||||
*/
|
||||
private boolean adminChat = false;
|
||||
|
||||
/**
|
||||
* Creates an admin with the ADMIN rank as the default rank
|
||||
*
|
||||
* @param uuid
|
||||
* @see UUID
|
||||
* @see Rank
|
||||
*/
|
||||
public Admin(UUID uuid)
|
||||
{
|
||||
this.uuid = uuid;
|
||||
this.rank = Rank.ADMIN;
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package dev.plex.admin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.query.Query;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Cached storage for Admin objects
|
||||
*
|
||||
* @see Admin
|
||||
*/
|
||||
|
||||
public class AdminList implements PlexBase
|
||||
{
|
||||
/**
|
||||
* Key / Value storage, where the key is the unique ID of the admin
|
||||
*/
|
||||
private final Map<UUID, Admin> admins = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* Adds the admin to cache
|
||||
*
|
||||
* @param admin The admin object
|
||||
*/
|
||||
public void addToCache(Admin admin)
|
||||
{
|
||||
admins.put(admin.getUuid(), admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an admin from the cache
|
||||
*
|
||||
* @param uuid The unique ID of the admin
|
||||
* @see UUID
|
||||
*/
|
||||
public void removeFromCache(UUID uuid)
|
||||
{
|
||||
admins.remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers every admins username (cached and in the database)
|
||||
*
|
||||
* @return An array list of the names of every admin
|
||||
*/
|
||||
public List<String> getAllAdmins()
|
||||
{
|
||||
List<String> admins = Lists.newArrayList();
|
||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
||||
admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && 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());
|
||||
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next())
|
||||
{
|
||||
admins.add(set.getString("name"));
|
||||
}
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
return admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers every admin (cached and in the database)
|
||||
*
|
||||
* @return An array list of the names of every admin
|
||||
*/
|
||||
public List<PlexPlayer> getAllAdminPlayers()
|
||||
{
|
||||
List<PlexPlayer> plexPlayers = Lists.newArrayList();
|
||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
||||
return query.stream().toList().stream().filter(player -> plugin.getRankManager().isAdmin(player)).collect(Collectors.toList());
|
||||
}
|
||||
else
|
||||
{
|
||||
try (Connection con = plugin.getSqlConnection().getCon())
|
||||
{
|
||||
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())
|
||||
{
|
||||
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());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -19,28 +19,14 @@ public class DataUtils
|
||||
* @return true if the player is registered in the database
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player from cache or from the database
|
||||
@ -61,15 +47,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
public static PlexPlayer getPlayer(String username)
|
||||
{
|
||||
@ -84,15 +63,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player from cache or from the database
|
||||
@ -109,15 +81,8 @@ public class DataUtils
|
||||
return player;
|
||||
}
|
||||
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoPlayerData().getByIP(ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plex.get().getSqlPlayerData().getByIP(ip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a player's information in the database
|
||||
@ -126,16 +91,9 @@ public class DataUtils
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static void update(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getMongoPlayerData().update(plexPlayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plex.get().getSqlPlayerData().update(plexPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a player's information in the database
|
||||
@ -144,17 +102,8 @@ public class DataUtils
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static void insert(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getMongoPlayerData().save(plexPlayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
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 net.kyori.adventure.audience.Audience;
|
||||
@ -45,11 +44,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
*/
|
||||
private final CommandPermissions perms;
|
||||
|
||||
/**
|
||||
* Minimum required rank fetched from the permissions
|
||||
*/
|
||||
private final Rank level;
|
||||
|
||||
/**
|
||||
* Required command source fetched from the permissions
|
||||
*/
|
||||
@ -72,7 +66,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
}
|
||||
this.level = perms.level();
|
||||
this.commandSource = perms.source();
|
||||
|
||||
if (register)
|
||||
@ -140,73 +133,23 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
return false;
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||
|
||||
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"))
|
||||
{
|
||||
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
|
||||
@ -286,39 +229,15 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
* Checks whether a sender has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param sender A CommandSender
|
||||
* @param rank The rank to check (if the server is using ranks)
|
||||
* @param permission The permission to check (if the server is using permissions)
|
||||
* @param permission The permission to check
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean checkRank(CommandSender sender, Rank rank, String permission)
|
||||
protected boolean checkPermission(CommandSender sender, String permission)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkRank((Player) sender, rank, permission);
|
||||
return checkPermission((Player) sender, permission);
|
||||
}
|
||||
/*if (!sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(rank))
|
||||
{
|
||||
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"))
|
||||
{
|
||||
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -326,40 +245,16 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
* Checks whether a sender has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param sender A CommandSender
|
||||
* @param rank The rank to check (if the server is using ranks)
|
||||
* @param permission The permission to check (if the server is using permissions)
|
||||
* @param permission The permission to check
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean silentCheckRank(CommandSender sender, Rank rank, String permission)
|
||||
protected boolean silentCheckPermission(CommandSender sender, String permission)
|
||||
{
|
||||
PlexLog.debug("Checking {0} with {1}", sender.getName(), permission);
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return silentCheckRank((Player) sender, rank, permission);
|
||||
return silentCheckPermission((Player) sender, permission);
|
||||
}
|
||||
/*if (!sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(rank))
|
||||
{
|
||||
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"))
|
||||
{
|
||||
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -367,48 +262,26 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
* Checks whether a player has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param player The player object
|
||||
* @param rank The rank to check (if the server is using ranks)
|
||||
* @param permission The permission to check (if the server is using permissions)
|
||||
* @param permission The permission to check
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean checkRank(Player player, Rank rank, String permission)
|
||||
protected boolean checkPermission(Player player, String permission)
|
||||
{
|
||||
if (player instanceof ConsoleCommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(rank) || (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive()))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!permission.isEmpty() && !player.hasPermission(permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean silentCheckRank(Player player, Rank rank, String permission)
|
||||
{
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
protected boolean silentCheckPermission(Player player, String permission)
|
||||
{
|
||||
return !permission.isEmpty() && player.hasPermission(permission);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* *//**
|
||||
* Checks whether a sender has enough permissions or is high enough a rank
|
||||
@ -419,11 +292,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*//*
|
||||
protected boolean silentCheckRank(CommandSender sender, Rank rank, String permission)
|
||||
protected boolean silentCheckPermission(CommandSender sender, Rank rank, String permission)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return silentCheckRank((Player) sender, rank, permission);
|
||||
return silentCheckPermission((Player) sender, rank, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -437,7 +310,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*//*
|
||||
protected boolean silentCheckRank(Player player, Rank rank, String permission)
|
||||
protected boolean silentCheckPermission(Player player, Rank rank, String permission)
|
||||
{
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
@ -451,62 +324,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
return true;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Checks if a player is an admin
|
||||
*
|
||||
* @param plexPlayer The PlexPlayer object
|
||||
* @return true if the player is an admin
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
protected boolean isAdmin(PlexPlayer plexPlayer)
|
||||
{
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a sender is an admin
|
||||
*
|
||||
* @param sender A command sender
|
||||
* @return true if the sender is an admin or if console
|
||||
*/
|
||||
protected boolean isAdmin(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
return plugin.getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a username is an admin
|
||||
*
|
||||
* @param name The username
|
||||
* @return true if the username is an admin
|
||||
*/
|
||||
protected boolean isAdmin(String name)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
|
||||
return plugin.getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a sender is a senior admin
|
||||
*
|
||||
* @param sender A command sender
|
||||
* @return true if the sender is a senior admin or if console
|
||||
*/
|
||||
protected boolean isSeniorAdmin(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
return plugin.getRankManager().isSeniorAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UUID of the sender
|
||||
*
|
||||
@ -682,11 +499,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
return PlexUtils.mmDeserialize(s);
|
||||
}
|
||||
|
||||
public Rank getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
public CommandMap getMap()
|
||||
{
|
||||
return Plex.get().getServer().getCommandMap();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@ -12,14 +11,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
/**
|
||||
* Minimum rank required
|
||||
*
|
||||
* @return Minimum rank required for the command
|
||||
* @see Rank
|
||||
*/
|
||||
Rank level() default Rank.IMPOSTOR;
|
||||
|
||||
/**
|
||||
* Required command source
|
||||
*
|
||||
|
@ -1,12 +0,0 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface System
|
||||
{
|
||||
String value() default "";
|
||||
|
||||
boolean debug() default false;
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.AdminAddEvent;
|
||||
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.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "admin", usage = "/<command> <add <player> | remove <player> | setrank <player> <rank> | list>", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
||||
@System(value = "ranks")
|
||||
public class AdminCMD extends PlexCommand
|
||||
{
|
||||
//TODO: Better return messages
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
return usage("/admin add <player>");
|
||||
}
|
||||
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
/*UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID != null)
|
||||
{
|
||||
PlexLog.debug("Admin Adding UUID: " + targetUUID);
|
||||
}*/
|
||||
|
||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
return messageComponent("playerIsAdmin");
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
||||
return null;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
return usage("/admin remove <player>");
|
||||
}
|
||||
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
return messageComponent("playerNotAdmin");
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("setrank"))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
return usage("/admin setrank <player> <rank>");
|
||||
}
|
||||
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
||||
if (!rankExists(args[2]))
|
||||
{
|
||||
return messageComponent("rankNotFound");
|
||||
}
|
||||
|
||||
Rank rank = Rank.valueOf(args[2].toUpperCase());
|
||||
|
||||
if (!rank.isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
return messageComponent("rankMustBeHigherThanAdmin");
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
return messageComponent("playerNotAdmin");
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage("/admin list");
|
||||
}
|
||||
|
||||
return componentFromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("add", "remove", "setrank", "list");
|
||||
}
|
||||
else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
|
||||
private boolean rankExists(String rank)
|
||||
{
|
||||
for (Rank ranks : Rank.values())
|
||||
{
|
||||
if (ranks.name().equalsIgnoreCase(rank))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import dev.plex.util.redis.MessageUtil;
|
||||
@ -20,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminchat", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
|
||||
public class AdminChatCMD extends PlexCommand
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -13,7 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
||||
public class AdminworldCMD extends PlexCommand
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -19,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
|
||||
public class AdventureCMD extends PlexCommand
|
||||
{
|
||||
@ -36,8 +35,7 @@ public class AdventureCMD extends PlexCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
||||
{
|
||||
checkPermission(sender, "plex.gamemode.adventure.others");
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
@ -51,14 +49,13 @@ public class AdventureCMD extends PlexCommand
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
||||
if (silentCheckPermission(sender, "plex.gamemode.adventure.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -24,10 +23,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class BanCMD extends PlexCommand
|
||||
{
|
||||
@ -48,22 +46,6 @@ public class BanCMD extends PlexCommand
|
||||
|
||||
Player player = Bukkit.getPlayer(plexPlayer.getUuid());
|
||||
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getPunishmentManager().isAsyncBanned(plexPlayer.getUuid()).whenComplete((aBoolean, throwable) ->
|
||||
{
|
||||
if (aBoolean)
|
||||
@ -87,7 +69,7 @@ public class BanCMD extends PlexCommand
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusDays(1));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
punishment.setActive(true);
|
||||
if (player != null)
|
||||
{
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
@ -110,6 +92,6 @@ public class BanCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.listener.impl.BlockListener;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -13,7 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.blockedit")
|
||||
@CommandPermissions(permission = "plex.blockedit")
|
||||
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
|
||||
public class BlockEditCMD extends PlexCommand
|
||||
{
|
||||
@ -63,7 +62,7 @@ public class BlockEditCMD extends PlexCommand
|
||||
int count = 0;
|
||||
for (final Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (!silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
||||
if (!silentCheckPermission(player, "plex.blockedit"))
|
||||
{
|
||||
bl.blockedPlayers.add(player.getName());
|
||||
++count;
|
||||
@ -76,7 +75,7 @@ public class BlockEditCMD extends PlexCommand
|
||||
final Player player = getNonNullPlayer(args[0]);
|
||||
if (!bl.blockedPlayers.contains(player.getName()))
|
||||
{
|
||||
if (silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
||||
if (silentCheckPermission(player, "plex.blockedit"))
|
||||
{
|
||||
send(sender, messageComponent("higherRankThanYou"));
|
||||
return null;
|
||||
|
@ -6,14 +6,13 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
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;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
|
||||
public class CommandSpyCMD extends PlexCommand
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -13,7 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||
@CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||
public class ConsoleSayCMD extends PlexCommand
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -19,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
|
||||
public class CreativeCMD extends PlexCommand
|
||||
{
|
||||
@ -39,8 +38,7 @@ public class CreativeCMD extends PlexCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
||||
{
|
||||
checkPermission(sender, "plex.gamemode.creative.others");
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
@ -56,13 +54,11 @@ public class CreativeCMD extends PlexCommand
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
||||
if (silentCheckPermission(sender, "plex.gamemode.creative.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@ -24,8 +22,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
||||
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
||||
@System(debug = true)
|
||||
@CommandPermissions(permission = "plex.debug")
|
||||
public class DebugCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -1,31 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "deopall", description = "Deop everyone on the server", aliases = "deopa")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
@System(value = "ranks")
|
||||
public class DeopAllCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
player.setOp(false);
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("deoppedAllPlayers", sender.getName()));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
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.util.List;
|
||||
|
||||
@CommandParameters(name = "deop", description = "Deop a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.deop")
|
||||
@System(value = "ranks")
|
||||
public class DeopCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
player.setOp(false);
|
||||
PlexUtils.broadcast(messageComponent("deoppedPlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [name]", aliases = "ew,rd")
|
||||
public class EntityWipeCMD extends PlexCommand
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||
public class FlatlandsCMD extends PlexCommand
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -21,7 +21,7 @@ import java.time.ZonedDateTime;
|
||||
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")
|
||||
@CommandPermissions(permission = "plex.freeze")
|
||||
public class FreezeCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
@ -39,19 +39,6 @@ public class FreezeCMD extends PlexCommand
|
||||
return messageComponent("playerFrozen");
|
||||
}
|
||||
|
||||
if (isAdmin(getPlexPlayer(player)))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()) && getPlexPlayer(player).isAdminActive())
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
@ -69,6 +56,6 @@ public class FreezeCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -21,7 +20,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||
public class GamemodeCMD extends PlexCommand
|
||||
{
|
||||
private GameMode gamemode;
|
||||
@ -62,14 +61,14 @@ public class GamemodeCMD extends PlexCommand
|
||||
case "spectator", "sp", "3", "6" ->
|
||||
{
|
||||
gamemode = GameMode.SPECTATOR;
|
||||
checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator");
|
||||
checkPermission(sender, "plex.gamemode.spectator");
|
||||
update(sender, playerSender, GameMode.SPECTATOR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (args.length > 1)
|
||||
{
|
||||
checkRank(sender, Rank.ADMIN, "plex.gamemode.others");
|
||||
checkPermission(sender, "plex.gamemode.others");
|
||||
Player player = getNonNullPlayer(args[1]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
|
||||
}
|
||||
|
@ -9,11 +9,10 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.BungeeUtil;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -24,10 +23,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||
public class KickCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -5,7 +5,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit,who,playerlist,online")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
||||
@CommandPermissions(permission = "plex.list")
|
||||
public class ListCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
@ -44,18 +44,11 @@ public class ListCMD extends PlexCommand
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player player = players.get(i);
|
||||
if (plugin.getSystem().equals("ranks"))
|
||||
{
|
||||
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
}
|
||||
else
|
||||
{
|
||||
Component prefix = VaultHook.getPrefix(getPlexPlayer(player));
|
||||
if (prefix != null && !prefix.equals(Component.empty()) && !prefix.equals(Component.space())) {
|
||||
list = list.append(prefix).append(Component.space());
|
||||
}
|
||||
list = list.append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
}
|
||||
if (i != players.size() - 1)
|
||||
{
|
||||
list = list.append(Component.text(",")).append(Component.space());
|
||||
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
||||
public class LocalSpawnCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -5,7 +5,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
|
||||
@CommandPermissions(permission = "plex.lockup")
|
||||
public class LockupCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
@ -29,19 +29,6 @@ public class LockupCMD extends PlexCommand
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
|
||||
if (isAdmin(getPlexPlayer(player)))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
|
||||
if (punishedPlayer.isLockedUp())
|
||||
{
|
||||
@ -54,6 +41,6 @@ public class LockupCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
public class MasterbuilderworldCMD extends PlexCommand
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp")
|
||||
public class MobPurgeCMD extends PlexCommand
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -21,7 +21,7 @@ import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute")
|
||||
@CommandPermissions(permission = "plex.mute")
|
||||
public class MuteCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
@ -39,7 +39,7 @@ public class MuteCMD extends PlexCommand
|
||||
return messageComponent("playerMuted");
|
||||
}
|
||||
|
||||
if (silentCheckRank(player, Rank.ADMIN, "plex.mute"))
|
||||
if (silentCheckPermission(player,"plex.mute"))
|
||||
{
|
||||
send(sender, messageComponent("higherRankThanYou"));
|
||||
return null;
|
||||
@ -62,6 +62,6 @@ public class MuteCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender,"plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import com.google.common.collect.Lists;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@ -18,7 +18,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
|
||||
@CommandPermissions(permission = "plex.namehistory")
|
||||
public class NameHistoryCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -6,8 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
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 dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -27,7 +26,7 @@ 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")
|
||||
@CommandPermissions(permission = "plex.notes")
|
||||
public class NotesCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
@ -48,8 +47,6 @@ public class NotesCMD extends PlexCommand
|
||||
switch (args[1].toLowerCase())
|
||||
{
|
||||
case "list":
|
||||
{
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
@ -60,16 +57,6 @@ public class NotesCMD extends PlexCommand
|
||||
}
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Note> notes = plexPlayer.getNotes();
|
||||
if (notes.size() == 0)
|
||||
{
|
||||
return messageComponent("noNotes");
|
||||
}
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
case "add":
|
||||
@ -83,14 +70,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);
|
||||
}
|
||||
return messageComponent("noteAdded");
|
||||
}
|
||||
}
|
||||
@ -109,8 +89,6 @@ public class NotesCMD extends PlexCommand
|
||||
{
|
||||
return messageComponent("unableToParseNumber", args[2]);
|
||||
}
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
boolean deleted = false;
|
||||
@ -129,40 +107,15 @@ public class NotesCMD extends PlexCommand
|
||||
}
|
||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
|
||||
{
|
||||
return messageComponent("removedNote", id);
|
||||
}
|
||||
return messageComponent("noteNotFound");
|
||||
}
|
||||
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;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return usage();
|
||||
|
@ -1,31 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "opall", description = "Op everyone on the server", aliases = "opa")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
@System(value = "ranks")
|
||||
public class OpAllCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
player.setOp(true);
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("oppedAllPlayers", sender.getName()));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
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.util.List;
|
||||
|
||||
@CommandParameters(name = "op", description = "Op a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
@System(value = "ranks")
|
||||
public class OpCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
player.setOp(true);
|
||||
PlexUtils.broadcast(messageComponent("oppedPlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.module.PlexModule;
|
||||
import dev.plex.module.PlexModuleFile;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.BuildInfo;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
@ -25,7 +24,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandPermissions(level = Rank.IMPOSTOR, source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
|
||||
public class PlexCMD extends PlexCommand
|
||||
{
|
||||
@ -45,7 +44,7 @@ public class PlexCMD extends PlexCommand
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
|
||||
checkPermission(sender, "plex.reload");
|
||||
plugin.config.load();
|
||||
send(sender, "Reloaded config file");
|
||||
plugin.messages.load();
|
||||
@ -55,10 +54,8 @@ public class PlexCMD extends PlexCommand
|
||||
send(sender, "Reloaded indefinite bans");
|
||||
plugin.commands.load();
|
||||
send(sender, "Reloaded blocked commands file");
|
||||
plugin.getRankManager().importDefaultRanks();
|
||||
send(sender, "Imported ranks");
|
||||
plugin.setSystem(plugin.config.getString("system"));
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
}
|
||||
@ -72,7 +69,7 @@ public class PlexCMD extends PlexCommand
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("redis"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis");
|
||||
checkPermission(sender, "plex.redis");
|
||||
if (!plugin.getRedisConnection().isEnabled())
|
||||
{
|
||||
throw new CommandFailException("&cRedis is not enabled.");
|
||||
@ -91,7 +88,7 @@ public class PlexCMD extends PlexCommand
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkRank(sender, Rank.EXECUTIVE, "plex.modules.reload");
|
||||
checkPermission(sender, "plex.modules.reload");
|
||||
plugin.getModuleManager().reloadModules();
|
||||
return mmString("<green>All modules reloaded!");
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.PunishmentMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
|
||||
public class PunishmentsCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -1,58 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
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.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.rank", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "rank", description = "Displays your rank")
|
||||
@System(value = "ranks")
|
||||
public class RankCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException("<red>When using the console, you must specify a player's rank.");
|
||||
}
|
||||
if (!(playerSender == null))
|
||||
{
|
||||
Rank rank = getPlexPlayer(playerSender).getRankFromString();
|
||||
return messageComponent("yourRank", rank.isAtLeast(Rank.ADMIN) && !getPlexPlayer(playerSender).isAdminActive() ? (playerSender.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
Rank rank = getPlexPlayer(player).getRankFromString();
|
||||
return messageComponent("otherRank", player.getName(), rank.isAtLeast(Rank.ADMIN) && !getPlexPlayer(player).isAdminActive() ? (player.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, permission = "plex.rawsay", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
||||
public class RawSayCMD extends PlexCommand
|
||||
{
|
||||
|
@ -6,14 +6,13 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
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;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
|
||||
public class RemoveLoginMessageCMD extends PlexCommand
|
||||
{
|
||||
@ -31,7 +30,7 @@ public class RemoveLoginMessageCMD extends PlexCommand
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("-o"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.removeloginmessage.others");
|
||||
checkPermission(sender, "plex.removeloginmessage.others");
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.say", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||
public class SayCMD extends PlexCommand
|
||||
{
|
||||
|
@ -7,8 +7,8 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,7 +16,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
|
||||
public class SetLoginMessageCMD extends PlexCommand
|
||||
{
|
||||
@ -34,7 +34,7 @@ public class SetLoginMessageCMD extends PlexCommand
|
||||
{
|
||||
if (args[0].equals("-o"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.setloginmessage.others");
|
||||
checkPermission(sender, "plex.setloginmessage.others");
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
@ -54,8 +54,7 @@ public class SetLoginMessageCMD extends PlexCommand
|
||||
validateMessage(message);
|
||||
plexPlayer.setLoginMessage(message);
|
||||
return messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
|
||||
message.replace("%player%", plexPlayer.getName())
|
||||
.replace("%rank%", plexPlayer.getRank()));
|
||||
message.replace("%player%", plexPlayer.getName()));
|
||||
}
|
||||
if (isConsole(sender))
|
||||
{
|
||||
@ -64,11 +63,11 @@ public class SetLoginMessageCMD extends PlexCommand
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
message = message.replace(plexPlayer.getName(), "%player%");
|
||||
message = PlexUtils.legacyToMiniString(message);
|
||||
validateMessage(message);
|
||||
plexPlayer.setLoginMessage(message);
|
||||
return messageComponent("setOwnLoginMessage",
|
||||
message.replace("%player%", plexPlayer.getName())
|
||||
.replace("%rank%", plexPlayer.getRank()));
|
||||
message.replace("%player%", plexPlayer.getName()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -80,10 +79,5 @@ public class SetLoginMessageCMD extends PlexCommand
|
||||
PlexLog.debug("Validating login message has a valid name in it");
|
||||
throw new CommandFailException(messageString("nameRequired"));
|
||||
}
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks") && rankRequired && !message.contains("%rank%"))
|
||||
{
|
||||
PlexLog.debug("Validating login message has a valid rank in it");
|
||||
throw new CommandFailException(messageString("rankRequired"));
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -28,7 +28,7 @@ import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.smite", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.smite", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
|
||||
public class SmiteCMD extends PlexCommand
|
||||
{
|
||||
@ -96,12 +96,6 @@ public class SmiteCMD extends PlexCommand
|
||||
send(sender, "Smitten " + player.getName() + " quietly.");
|
||||
}
|
||||
|
||||
// Deop
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
// Set gamemode to survival
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
@ -144,7 +138,7 @@ public class SmiteCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckRank(sender, Rank.ADMIN, "plex.smite") && args.length == 1)
|
||||
if (silentCheckPermission(sender,"plex.smite") && args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
|
||||
public class SpectatorCMD extends PlexCommand
|
||||
{
|
||||
@ -36,7 +36,7 @@ public class SpectatorCMD extends PlexCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
||||
if (checkPermission(sender,"plex.gamemode.spectator.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
@ -58,7 +58,7 @@ public class SpectatorCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
||||
if (silentCheckPermission(sender,"plex.gamemode.spectator.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode")
|
||||
public class SurvivalCMD extends PlexCommand
|
||||
{
|
||||
@ -36,7 +36,7 @@ public class SurvivalCMD extends PlexCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
||||
if (checkPermission(sender,"plex.gamemode.survival.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
@ -59,7 +59,7 @@ public class SurvivalCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
||||
if (silentCheckPermission(sender,"plex.gamemode.survival.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.inventory.Book;
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "totalfreedommod", description = "You can't simpy do that.", aliases = "tfm")
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
|
||||
public class TFMCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
if (playerSender != null)
|
||||
{
|
||||
String simpy = "It's not about credit or discredit, it's about copyright of TFM. Looking at Plex's source code, it looks like a bunch of copy-pasted source code from TFM and Aero (utility plugin). You just put it under a different license and pretended it's yours. You can't simpy do that. You have to remove all parts which infringe on the TFM license (as per the TFM repository) and the Aero License (as per the Aero repository) or otherwise comply to the license requirements.";
|
||||
List<String> pages = Splitter.fixedLength(256).splitToList(simpy);
|
||||
List<Component> pageComponents = new ArrayList<>();
|
||||
|
||||
for (String page : pages)
|
||||
{
|
||||
pageComponents.add(PlexUtils.mmDeserialize("<rainbow>" + page + "</rainbow>"));
|
||||
}
|
||||
|
||||
playerSender.openBook(Book.builder()
|
||||
.title(Component.text("TFM License"))
|
||||
.author(Component.text("Prozza"))
|
||||
.pages(pageComponents));
|
||||
}
|
||||
|
||||
return PlexUtils.mmDeserialize("<rainbow>It's not about credit or discredit, it's about copyright of TFM.<br>Looking at Plex's source code, it looks like a bunch of copy-pasted source code from TFM and Aero (utility plugin). You just put it under a different license and pretended it's yours.<br>You can't simpy do that. You have to remove all parts which infringe on the TFM license (as per the TFM repository) and the Aero License (as per the Aero repository) or otherwise comply to the license requirements.</rainbow>");
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -19,7 +19,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tag", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
|
||||
public class TagCMD extends PlexCommand
|
||||
{
|
||||
@ -47,7 +47,7 @@ public class TagCMD extends PlexCommand
|
||||
{
|
||||
return usage("/tag set <prefix>");
|
||||
}
|
||||
String prefix = PlexUtils.cleanString(StringUtils.join(args, " ", 1, args.length));
|
||||
String prefix = PlexUtils.legacyToMiniString(StringUtils.join(args, " ", 1, args.length));
|
||||
|
||||
Component convertedComponent = SafeMiniMessage.mmDeserializeWithoutEvents(prefix);
|
||||
|
||||
@ -80,7 +80,7 @@ public class TagCMD extends PlexCommand
|
||||
DataUtils.update(player);
|
||||
return messageComponent("prefixCleared");
|
||||
}
|
||||
checkRank(sender, Rank.ADMIN, "plex.tag.clear.others");
|
||||
checkPermission(sender,"plex.tag.clear.others");
|
||||
Player target = getNonNullPlayer(args[1]);
|
||||
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
|
||||
plexTarget.setPrefix(null);
|
||||
|
@ -10,7 +10,7 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.BungeeUtil;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
@ -27,7 +27,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class TempbanCMD extends PlexCommand
|
||||
{
|
||||
@ -50,19 +50,6 @@ public class TempbanCMD extends PlexCommand
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
Player player = Bukkit.getPlayer(targetUUID);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()) && plexPlayer.isAdminActive())
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isBanned(targetUUID))
|
||||
{
|
||||
return messageComponent("playerBanned");
|
||||
@ -81,7 +68,7 @@ public class TempbanCMD extends PlexCommand
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
punishment.setActive(true);
|
||||
if (player != null)
|
||||
{
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
@ -98,6 +85,6 @@ public class TempbanCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender,"plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.ToggleMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
||||
public class ToggleCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -9,7 +9,7 @@ import dev.plex.command.exception.PlayerNotBannedException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -22,7 +22,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class UnbanCMD extends PlexCommand
|
||||
{
|
||||
@ -61,6 +61,6 @@ public class UnbanCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender,"plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unfreeze")
|
||||
@CommandPermissions(permission = "plex.unfreeze")
|
||||
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
|
||||
public class UnfreezeCMD extends PlexCommand
|
||||
{
|
||||
@ -41,6 +41,6 @@ public class UnfreezeCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender,"plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unmute")
|
||||
@CommandPermissions(permission = "plex.unmute")
|
||||
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
|
||||
public class UnmuteCMD extends PlexCommand
|
||||
{
|
||||
@ -41,6 +41,6 @@ public class UnmuteCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && silentCheckPermission(sender,"plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -19,7 +19,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.world", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandPermissions(permission = "plex.world", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
|
||||
public class WorldCMD extends PlexCommand
|
||||
{
|
||||
@ -38,7 +38,7 @@ public class WorldCMD extends PlexCommand
|
||||
boolean playerWorld = args[0].matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
||||
if (playerWorld && Plex.get().getModuleManager().getModules().stream().anyMatch(plexModule -> plexModule.getPlexModuleFile().getName().equalsIgnoreCase("Module-TFMExtras")))
|
||||
{
|
||||
checkRank(playerSender, Rank.ADMIN, "plex.world.playerworlds");
|
||||
checkPermission(playerSender,"plex.world.playerworlds");
|
||||
}
|
||||
playerSender.teleportAsync(world.getSpawnLocation());
|
||||
return messageComponent("playerWorldTeleport", world.getName());
|
||||
@ -60,7 +60,7 @@ public class WorldCMD extends PlexCommand
|
||||
try
|
||||
{
|
||||
final UUID uuid = UUID.fromString(worldName);
|
||||
if (uuid.equals(player.getUniqueId()) || silentCheckRank(player, Rank.ADMIN, "plex.world.playerworlds"))
|
||||
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player,"plex.world.playerworlds"))
|
||||
{
|
||||
completions.add(worldName);
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Event that is run when a player is added to the admin list
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
public class AdminAddEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* The sender who added the player
|
||||
*/
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* The PlexPlayer that was added
|
||||
*/
|
||||
private final PlexPlayer plexPlayer;
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Event that is run when a player is removed from the admin list
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
public class AdminRemoveEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* The sender who added the player
|
||||
*/
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* The PlexPlayer that was removed
|
||||
*/
|
||||
private final PlexPlayer plexPlayer;
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Event that is run when an admins rank is set
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
public class AdminSetRankEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* The sender who added the player
|
||||
*/
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* The PlexPlayer that was removed
|
||||
*/
|
||||
private final PlexPlayer plexPlayer;
|
||||
|
||||
/**
|
||||
* The rank the player was set to
|
||||
*/
|
||||
private final Rank rank;
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package dev.plex.handlers;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.command.impl.DebugCMD;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
|
||||
@ -22,19 +22,10 @@ public class CommandHandler implements PlexBase
|
||||
{
|
||||
try
|
||||
{
|
||||
if (clazz.isAnnotationPresent(System.class))
|
||||
{
|
||||
System annotation = clazz.getDeclaredAnnotation(System.class);
|
||||
if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase()))
|
||||
if (plugin.config.getBoolean("debug") && DebugCMD.class.isAssignableFrom(clazz))
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
|
||||
if (plugin.config.getBoolean("debug") && annotation.debug())
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
|
@ -1,7 +1,9 @@
|
||||
package dev.plex.hook;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
@ -57,9 +59,9 @@ public class VaultHook
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (Plex.get().getRankManager().getConfigPrefixes(plexPlayer) != null)
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString()))
|
||||
{
|
||||
return Plex.get().getRankManager().getConfigPrefixes(plexPlayer);
|
||||
return PlexUtils.mmDeserialize("<dark_gray>[<dark_purple>Developer<dark_gray>]");
|
||||
}
|
||||
Player bukkitPlayer = Bukkit.getPlayer(plexPlayer.getUuid());
|
||||
String group = VaultHook.getPermission().getPrimaryGroup(bukkitPlayer);
|
||||
|
@ -1,55 +0,0 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.event.AdminAddEvent;
|
||||
import dev.plex.event.AdminRemoveEvent;
|
||||
import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import static dev.plex.util.PlexUtils.messageComponent;
|
||||
|
||||
public class AdminListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onAdminAdd(AdminAddEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
||||
}
|
||||
else
|
||||
{
|
||||
target.setRank(Rank.ADMIN.name());
|
||||
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.setAdminActive(false);
|
||||
DataUtils.update(target);
|
||||
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAdminSetRank(AdminSetRankEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
Rank newRank = event.getRank();
|
||||
target.setRank(newRank.name().toLowerCase());
|
||||
DataUtils.update(target);
|
||||
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.annotation.Toggleable;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
@ -15,6 +16,7 @@ import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -35,7 +37,7 @@ public class ChatListener extends PlexListener
|
||||
public static BiConsumer<AsyncChatEvent, PlexPlayer> PRE_RENDERER = ChatListener::defaultChatProcessing;
|
||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||
@ -46,7 +48,7 @@ public class ChatListener extends PlexListener
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
|
||||
Component prefix = PlayerMeta.getPrefix(plexPlayer);
|
||||
|
||||
if (prefix != null && !prefix.equals(Component.empty()) && !prefix.equals(Component.space()))
|
||||
{
|
||||
@ -100,7 +102,7 @@ public class ChatListener extends PlexListener
|
||||
|
||||
private static void defaultChatProcessing(AsyncChatEvent event, PlexPlayer plexPlayer)
|
||||
{
|
||||
String text = PlexUtils.cleanString(PlexUtils.getTextFromComponent(event.message()));
|
||||
String text = PlexUtils.legacyToMiniString(PlexUtils.getTextFromComponent(event.message()));
|
||||
event.message(SafeMiniMessage.mmDeserializeWithoutEvents(text));
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import dev.plex.cache.DataUtils;
|
||||
import dev.plex.command.blocking.BlockedCommand;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
import dev.plex.services.impl.CommandBlockerService;
|
||||
import dev.plex.util.PlexLog;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -108,7 +108,10 @@ public class CommandListener extends PlexListener
|
||||
if (cmdRef.get() != null)
|
||||
{
|
||||
BlockedCommand cmd = cmdRef.get();
|
||||
switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
//TODO: Look into removing this or fixing it so they require permissions instead
|
||||
/*switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
|
||||
{
|
||||
case "e" ->
|
||||
{
|
||||
@ -133,20 +136,12 @@ public class CommandListener extends PlexListener
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasCommandSpy(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
return plexPlayer.isAdminActive();
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return plexPlayer.getPlayer().hasPermission("plex.commandspy");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,8 @@ package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PermissionsUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -30,17 +29,6 @@ public class PlayerListener<T> extends PlexListener
|
||||
Player player = event.getPlayer();
|
||||
PlexPlayer plexPlayer;
|
||||
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
player.setOp(true);
|
||||
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
player.setOp(false);
|
||||
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
|
||||
}
|
||||
|
||||
if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
|
||||
{
|
||||
PlexLog.log("A player with this name has not joined the server before, creating new entry.");
|
||||
@ -74,49 +62,30 @@ public class PlayerListener<T> extends PlexListener
|
||||
player.openInventory(player.getInventory());
|
||||
}
|
||||
|
||||
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
|
||||
String loginMessage = PlayerMeta.getLoginMessage(plexPlayer);
|
||||
if (!loginMessage.isEmpty())
|
||||
{
|
||||
PlexUtils.broadcast(loginMessage);
|
||||
}
|
||||
|
||||
PermissionsUtil.setupPermissions(player);
|
||||
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plexPlayer.loadNotes();
|
||||
}
|
||||
|
||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
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())
|
||||
{
|
||||
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
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerSave(PlayerQuitEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
||||
|
||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
|
||||
}
|
||||
|
||||
DataUtils.update(plexPlayer);
|
||||
plugin.getPlayerCache().getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.event.AdminAddEvent;
|
||||
import dev.plex.event.AdminRemoveEvent;
|
||||
import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -19,42 +17,6 @@ public class TabListener extends PlexListener
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdminAdd(AdminAddEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdminRemove(AdminRemoveEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAdminSetRank(AdminSetRankEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
||||
player.playerListName(Component.text(player.getName()).color(PlayerMeta.getColor(plexPlayer)));
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,12 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.rank.enums.Title;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.type.Door;
|
||||
import org.bukkit.block.data.type.TrapDoor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -28,11 +18,9 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class WorldListener extends PlexListener
|
||||
{
|
||||
@ -139,47 +127,6 @@ public class WorldListener extends PlexListener
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkLevel(PlexPlayer player, String[] requiredList)
|
||||
{
|
||||
PlexLog.debug("Checking world required levels " + Arrays.toString(requiredList));
|
||||
boolean hasAccess = false;
|
||||
for (String required : requiredList)
|
||||
{
|
||||
PlexLog.debug("Checking if player has " + required);
|
||||
if (required.startsWith("Title"))
|
||||
{
|
||||
String titleString = required.split("\\.")[1];
|
||||
Title title = Title.valueOf(titleString.toUpperCase(Locale.ROOT));
|
||||
switch (title)
|
||||
{
|
||||
case DEV ->
|
||||
{
|
||||
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());
|
||||
}
|
||||
case OWNER ->
|
||||
{
|
||||
hasAccess = Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName());
|
||||
}
|
||||
default ->
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (required.startsWith("Rank"))
|
||||
{
|
||||
String rankString = required.split("\\.")[1];
|
||||
Rank rank = Rank.valueOf(rankString.toUpperCase(Locale.ROOT));
|
||||
hasAccess = rank.isAtLeast(Rank.ADMIN) ? player.isAdminActive() && player.getRankFromString().isAtLeast(rank) : player.getRankFromString().isAtLeast(rank);
|
||||
}
|
||||
}
|
||||
return hasAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Player has the ability to modify the world they are in
|
||||
*
|
||||
@ -189,10 +136,7 @@ public class WorldListener extends PlexListener
|
||||
*/
|
||||
private boolean canModifyWorld(Player player, boolean showMessage)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
||||
World world = player.getWorld();
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".modification.permission");
|
||||
if (permission == null)
|
||||
{
|
||||
@ -202,22 +146,6 @@ public class WorldListener extends PlexListener
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".modification.requiredLevels"))
|
||||
{
|
||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".modification.requiredLevels");
|
||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (showMessage)
|
||||
{
|
||||
@ -237,9 +165,6 @@ public class WorldListener extends PlexListener
|
||||
* @return Returns true if the person has the ability to enter the world
|
||||
*/
|
||||
private boolean canEnterWorld(Player player, World destination)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
String permission = plugin.config.getString("worlds." + destination.getName().toLowerCase() + ".entry.permission");
|
||||
if (permission == null)
|
||||
@ -250,22 +175,6 @@ public class WorldListener extends PlexListener
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (plugin.config.contains("worlds." + destination.getName().toLowerCase() + ".entry.requiredLevels"))
|
||||
{
|
||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + destination.getName().toLowerCase() + ".entry.requiredLevels");
|
||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String noEntry = plugin.config.getString("worlds." + destination.getName().toLowerCase() + ".entry.message");
|
||||
if (noEntry != null)
|
||||
|
61
server/src/main/java/dev/plex/meta/PlayerMeta.java
Normal file
61
server/src/main/java/dev/plex/meta/PlayerMeta.java
Normal file
@ -0,0 +1,61 @@
|
||||
package dev.plex.meta;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class PlayerMeta
|
||||
{
|
||||
|
||||
public static Component getPrefix(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty())
|
||||
{
|
||||
return SafeMiniMessage.mmDeserializeWithoutEvents(plexPlayer.getPrefix());
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return PlexUtils.mmDeserialize("<dark_gray>[<dark_purple>Developer<dark_gray>]");
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
return VaultHook.getPrefix(plexPlayer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getLoginMessage(PlexPlayer plexPlayer)
|
||||
{
|
||||
String prepend;
|
||||
// We don't want to prepend the "<player> is" if the login message is custom
|
||||
if (!plexPlayer.getLoginMessage().isEmpty())
|
||||
{
|
||||
return plexPlayer.getLoginMessage()
|
||||
.replace("%player%", plexPlayer.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
prepend = MiniMessage.miniMessage().serialize(Component.text(plexPlayer.getName() + " is ").color(NamedTextColor.AQUA));
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return prepend + "<aqua>a <dark_purple>Developer<reset>";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static NamedTextColor getColor(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return NamedTextColor.DARK_PURPLE;
|
||||
}
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package dev.plex.permission;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class Permission
|
||||
{
|
||||
private final UUID uuid;
|
||||
private final String permission;
|
||||
private boolean allowed = true;
|
||||
}
|
@ -2,25 +2,22 @@ package dev.plex.player;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.IndexOptions;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.permission.Permission;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.storage.annotation.MapObjectList;
|
||||
import dev.plex.storage.annotation.PrimaryKey;
|
||||
import dev.plex.storage.annotation.SQLTable;
|
||||
import dev.plex.storage.annotation.VarcharLimit;
|
||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
@ -28,18 +25,16 @@ import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity(value = "players", useDiscriminator = false)
|
||||
@SQLTable("players")
|
||||
public class PlexPlayer
|
||||
{
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Indexed(options = @IndexOptions(unique = true))
|
||||
@PrimaryKey
|
||||
@NotNull
|
||||
private UUID uuid;
|
||||
|
||||
@Indexed
|
||||
@VarcharLimit(16)
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
private String loginMessage;
|
||||
@ -58,14 +53,13 @@ public class PlexPlayer
|
||||
|
||||
private long coins;
|
||||
|
||||
private String rank;
|
||||
|
||||
private List<String> ips = Lists.newArrayList();
|
||||
private List<Punishment> punishments = Lists.newArrayList();
|
||||
private List<Note> notes = Lists.newArrayList();
|
||||
private List<Permission> permissions = Lists.newArrayList();
|
||||
|
||||
private transient PermissionAttachment permissionAttachment;
|
||||
@MapObjectList
|
||||
private List<Punishment> punishments = Lists.newArrayList();
|
||||
|
||||
@MapObjectList
|
||||
private List<Note> notes = Lists.newArrayList();
|
||||
|
||||
public PlexPlayer()
|
||||
{
|
||||
@ -74,9 +68,6 @@ public class PlexPlayer
|
||||
public PlexPlayer(UUID playerUUID, boolean loadExtraData)
|
||||
{
|
||||
this.uuid = playerUUID;
|
||||
|
||||
this.id = uuid.toString().substring(0, 8);
|
||||
|
||||
this.name = "";
|
||||
|
||||
this.loginMessage = "";
|
||||
@ -87,14 +78,10 @@ public class PlexPlayer
|
||||
|
||||
this.coins = 0;
|
||||
|
||||
this.rank = "";
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,41 +95,15 @@ public class PlexPlayer
|
||||
return PlainTextComponentSerializer.plainText().serialize(getPlayer().displayName());
|
||||
}
|
||||
|
||||
public Rank getRankFromString()
|
||||
{
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
if (rank.isEmpty() || !isAdminActive())
|
||||
{
|
||||
if (player.isOp())
|
||||
{
|
||||
return Rank.OP;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rank.NONOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
public void loadPunishments()
|
||||
{
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadNotes()
|
||||
{
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getSqlNotes().getNotes(this.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
|
@ -2,8 +2,8 @@ package dev.plex.punishment;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.storage.annotation.SQLTable;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
@ -11,17 +11,19 @@ import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@SQLTable("punishments")
|
||||
public class Punishment
|
||||
{
|
||||
private static final Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create();
|
||||
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
||||
@NotNull
|
||||
private final UUID punished;
|
||||
private final UUID punisher;
|
||||
private String ip;
|
||||
|
@ -102,18 +102,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(File file)
|
||||
{
|
||||
@ -159,16 +149,6 @@ public class PunishmentManager implements PlexBase
|
||||
}
|
||||
|
||||
public CompletableFuture<List<Punishment>> getActiveBans()
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
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<>();
|
||||
@ -181,7 +161,6 @@ public class PunishmentManager implements PlexBase
|
||||
});
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
||||
public void unban(Punishment punishment)
|
||||
{
|
||||
@ -189,22 +168,9 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
private void doPunishment(PlexPlayer player, Punishment punishment)
|
||||
{
|
||||
|
@ -1,7 +1,8 @@
|
||||
package dev.plex.punishment.extra;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.storage.annotation.NoLimit;
|
||||
import dev.plex.storage.annotation.SQLTable;
|
||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import lombok.Data;
|
||||
|
||||
@ -9,10 +10,12 @@ import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@SQLTable("notes")
|
||||
public class Note
|
||||
{
|
||||
private final UUID uuid;
|
||||
|
||||
@NoLimit
|
||||
private final String note;
|
||||
private final UUID writtenBy;
|
||||
private final ZonedDateTime timestamp;
|
||||
|
@ -1,199 +0,0 @@
|
||||
package dev.plex.rank;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.rank.enums.Title;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RankManager
|
||||
{
|
||||
private final File options;
|
||||
|
||||
public RankManager()
|
||||
{
|
||||
File ranksFolder = new File(Plex.get().getDataFolder() + File.separator + "ranks");
|
||||
if (!ranksFolder.exists())
|
||||
{
|
||||
ranksFolder.mkdir();
|
||||
}
|
||||
|
||||
options = new File(ranksFolder, "options.json");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void generateDefaultRanks()
|
||||
{
|
||||
if (options.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("ranks", new JSONArray().putAll(Arrays.stream(Rank.values()).map(Rank::toJSON).collect(Collectors.toList())));
|
||||
object.put("titles", new JSONArray().putAll(Arrays.stream(Title.values()).map(Title::toJSON).collect(Collectors.toList())));
|
||||
FileWriter writer = new FileWriter(options);
|
||||
writer.append(object.toString(4));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public Rank getRankFromString(String rank)
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
|
||||
public void importDefaultRanks()
|
||||
{
|
||||
if (!options.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(options))
|
||||
{
|
||||
JSONTokener tokener = new JSONTokener(fis);
|
||||
JSONObject object = new JSONObject(tokener);
|
||||
|
||||
JSONArray ranks = object.getJSONArray("ranks");
|
||||
ranks.forEach(r ->
|
||||
{
|
||||
JSONObject rank = new JSONObject(r.toString());
|
||||
String key = rank.keys().next();
|
||||
Rank.valueOf(key).setLoginMessage(rank.getJSONObject(key).getString("loginMessage"));
|
||||
Rank.valueOf(key).setPrefix(rank.getJSONObject(key).getString("prefix"));
|
||||
});
|
||||
|
||||
JSONArray titles = object.getJSONArray("titles");
|
||||
titles.forEach(t ->
|
||||
{
|
||||
JSONObject title = new JSONObject(t.toString());
|
||||
String key = title.keys().next();
|
||||
Title.valueOf(key).setLoginMessage(title.getJSONObject(key).getString("loginMessage"));
|
||||
Title.valueOf(key).setPrefix(title.getJSONObject(key).getString("prefix"));
|
||||
});
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Component getConfigPrefixes(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.OWNER.getPrefix();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return Title.DEV.getPrefix();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getPrefix();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
||||
{
|
||||
return plexPlayer.getRankFromString().getPrefix();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Component getPrefix(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty())
|
||||
{
|
||||
return SafeMiniMessage.mmDeserializeWithoutEvents(plexPlayer.getPrefix());
|
||||
}
|
||||
if (getConfigPrefixes(plexPlayer) != null)
|
||||
{
|
||||
return getConfigPrefixes(plexPlayer);
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault") && Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return VaultHook.getPrefix(plexPlayer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLoginMessage(PlexPlayer plexPlayer)
|
||||
{
|
||||
String prepend;
|
||||
// We don't want to prepend the "<player> is" if the login message is custom
|
||||
if (!plexPlayer.getLoginMessage().isEmpty())
|
||||
{
|
||||
return plexPlayer.getLoginMessage()
|
||||
.replace("%player%", plexPlayer.getName())
|
||||
.replace("%rank%", plexPlayer.getRank());
|
||||
}
|
||||
else
|
||||
{
|
||||
prepend = MiniMessage.miniMessage().serialize(Component.text(plexPlayer.getName() + " is ").color(NamedTextColor.AQUA));
|
||||
}
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
||||
{
|
||||
return prepend + Title.OWNER.getLoginMessage();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return prepend + Title.DEV.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
||||
{
|
||||
return prepend + Title.MASTER_BUILDER.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
||||
{
|
||||
return prepend + plexPlayer.getRankFromString().getLoginMessage();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public NamedTextColor getColor(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.OWNER.getColor();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return Title.DEV.getColor();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getColor();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
||||
{
|
||||
return plexPlayer.getRankFromString().getColor();
|
||||
}
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
public boolean isAdmin(PlexPlayer plexPlayer)
|
||||
{
|
||||
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) && plexPlayer.isAdminActive();
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Getter
|
||||
public enum Rank
|
||||
{
|
||||
IMPOSTOR(-1, "<aqua>an <yellow>Impostor<reset>", "Impostor", "<dark_gray>[<yellow>Imp<dark_gray>]", NamedTextColor.YELLOW),
|
||||
NONOP(0, "a <white>Non-Op<reset>", "Non-Op", "", NamedTextColor.WHITE),
|
||||
OP(1, "an <green>Op<reset>", "Operator", "<dark_gray>[<green>OP<dark_gray>]", NamedTextColor.GREEN),
|
||||
ADMIN(2, "an <dark_green>Admin<reset>", "Admin", "<dark_gray>[<green>Admin<dark_gray>]", NamedTextColor.DARK_GREEN),
|
||||
SENIOR_ADMIN(3, "a <gold>Senior Admin<reset>", "Senior Admin", "<dark_gray>[<gold>SrA<dark_gray>]", NamedTextColor.GOLD),
|
||||
EXECUTIVE(4, "an <red>Executive<reset>", "Executive", "<dark_gray>[<red>Exec<dark_gray>]", NamedTextColor.RED);
|
||||
|
||||
private final int level;
|
||||
@Getter
|
||||
private final NamedTextColor color;
|
||||
@Setter
|
||||
private String loginMessage;
|
||||
@Setter
|
||||
private String readable;
|
||||
@Setter
|
||||
private String prefix;
|
||||
|
||||
Rank(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
||||
{
|
||||
this.level = level;
|
||||
this.loginMessage = loginMessage;
|
||||
this.readable = readable;
|
||||
this.prefix = prefix;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public boolean isAtLeast(Rank rank)
|
||||
{
|
||||
return this.level >= rank.getLevel();
|
||||
}
|
||||
|
||||
public Component getPrefix()
|
||||
{
|
||||
return PlexUtils.mmDeserialize(this.prefix);
|
||||
}
|
||||
|
||||
public JSONObject toJSON()
|
||||
{
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("prefix", this.prefix);
|
||||
object.put("loginMessage", this.loginMessage);
|
||||
return new JSONObject().put(this.name(), object);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Getter
|
||||
public enum Title
|
||||
{
|
||||
MASTER_BUILDER(0, "<aqua>a <dark_aqua>Master Builder<reset>", "Master Builder", "<dark_gray>[<dark_aqua>Master Builder<dark_gray>]", NamedTextColor.DARK_AQUA),
|
||||
DEV(1, "<aqua>a <dark_purple>Developer<reset>", "Developer", "<dark_gray>[<dark_purple>Developer<dark_gray>]", NamedTextColor.DARK_PURPLE),
|
||||
OWNER(2, "<aqua>an <blue>Owner<reset>", "Owner", "<dark_gray>[<blue>Owner<dark_gray>]", NamedTextColor.BLUE);
|
||||
|
||||
private final int level;
|
||||
@Getter
|
||||
private final NamedTextColor color;
|
||||
@Setter
|
||||
private String loginMessage;
|
||||
@Setter
|
||||
private String readable;
|
||||
@Setter
|
||||
private String prefix;
|
||||
|
||||
Title(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
||||
{
|
||||
this.level = level;
|
||||
this.loginMessage = loginMessage;
|
||||
this.readable = readable;
|
||||
this.prefix = prefix;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Component getPrefix()
|
||||
{
|
||||
return PlexUtils.mmDeserialize(this.prefix);
|
||||
}
|
||||
|
||||
public JSONObject toJSON()
|
||||
{
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("prefix", this.prefix);
|
||||
object.put("loginMessage", this.loginMessage);
|
||||
return new JSONObject().put(this.name(), object);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Getter
|
||||
@ -62,6 +64,10 @@ public class SQLConnection implements PlexBase
|
||||
|
||||
try (Connection con = getCon())
|
||||
{
|
||||
if (tableExistsSQL("players"))
|
||||
{
|
||||
|
||||
}
|
||||
con.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (" +
|
||||
"`uuid` VARCHAR(46) NOT NULL, " +
|
||||
"`name` VARCHAR(18), " +
|
||||
@ -93,20 +99,6 @@ public class SQLConnection implements PlexBase
|
||||
"`note` VARCHAR(2000), " +
|
||||
"`timestamp` BIGINT" +
|
||||
");").execute();
|
||||
con.prepareStatement("CREATE TABLE IF NOT EXISTS `permissions` (" +
|
||||
"`uuid` VARCHAR(46) NOT NULL," +
|
||||
"`permission` VARCHAR(1000) NOT NULL," +
|
||||
"`allowed` BOOLEAN" +
|
||||
");").execute();
|
||||
// Plex 1.2
|
||||
|
||||
try
|
||||
{
|
||||
con.prepareStatement("ALTER TABLE `players` ADD COLUMN `staffChat` BOOLEAN DEFAULT false;").execute();
|
||||
}
|
||||
catch (SQLException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
@ -114,6 +106,26 @@ public class SQLConnection implements PlexBase
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tableExistsSQL(String tableName) throws SQLException
|
||||
{
|
||||
try (Connection connection = getCon())
|
||||
{
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT count(*) "
|
||||
+ "FROM information_schema.tables "
|
||||
+ "WHERE table_name = ?"
|
||||
+ "LIMIT 1;");
|
||||
preparedStatement.setString(1, tableName);
|
||||
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
resultSet.next();
|
||||
return resultSet.getInt(1) != 0;
|
||||
}
|
||||
catch (SQLException ignored)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getCon()
|
||||
{
|
||||
if (this.dataSource == null)
|
||||
|
@ -2,5 +2,5 @@ package dev.plex.storage;
|
||||
|
||||
public enum StorageType
|
||||
{
|
||||
MONGODB, MARIADB, SQLITE
|
||||
MARIADB, SQLITE
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package dev.plex.storage.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 1:42 AM [25-08-2023]
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface MapObjectList
|
||||
{
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package dev.plex.storage.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 1:42 AM [25-08-2023]
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface NoLimit
|
||||
{
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package dev.plex.storage.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 1:42 AM [25-08-2023]
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface PrimaryKey
|
||||
{
|
||||
boolean dontSet() default false;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package dev.plex.storage.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 4:27 AM [25-08-2023]
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface SQLTable
|
||||
{
|
||||
String value();
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package dev.plex.storage.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 1:42 AM [25-08-2023]
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface VarcharLimit
|
||||
{
|
||||
int value();
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package dev.plex.storage.codec;
|
||||
|
||||
import org.bson.BsonReader;
|
||||
import org.bson.BsonWriter;
|
||||
import org.bson.codecs.Codec;
|
||||
import org.bson.codecs.DecoderContext;
|
||||
import org.bson.codecs.EncoderContext;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import static dev.plex.util.TimeUtils.TIMEZONE;
|
||||
|
||||
public class ZonedDateTimeCodec implements Codec<ZonedDateTime>
|
||||
{
|
||||
@Override
|
||||
public ZonedDateTime decode(BsonReader reader, DecoderContext decoderContext)
|
||||
{
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(reader.readDateTime()), ZoneId.of(TIMEZONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(BsonWriter writer, ZonedDateTime value, EncoderContext encoderContext)
|
||||
{
|
||||
writer.writeDateTime(value.toInstant().toEpochMilli());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ZonedDateTime> getEncoderClass()
|
||||
{
|
||||
return ZonedDateTime.class;
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package dev.plex.storage.permission;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.permission.Permission;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SQLPermissions
|
||||
{
|
||||
private static final String SELECT = "SELECT * FROM `permissions` WHERE uuid=?";
|
||||
private static final String INSERT = "INSERT INTO `permissions` (`uuid`, `permission`, `allowed`) VALUES(?, ?, ?)";
|
||||
private static final String REMOVE_PERMISSION = "DELETE FROM `permissions` WHERE uuid=? AND permission=?";
|
||||
private static final String UPDATE_PERMISSION = "UPDATE `permissions` SET allowed=? WHERE uuid=? AND permission=?";
|
||||
|
||||
public List<Permission> getPermissions(UUID uuid)
|
||||
{
|
||||
List<Permission> permissions = Lists.newArrayList();
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next())
|
||||
{
|
||||
Permission permission = new Permission(UUID.fromString(set.getString("uuid")), set.getString("permission"));
|
||||
permission.setAllowed(set.getBoolean("allowed"));
|
||||
permissions.add(permission);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void addPermission(Permission permission)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(INSERT);
|
||||
statement.setString(1, permission.getUuid().toString());
|
||||
statement.setString(2, permission.getPermission().toLowerCase(Locale.ROOT));
|
||||
statement.setBoolean(3, permission.isAllowed());
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePermission(Permission permission, boolean newValue)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(UPDATE_PERMISSION);
|
||||
statement.setBoolean(1, newValue);
|
||||
statement.setString(2, permission.getUuid().toString());
|
||||
statement.setString(3, permission.getPermission().toLowerCase(Locale.ROOT));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void removePermission(Permission permission)
|
||||
{
|
||||
this.removePermission(permission.getUuid(), permission.getPermission());
|
||||
}
|
||||
|
||||
public void removePermission(UUID uuid, String permission)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(REMOVE_PERMISSION);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, permission.toLowerCase(Locale.ROOT));
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -86,7 +86,6 @@ public class SQLPlayerData
|
||||
String name = set.getString("name");
|
||||
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");
|
||||
@ -97,7 +96,6 @@ public class SQLPlayerData
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
@ -135,7 +133,6 @@ public class SQLPlayerData
|
||||
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(set.getString("uuid")), loadExtraData);
|
||||
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");
|
||||
@ -146,7 +143,6 @@ public class SQLPlayerData
|
||||
plexPlayer.setName(username);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
@ -211,7 +207,6 @@ public class SQLPlayerData
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
@ -257,7 +252,6 @@ public class SQLPlayerData
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
@ -288,7 +282,7 @@ public class SQLPlayerData
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, player.getLoginMessage());
|
||||
statement.setString(3, player.getPrefix());
|
||||
statement.setString(4, player.getRank().toLowerCase());
|
||||
statement.setString(4, null); // rank
|
||||
statement.setBoolean(5, player.isAdminActive());
|
||||
statement.setString(6, new Gson().toJson(player.getIps()));
|
||||
statement.setLong(7, player.getCoins());
|
||||
@ -318,7 +312,7 @@ public class SQLPlayerData
|
||||
statement.setString(2, player.getName());
|
||||
statement.setString(3, player.getLoginMessage());
|
||||
statement.setString(4, player.getPrefix());
|
||||
statement.setString(5, player.getRank().toLowerCase());
|
||||
statement.setString(5, null); //rank
|
||||
statement.setBoolean(6, player.isAdminActive());
|
||||
statement.setString(7, new Gson().toJson(player.getIps()));
|
||||
statement.setLong(8, player.getCoins());
|
||||
|
@ -1,65 +0,0 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.permission.Permission;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PermissionsUtil
|
||||
{
|
||||
public static void setupPermissions(@NotNull Player player)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
PermissionAttachment attachment = player.addAttachment(Plex.get());
|
||||
plexPlayer.getPermissions().forEach(permission -> attachment.setPermission(permission.getPermission(), permission.isAllowed()));
|
||||
plexPlayer.setPermissionAttachment(attachment);
|
||||
}
|
||||
|
||||
public static void addPermission(PlexPlayer player, Permission permission)
|
||||
{
|
||||
Plex.get().getSqlPermissions().addPermission(PlexUtils.addToArrayList(player.getPermissions(), permission));
|
||||
Player p = Bukkit.getPlayer(player.getUuid());
|
||||
if (p == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getPermissionAttachment().setPermission(permission.getPermission(), permission.isAllowed());
|
||||
}
|
||||
|
||||
public static void addPermission(PlexPlayer player, String permission)
|
||||
{
|
||||
addPermission(player, new Permission(player.getUuid(), permission));
|
||||
}
|
||||
|
||||
public static void removePermission(PlexPlayer player, String permission)
|
||||
{
|
||||
Plex.get().getSqlPermissions().removePermission(player.getUuid(), permission);
|
||||
player.getPermissions().removeIf(permission1 -> permission1.getPermission().equalsIgnoreCase(permission));
|
||||
Player p = Bukkit.getPlayer(player.getUuid());
|
||||
if (p == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getPermissionAttachment().unsetPermission(permission);
|
||||
}
|
||||
|
||||
public static void updatePermission(PlexPlayer player, String permission, boolean newValue)
|
||||
{
|
||||
player.getPermissions().stream().filter(permission1 -> permission.equalsIgnoreCase(permission)).findFirst().ifPresent(permission1 ->
|
||||
{
|
||||
Plex.get().getSqlPermissions().updatePermission(permission1, newValue);
|
||||
});
|
||||
player.getPermissions().removeIf(permission1 -> permission1.getPermission().equalsIgnoreCase(permission));
|
||||
Player p = Bukkit.getPlayer(player.getUuid());
|
||||
if (p == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getPermissionAttachment().unsetPermission(permission);
|
||||
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ public class PlexLog
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (strings[i] == null) continue;
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
@ -30,6 +31,7 @@ public class PlexLog
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (strings[i] == null) continue;
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
@ -42,6 +44,7 @@ public class PlexLog
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (strings[i] == null) continue;
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
@ -56,6 +59,7 @@ public class PlexLog
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (strings[i] == null) continue;
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
|
@ -5,8 +5,6 @@ import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.listener.impl.ChatListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -28,6 +26,7 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -90,26 +89,23 @@ 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!");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFolia() {
|
||||
try {
|
||||
public static boolean isFolia()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("io.papermc.paper.threadedregions.ThreadedRegionizer");
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -136,6 +132,45 @@ public class PlexUtils implements PlexBase
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Component removeHoverAndClick(Component component)
|
||||
{
|
||||
Stack<Component> components = new Stack<>();
|
||||
components.push(component);
|
||||
while (!components.isEmpty())
|
||||
{
|
||||
Component curr = components.pop();
|
||||
curr.clickEvent(null).hoverEvent(null);
|
||||
curr.children().forEach(components::push);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
public static String legacyToMiniString(String input)
|
||||
{
|
||||
return cleanString(input.replace("&a", "<green>")
|
||||
.replace("&b", "<aqua>")
|
||||
.replace("&c", "<red>")
|
||||
.replace("&d", "<light_purple>")
|
||||
.replace("&e", "<yellow>")
|
||||
.replace("&f", "<white>")
|
||||
.replace("&1", "<dark_blue>")
|
||||
.replace("&2", "<dark_green>")
|
||||
.replace("&3", "<dark_aqua>")
|
||||
.replace("&4", "<dark_red>")
|
||||
.replace("&5", "<dark_purple>")
|
||||
.replace("&6", "<gold>")
|
||||
.replace("&7", "<gray>")
|
||||
.replace("&8", "<dark_gray>")
|
||||
.replace("&9", "<blue>")
|
||||
.replace("&0", "<black>")
|
||||
.replace("&r", "<reset>")
|
||||
.replace("&l", "<bold>")
|
||||
.replace("&o", "<italic>")
|
||||
.replace("&n", "<underlined>")
|
||||
.replace("&m", "<strikethrough>")
|
||||
.replace("&k", "<obf>"));
|
||||
}
|
||||
|
||||
public static String mmStripColor(String input)
|
||||
{
|
||||
return PlainTextComponentSerializer.plainText().serialize(mmDeserialize(input));
|
||||
@ -241,9 +276,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);
|
||||
});
|
||||
@ -258,24 +293,12 @@ public class PlexUtils implements PlexBase
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
|
||||
{
|
||||
player.sendMessage(messageComponent("adminChatFormat", senderName, message).replaceText(ChatListener.URL_REPLACEMENT_CONFIG));
|
||||
sent.add(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (player.hasPermission("plex.adminchat"))
|
||||
{
|
||||
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", senderName, message).replaceText(ChatListener.URL_REPLACEMENT_CONFIG));
|
||||
sent.add(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,13 @@ package dev.plex.util;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -54,4 +58,14 @@ public class ReflectionsUtil
|
||||
});
|
||||
return Collections.unmodifiableSet(classes);
|
||||
}
|
||||
|
||||
public static Class<?> getGenericField(Field field)
|
||||
{
|
||||
Type type = field.getGenericType();
|
||||
if (type instanceof ParameterizedType parameterizedType)
|
||||
{
|
||||
return TypeToken.of(parameterizedType.getActualTypeArguments()[0]).getRawType();
|
||||
}
|
||||
return field.getType();
|
||||
}
|
||||
}
|
||||
|
186
server/src/main/java/dev/plex/util/sql/SQLUtil.java
Normal file
186
server/src/main/java/dev/plex/util/sql/SQLUtil.java
Normal file
@ -0,0 +1,186 @@
|
||||
package dev.plex.util.sql;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.storage.annotation.*;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 4:28 AM [25-08-2023]
|
||||
*/
|
||||
public class SQLUtil
|
||||
{
|
||||
public static final List<Table> TABLES = Lists.newArrayList();
|
||||
|
||||
public static List<String> createTable(List<String> result, Class<?> clazz)
|
||||
{
|
||||
if (!clazz.isAnnotationPresent(SQLTable.class))
|
||||
{
|
||||
PlexLog.error("Unable to map {0} to a table, it is missing the SQLTable's annotation", clazz.getName());
|
||||
return null;
|
||||
}
|
||||
final List<Field> collectionFields = Lists.newArrayList();
|
||||
|
||||
final Table table = new Table(clazz.getAnnotation(SQLTable.class).value());
|
||||
|
||||
final StringBuilder mainResult = new StringBuilder("CREATE TABLE IF NOT EXISTS `" + table.name() + "` (");
|
||||
final List<Field> declaredFields = Arrays.stream(clazz.getDeclaredFields()).filter(field -> !Modifier.isTransient(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())).collect(Collectors.toList());
|
||||
final List<Field> iterating = declaredFields.stream().toList();
|
||||
for (Field value : iterating)
|
||||
{
|
||||
if (Collection.class.isAssignableFrom(value.getType()))
|
||||
{
|
||||
collectionFields.add(value);
|
||||
declaredFields.remove(value);
|
||||
}
|
||||
}
|
||||
Field primaryKey = null;
|
||||
|
||||
for (int i = 0; i < declaredFields.size(); i++)
|
||||
{
|
||||
Field declaredField = declaredFields.get(i);
|
||||
final Mapper mapped = Mapper.getByClass(declaredField.getType());
|
||||
if (mapped == null)
|
||||
{
|
||||
PlexLog.warn("Could not map field {0} for class {1}", declaredField.getName(), clazz.getName());
|
||||
continue;
|
||||
}
|
||||
if (declaredField.isAnnotationPresent(PrimaryKey.class))
|
||||
{
|
||||
if (primaryKey != null)
|
||||
{
|
||||
PlexLog.error("You can only have one primary key for a table! The class {0} has more than one!", clazz.getName());
|
||||
return ImmutableList.of();
|
||||
}
|
||||
primaryKey = declaredField;
|
||||
}
|
||||
|
||||
writeFieldToSQL(table, mainResult, mapped, declaredField);
|
||||
if (i < declaredFields.size() - 1)
|
||||
{
|
||||
mainResult.append(", ");
|
||||
}
|
||||
}
|
||||
if (primaryKey != null && !primaryKey.getAnnotation(PrimaryKey.class).dontSet())
|
||||
{
|
||||
mainResult.append(", PRIMARY KEY (`").append(primaryKey.getName()).append("`)");
|
||||
}
|
||||
mainResult.append(");");
|
||||
result.add(mainResult.toString());
|
||||
|
||||
TABLES.add(table);
|
||||
|
||||
if (primaryKey == null && !collectionFields.isEmpty())
|
||||
{
|
||||
PlexLog.error("You must define a primary key to point to if you wish to have a list saved. You can use @PrimaryKey(dontSet = true) to make sure that SQL does not save it as a primary key.");
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
Field finalPrimaryKey = primaryKey;
|
||||
collectionFields.forEach(field ->
|
||||
{
|
||||
final String tableName = field.getName() + "To" + StringUtils.capitalize(clazz.getSimpleName());
|
||||
StringBuilder sql = new StringBuilder("CREATE TABLE IF NOT EXISTS `" + tableName + "` (");
|
||||
if (field.isAnnotationPresent(MapObjectList.class))
|
||||
{
|
||||
createTable(result, ReflectionsUtil.getGenericField(field));
|
||||
return;
|
||||
}
|
||||
final Mapper mapped = Mapper.getByClass(ReflectionsUtil.getGenericField(field));
|
||||
if (mapped == null)
|
||||
{
|
||||
PlexLog.warn("Could not map collection field {0} for class {1}", field.getName(), clazz.getName());
|
||||
return;
|
||||
}
|
||||
final Table listTable = new Table(tableName);
|
||||
writeFieldToSQL(listTable, sql, mapped, field);
|
||||
sql.append(", ");
|
||||
writeFieldToSQL(listTable, sql, Mapper.getByClass(finalPrimaryKey.getType()), finalPrimaryKey);
|
||||
sql.append(");");
|
||||
result.add(sql.toString());
|
||||
table.mappedTables().add(listTable);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void writeFieldToSQL(Table table, StringBuilder sb, Mapper mapped, Field field)
|
||||
{
|
||||
|
||||
sb.append("`").append(field.getName()).append("` ");
|
||||
if (mapped == Mapper.VARCHAR)
|
||||
{
|
||||
if (field.isAnnotationPresent(NoLimit.class))
|
||||
{
|
||||
sb.append("TEXT");
|
||||
table.columns().put(field.getName(), Mapper.TEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(mapped.name());
|
||||
table.columns().put(field.getName(), mapped);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(mapped.name());
|
||||
table.columns().put(field.getName(), mapped);
|
||||
}
|
||||
if (mapped == Mapper.VARCHAR && !field.isAnnotationPresent(NoLimit.class))
|
||||
{
|
||||
if (UUID.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
sb.append(" (").append(36).append(")");
|
||||
}
|
||||
else if (field.isAnnotationPresent(VarcharLimit.class))
|
||||
{
|
||||
int limit = field.getAnnotation(VarcharLimit.class).value();
|
||||
sb.append(" (").append(limit).append(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append("(65535)");
|
||||
}
|
||||
}
|
||||
if (field.isAnnotationPresent(NotNull.class))
|
||||
{
|
||||
sb.append(" NOT NULL");
|
||||
}
|
||||
}
|
||||
|
||||
@Accessors(fluent = true)
|
||||
public enum Mapper
|
||||
{
|
||||
VARCHAR(String.class, UUID.class, PunishmentType.class),
|
||||
BOOLEAN(Boolean.class, boolean.class),
|
||||
BIGINT(Long.class, long.class, ZonedDateTime.class),
|
||||
INT(Integer.class, int.class),
|
||||
TEXT;
|
||||
|
||||
private final Class<?>[] clazz;
|
||||
|
||||
Mapper(Class<?>... clazz)
|
||||
{
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public static Mapper getByClass(Class<?> clazz)
|
||||
{
|
||||
return Arrays.stream(values()).filter(mapper -> mapper.clazz != null && Arrays.asList(mapper.clazz).contains(clazz)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
}
|
23
server/src/main/java/dev/plex/util/sql/Table.java
Normal file
23
server/src/main/java/dev/plex/util/sql/Table.java
Normal file
@ -0,0 +1,23 @@
|
||||
package dev.plex.util.sql;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 5:30 AM [26-08-2023]
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
public class Table
|
||||
{
|
||||
private final String name;
|
||||
private final Map<String, SQLUtil.Mapper> columns = Maps.newHashMap();
|
||||
private final List<Table> mappedTables = Lists.newArrayList();
|
||||
}
|
@ -10,11 +10,6 @@ server:
|
||||
# What timezone should various messages appear in (e.g. ban message end date)
|
||||
timezone: Etc/UTC
|
||||
|
||||
titles:
|
||||
masterbuilders: [ ]
|
||||
owners:
|
||||
- Telesphoreo
|
||||
|
||||
# Ban message is customized in the messages.yml file. The URL to appeal at is below.
|
||||
banning:
|
||||
ban_url: "https://forum.plex.us.org"
|
||||
@ -29,21 +24,14 @@ chat:
|
||||
# Color tag for name color
|
||||
name-color: '<white>'
|
||||
|
||||
# Should Plex use a "true op" system with ranks or only permission nodes
|
||||
# Options are "permissions" or "ranks"
|
||||
# NOTE: If you are using a proxy such as BungeeCord or Velocity, it is highly recommended to use permissions
|
||||
system: ranks
|
||||
|
||||
# Login Messages
|
||||
loginmessages:
|
||||
# Should the player be required to put their name in the login message?
|
||||
name: true
|
||||
# If ranks are enabled, should the player be required to put their rank in the login message?
|
||||
rank: true
|
||||
|
||||
data:
|
||||
central:
|
||||
storage: sqlite # Use mariadb, mongodb, or sqlite here
|
||||
storage: sqlite # Use mariadb, or sqlite here
|
||||
user: ""
|
||||
password: ""
|
||||
hostname: 127.0.0.1
|
||||
@ -193,15 +181,9 @@ worlds:
|
||||
name: "Admin World"
|
||||
entry:
|
||||
permission: "plex.world.adminworld.enter"
|
||||
# Minimum rank requirement
|
||||
requiredLevels:
|
||||
- "Rank.ADMIN"
|
||||
message: "<red>You do not have permission to enter this world."
|
||||
modification:
|
||||
permission: "plex.world.adminworld.modify"
|
||||
# Minimum rank requirement
|
||||
requiredLevels:
|
||||
- "Rank.ADMIN"
|
||||
message: "<red>You do not have permission to modify this world."
|
||||
gameRules:
|
||||
- "doWeatherCycle;false"
|
||||
@ -215,14 +197,9 @@ worlds:
|
||||
name: "MasterBuilder World"
|
||||
entry:
|
||||
permission: "plex.world.masterbuilderworld.enter"
|
||||
requiredLevels:
|
||||
- "Rank.OP"
|
||||
message: "<red>You do not have permission to enter this world."
|
||||
modification:
|
||||
permission: "plex.world.masterbuilderworld.modify"
|
||||
requiredLevels:
|
||||
# Title has no "minimum", so this will have to be their title
|
||||
- "Title.MASTER_BUILDER"
|
||||
message: "<red>You do not have permission to modify this world."
|
||||
gameRules:
|
||||
- "doWeatherCycle;false"
|
||||
|
Loading…
Reference in New Issue
Block a user