mirror of
https://github.com/plexusorg/Plex.git
synced 2025-06-12 15:43:55 +00:00
Move Plex to API-driven plugin and fix NoClassDefFoundError on startup
This commit is contained in:
250
server/src/main/java/dev/plex/Plex.java
Normal file
250
server/src/main/java/dev/plex/Plex.java
Normal file
@ -0,0 +1,250 @@
|
||||
package dev.plex;
|
||||
|
||||
import dev.plex.admin.Admin;
|
||||
import dev.plex.admin.AdminList;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.handlers.CommandHandler;
|
||||
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.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.UpdateChecker;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import java.io.File;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
{
|
||||
private static Plex plugin;
|
||||
|
||||
public Config config;
|
||||
public Config messages;
|
||||
public Config indefBans;
|
||||
public Config commands;
|
||||
|
||||
public File modulesFolder;
|
||||
private StorageType storageType = StorageType.SQLITE;
|
||||
|
||||
public static final BuildInfo build = new BuildInfo();
|
||||
|
||||
private SQLConnection sqlConnection;
|
||||
private MongoConnection mongoConnection;
|
||||
private RedisConnection redisConnection;
|
||||
|
||||
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;
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
plugin = this;
|
||||
config = new Config(this, "config.yml");
|
||||
messages = new Config(this, "messages.yml");
|
||||
indefBans = new Config(this, "indefbans.yml");
|
||||
commands = new Config(this, "commands.yml");
|
||||
build.load(this);
|
||||
|
||||
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
||||
if (!modulesFolder.exists())
|
||||
{
|
||||
modulesFolder.mkdir();
|
||||
}
|
||||
|
||||
moduleManager = new ModuleManager();
|
||||
moduleManager.loadAllModules();
|
||||
moduleManager.loadModules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
config.load();
|
||||
messages.load();
|
||||
// Don't add default entries to indefinite ban file
|
||||
indefBans.load(false);
|
||||
commands.load(false);
|
||||
|
||||
sqlConnection = new SQLConnection();
|
||||
mongoConnection = new MongoConnection();
|
||||
redisConnection = new RedisConnection();
|
||||
|
||||
moduleManager.enableModules();
|
||||
|
||||
system = config.getString("system");
|
||||
|
||||
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db"));
|
||||
try
|
||||
{
|
||||
PlexUtils.testConnections();
|
||||
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (system.equalsIgnoreCase("permissions") && !getServer().getPluginManager().isPluginEnabled("Vault") && !setupPermissions())
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
}
|
||||
|
||||
updateChecker = new UpdateChecker();
|
||||
PlexLog.log("Update checking enabled");
|
||||
|
||||
// https://bstats.org/plugin/bukkit/Plex/14143
|
||||
Metrics metrics = new Metrics(this, 14143);
|
||||
PlexLog.log("Enabled Metrics");
|
||||
|
||||
if (redisConnection != null && redisConnection.isEnabled())
|
||||
{
|
||||
redisConnection.getJedis();
|
||||
PlexLog.log("Connected to Redis!");
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
|
||||
generateWorlds();
|
||||
|
||||
serviceManager = new ServiceManager();
|
||||
PlexLog.log("Service Manager initialized");
|
||||
serviceManager.startServices();
|
||||
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
|
||||
|
||||
reloadPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
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())
|
||||
{
|
||||
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!");
|
||||
redisConnection.getJedis().close();
|
||||
}
|
||||
|
||||
moduleManager.disableModules();
|
||||
}
|
||||
|
||||
private void generateWorlds()
|
||||
{
|
||||
PlexLog.log("Generating any worlds if needed...");
|
||||
for (String key : config.getConfigurationSection("worlds").getKeys(false))
|
||||
{
|
||||
CustomWorld.generateConfigFlatWorld(key);
|
||||
}
|
||||
PlexLog.log("Finished with world generation!");
|
||||
}
|
||||
|
||||
private void reloadPlayers()
|
||||
{
|
||||
Bukkit.getOnlinePlayers().forEach(player ->
|
||||
{
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean setupPermissions()
|
||||
{
|
||||
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
|
||||
permissions = rsp.getProvider();
|
||||
return permissions != null;
|
||||
}
|
||||
}
|
6
server/src/main/java/dev/plex/PlexBase.java
Normal file
6
server/src/main/java/dev/plex/PlexBase.java
Normal file
@ -0,0 +1,6 @@
|
||||
package dev.plex;
|
||||
|
||||
public interface PlexBase
|
||||
{
|
||||
Plex plugin = Plex.get();
|
||||
}
|
55
server/src/main/java/dev/plex/admin/Admin.java
Normal file
55
server/src/main/java/dev/plex/admin/Admin.java
Normal file
@ -0,0 +1,55 @@
|
||||
package dev.plex.admin;
|
||||
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
150
server/src/main/java/dev/plex/admin/AdminList.java
Normal file
150
server/src/main/java/dev/plex/admin/AdminList.java
Normal file
@ -0,0 +1,150 @@
|
||||
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;
|
||||
}
|
||||
}
|
142
server/src/main/java/dev/plex/cache/DataUtils.java
vendored
Normal file
142
server/src/main/java/dev/plex/cache/DataUtils.java
vendored
Normal file
@ -0,0 +1,142 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Parent cache class
|
||||
*/
|
||||
public class DataUtils
|
||||
{
|
||||
/**
|
||||
* Checks if the player has been on the server before
|
||||
*
|
||||
* @param uuid The unique ID of the player
|
||||
* @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
|
||||
*
|
||||
* @param uuid The unique ID of the player
|
||||
* @return a PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static PlexPlayer getPlayer(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
{
|
||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoPlayerData().getByUUID(uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plex.get().getSqlPlayerData().getByUUID(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static PlexPlayer getPlayer(String username)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoPlayerData().getByName(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plex.get().getSqlPlayerData().getByName(username);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player from cache or from the database
|
||||
*
|
||||
* @param ip The IP address of the player.
|
||||
* @return a PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static PlexPlayer getPlayerByIP(String ip)
|
||||
{
|
||||
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
|
||||
if (player != null)
|
||||
{
|
||||
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
|
||||
*
|
||||
* @param plexPlayer The PlexPlayer to update
|
||||
* @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
|
||||
*
|
||||
* @param plexPlayer The PlexPlayer to insert
|
||||
* @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 */
|
||||
|
||||
}
|
46
server/src/main/java/dev/plex/cache/PlayerCache.java
vendored
Normal file
46
server/src/main/java/dev/plex/cache/PlayerCache.java
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Cache storage
|
||||
*/
|
||||
|
||||
public class PlayerCache
|
||||
{
|
||||
/**
|
||||
* A key/value pair where the key is the unique ID of the Plex Player
|
||||
*/
|
||||
private static final Map<UUID, PlexPlayer> plexPlayerMap = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* A key/value pair where the key is the unique ID of the Punished Player
|
||||
*/
|
||||
// private static final Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
|
||||
|
||||
// public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
|
||||
// {
|
||||
// return punishedPlayerMap;
|
||||
// }
|
||||
public static Map<UUID, PlexPlayer> getPlexPlayerMap()
|
||||
{
|
||||
return plexPlayerMap;
|
||||
}
|
||||
|
||||
/*public static PunishedPlayer getPunishedPlayer(UUID uuid)
|
||||
{
|
||||
if (!getPunishedPlayerMap().containsKey(uuid))
|
||||
{
|
||||
getPunishedPlayerMap().put(uuid, new PunishedPlayer(uuid));
|
||||
}
|
||||
return getPunishedPlayerMap().get(uuid);
|
||||
}
|
||||
*/
|
||||
public static PlexPlayer getPlexPlayer(UUID uuid)
|
||||
{
|
||||
return getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
}
|
624
server/src/main/java/dev/plex/command/PlexCommand.java
Normal file
624
server/src/main/java/dev/plex/command/PlexCommand.java
Normal file
@ -0,0 +1,624 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotBannedException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Superclass for all commands
|
||||
*/
|
||||
public abstract class PlexCommand extends Command implements PluginIdentifiableCommand
|
||||
{
|
||||
/**
|
||||
* Returns the instance of the plugin
|
||||
*/
|
||||
protected static Plex plugin = Plex.get();
|
||||
|
||||
/**
|
||||
* The parameters for the command
|
||||
*/
|
||||
private final CommandParameters params;
|
||||
|
||||
/**
|
||||
* The permissions for the command
|
||||
*/
|
||||
private final CommandPermissions perms;
|
||||
|
||||
/**
|
||||
* Minimum required rank fetched from the permissions
|
||||
*/
|
||||
private final Rank level;
|
||||
|
||||
/**
|
||||
* Required command source fetched from the permissions
|
||||
*/
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
/**
|
||||
* Creates an instance of the command
|
||||
*/
|
||||
public PlexCommand()
|
||||
{
|
||||
super("");
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
|
||||
setName(this.params.name());
|
||||
setLabel(this.params.name());
|
||||
setDescription(params.description());
|
||||
setUsage(params.usage().replace("<command>", this.params.name()));
|
||||
if (params.aliases().split(",").length > 0)
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
}
|
||||
this.level = perms.level();
|
||||
this.commandSource = perms.source();
|
||||
|
||||
getMap().register("plex", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the command
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param playerSender The player who executed the command (null if CommandSource is console or if CommandSource is any but console executed)
|
||||
* @param args A Kyori Component to send to the sender (can be null)
|
||||
*/
|
||||
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args)
|
||||
{
|
||||
if (!matches(label))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
sender.sendMessage(messageComponent("noPermissionInGame"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.IN_GAME)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionConsole"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
|
||||
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 (!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 (!plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getUuid()), 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);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
}
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException |
|
||||
ConsoleMustDefinePlayerException | PlayerNotBannedException | NumberFormatException ex)
|
||||
{
|
||||
send(sender, PlexUtils.mmDeserialize(ex.getMessage()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the String given is a matching command
|
||||
*
|
||||
* @param label The String to check
|
||||
* @return true if the string is a command name or alias
|
||||
*/
|
||||
private boolean matches(String label)
|
||||
{
|
||||
if (params.aliases().split(",").length > 0)
|
||||
{
|
||||
for (String alias : params.aliases().split(","))
|
||||
{
|
||||
if (alias.equalsIgnoreCase(label) || getName().equalsIgnoreCase(label))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (params.aliases().split(",").length < 1)
|
||||
{
|
||||
return getName().equalsIgnoreCase(label);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a PlexPlayer from Player object
|
||||
*
|
||||
* @param player The player object
|
||||
* @return PlexPlayer Object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
protected PlexPlayer getPlexPlayer(@NotNull Player player)
|
||||
{
|
||||
return DataUtils.getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to an Audience
|
||||
*
|
||||
* @param audience The Audience to send the message to
|
||||
* @param s The message to send
|
||||
*/
|
||||
protected void send(Audience audience, String s)
|
||||
{
|
||||
audience.sendMessage(componentFromString(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to an Audience
|
||||
*
|
||||
* @param audience The Audience to send the message to
|
||||
* @param component The Component to send
|
||||
*/
|
||||
protected void send(Audience audience, Component component)
|
||||
{
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean checkRank(CommandSender sender, Rank rank, String permission)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkRank((Player)sender, rank, 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 (!plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getUuid()), permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean checkRank(Player player, Rank rank, String permission)
|
||||
{
|
||||
if (player instanceof ConsoleCommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
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 (!player.hasPermission(permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean silentCheckRank(Player player, Rank rank, String permission)
|
||||
{
|
||||
if (player instanceof ConsoleCommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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"))
|
||||
{
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a sender has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param sender 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)
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean checkTab(CommandSender sender, Rank rank, String permission)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkTab((Player)sender, rank, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @return true if the sender has enough permissions
|
||||
* @see Rank
|
||||
*/
|
||||
protected boolean checkTab(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"))
|
||||
{
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
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
|
||||
*
|
||||
* @param sender A command sender
|
||||
* @return A unique ID or null if the sender is console
|
||||
* @see UUID
|
||||
*/
|
||||
protected UUID getUUID(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin
|
||||
*
|
||||
* @return The instance of the plugin
|
||||
* @see Plex
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Plex getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a sender is console
|
||||
*
|
||||
* @param sender A command sender
|
||||
* @return true if the sender is console
|
||||
*/
|
||||
protected boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a message entry from the "messages.yml" to a Component
|
||||
*
|
||||
* @param s The message entry
|
||||
* @param objects Any objects to replace in order
|
||||
* @return A Kyori Component
|
||||
*/
|
||||
protected Component messageComponent(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a message entry from the "messages.yml" to a String
|
||||
*
|
||||
* @param s The message entry
|
||||
* @param objects Any objects to replace in order
|
||||
* @return A String
|
||||
*/
|
||||
protected String messageString(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageString(s, objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts usage to a Component
|
||||
*
|
||||
* @return A Kyori Component stating the usage
|
||||
*/
|
||||
protected Component usage()
|
||||
{
|
||||
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(this.getUsage()).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts usage to a Component
|
||||
* <p>
|
||||
* s The usage to convert
|
||||
*
|
||||
* @return A Kyori Component stating the usage
|
||||
*/
|
||||
protected Component usage(String s)
|
||||
{
|
||||
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(s).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
protected PlexPlayer getOnlinePlexPlayer(String name)
|
||||
{
|
||||
Player player = getNonNullPlayer(name);
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId());
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
protected PlexPlayer getOfflinePlexPlayer(UUID uuid)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(uuid);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
protected World getNonNullWorld(String name)
|
||||
{
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("worldNotFound"));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a legacy Kyori Component
|
||||
*
|
||||
* @param s The String to convert
|
||||
* @return A Kyori component
|
||||
*/
|
||||
protected Component componentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
|
||||
}
|
||||
|
||||
protected Component noColorComponentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a MiniMessage Component
|
||||
*
|
||||
* @param s The String to convert
|
||||
* @return A Kyori Component
|
||||
*/
|
||||
protected Component mmString(String s)
|
||||
{
|
||||
return PlexUtils.mmDeserialize(s);
|
||||
}
|
||||
|
||||
public Rank getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
public CommandMap getMap()
|
||||
{
|
||||
return Plex.get().getServer().getCommandMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Storage for a command's parameters
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
/**
|
||||
* The name
|
||||
*
|
||||
* @return Name of the command
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* The description
|
||||
*
|
||||
* @return Description of the command
|
||||
*/
|
||||
String description() default "";
|
||||
|
||||
/**
|
||||
* The usage (optional)
|
||||
*
|
||||
* @return The usage of the command
|
||||
*/
|
||||
String usage() default "/<command>";
|
||||
|
||||
/**
|
||||
* The aliases (optional)
|
||||
*
|
||||
* @return The aliases of the command
|
||||
*/
|
||||
String aliases() default "";
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Storage for the command's permissions
|
||||
*/
|
||||
@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
|
||||
*
|
||||
* @return The required command source of the command
|
||||
* @see RequiredCommandSource
|
||||
*/
|
||||
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||
|
||||
/**
|
||||
* The permission
|
||||
*
|
||||
* @return Permission of the command
|
||||
*/
|
||||
String permission() default ""; // No idea what to put here
|
||||
}
|
12
server/src/main/java/dev/plex/command/annotation/System.java
Normal file
12
server/src/main/java/dev/plex/command/annotation/System.java
Normal file
@ -0,0 +1,12 @@
|
||||
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;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package dev.plex.command.blocking;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@Data
|
||||
public class BlockedCommand
|
||||
{
|
||||
private Component message;
|
||||
private String requiredLevel;
|
||||
private String regex;
|
||||
private String command;
|
||||
private List<String> commandAliases = Lists.newArrayList();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
public class CommandFailException extends RuntimeException // this is literally just a runtime exception lol
|
||||
{
|
||||
public CommandFailException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
import static dev.plex.util.PlexUtils.messageString;
|
||||
|
||||
public class ConsoleMustDefinePlayerException extends RuntimeException
|
||||
{
|
||||
public ConsoleMustDefinePlayerException()
|
||||
{
|
||||
super(messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
import static dev.plex.util.PlexUtils.messageString;
|
||||
|
||||
public class ConsoleOnlyException extends RuntimeException
|
||||
{
|
||||
public ConsoleOnlyException()
|
||||
{
|
||||
super(messageString("consoleOnly"));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
import static dev.plex.util.PlexUtils.messageString;
|
||||
|
||||
public class PlayerNotBannedException extends RuntimeException
|
||||
{
|
||||
public PlayerNotBannedException()
|
||||
{
|
||||
super(messageString("playerNotBanned"));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
import static dev.plex.util.PlexUtils.messageString;
|
||||
|
||||
public class PlayerNotFoundException extends RuntimeException
|
||||
{
|
||||
public PlayerNotFoundException()
|
||||
{
|
||||
super(messageString("playerNotFound"));
|
||||
}
|
||||
}
|
186
server/src/main/java/dev/plex/command/impl/AdminCMD.java
Normal file
186
server/src/main/java/dev/plex/command/impl/AdminCMD.java
Normal file
@ -0,0 +1,186 @@
|
||||
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.api.event.AdminAddEvent;
|
||||
import dev.plex.api.event.AdminRemoveEvent;
|
||||
import dev.plex.api.event.AdminSetRankEvent;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.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;
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
57
server/src/main/java/dev/plex/command/impl/AdminChatCMD.java
Normal file
57
server/src/main/java/dev/plex/command/impl/AdminChatCMD.java
Normal file
@ -0,0 +1,57 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.cache.PlayerCache;
|
||||
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.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.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;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, 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
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
adminChat(sender, StringUtils.join(args, " "));
|
||||
return null;
|
||||
}
|
||||
|
||||
private void adminChat(CommandSender sender, String message)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
|
||||
{
|
||||
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (player.hasPermission("plex.adminchat"))
|
||||
{
|
||||
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
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.adminworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
||||
public class AdminworldCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
assert playerSender != null;
|
||||
// TODO: Add adminworld settings
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0);
|
||||
playerSender.teleportAsync(loc);
|
||||
return messageComponent("teleportedToWorld", "adminworld");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
66
server/src/main/java/dev/plex/command/impl/AdventureCMD.java
Normal file
66
server/src/main/java/dev/plex/command/impl/AdventureCMD.java
Normal file
@ -0,0 +1,66 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.api.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "adventure", aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
|
||||
public class AdventureCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.ADVENTURE);
|
||||
messageComponent("gameModeSetTo", "adventure");
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "adventure"));
|
||||
return null;
|
||||
}
|
||||
|
||||
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 (checkTab(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
117
server/src/main/java/dev/plex/command/impl/BanCMD.java
Normal file
117
server/src/main/java/dev/plex/command/impl/BanCMD.java
Normal file
@ -0,0 +1,117 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.Plex;
|
||||
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.exception.PlayerNotFoundException;
|
||||
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.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.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;
|
||||
|
||||
@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)
|
||||
|
||||
public class BanCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
Player player = Bukkit.getPlayer(targetUUID);
|
||||
|
||||
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(targetUUID).whenComplete((aBoolean, throwable) ->
|
||||
{
|
||||
if (aBoolean)
|
||||
{
|
||||
send(sender, messageComponent("playerBanned"));
|
||||
return;
|
||||
}
|
||||
String reason;
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
punishment.setReason(reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusDays(1));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
if (player != null)
|
||||
{
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
}
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
Bukkit.getScheduler().runTask(Plex.get(), () ->
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
player.kick(Punishment.generateBanMessage(punishment));
|
||||
}
|
||||
});
|
||||
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid());
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
98
server/src/main/java/dev/plex/command/impl/BlockEditCMD.java
Normal file
98
server/src/main/java/dev/plex/command/impl/BlockEditCMD.java
Normal file
@ -0,0 +1,98 @@
|
||||
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.listener.impl.BlockListener;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
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.blockedit")
|
||||
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
|
||||
public class BlockEditCMD extends PlexCommand
|
||||
{
|
||||
private final BlockListener bl = new BlockListener();
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
send(sender, "The following have block modification abilities restricted:");
|
||||
int count = 0;
|
||||
for (String player : bl.blockedPlayers.stream().toList())
|
||||
{
|
||||
send(sender, "- " + player);
|
||||
++count;
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
send(sender, "- none");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
PlexUtils.broadcast(componentFromString(sender.getName() + " - Unblocking block modification abilities for all players").color(NamedTextColor.AQUA));
|
||||
int count = 0;
|
||||
for (String player : bl.blockedPlayers.stream().toList())
|
||||
{
|
||||
if (bl.blockedPlayers.contains(player))
|
||||
{
|
||||
bl.blockedPlayers.remove(player);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return messageComponent("unblockedEditsSize", count);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("all"))
|
||||
{
|
||||
PlexUtils.broadcast(componentFromString(sender.getName() + " - Blocking block modification abilities for all non-admins").color(NamedTextColor.RED));
|
||||
int count = 0;
|
||||
for (final Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (!silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
||||
{
|
||||
bl.blockedPlayers.add(player.getName());
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return messageComponent("blockedEditsSize", count);
|
||||
}
|
||||
|
||||
final Player player = getNonNullPlayer(args[0]);
|
||||
if (!bl.blockedPlayers.contains(player.getName()))
|
||||
{
|
||||
if (silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
||||
{
|
||||
send(sender, messageComponent("higherRankThanYou"));
|
||||
return null;
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("blockingEditFor", sender.getName(), player.getName()));
|
||||
bl.blockedPlayers.add(player.getName());
|
||||
send(player, messageComponent("yourEditsHaveBeenBlocked"));
|
||||
send(sender, messageComponent("editsBlocked", player.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("unblockingEditFor", sender.getName(), player.getName()));
|
||||
bl.blockedPlayers.remove(player.getName());
|
||||
send(player, messageComponent("yourEditsHaveBeenUnblocked"));
|
||||
send(sender, messageComponent("editsUnblocked", player.getName()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
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.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)
|
||||
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
|
||||
public class CommandSpyCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
if (playerSender != null)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(playerSender.getUniqueId());
|
||||
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
|
||||
DataUtils.update(plexPlayer);
|
||||
send(sender, messageComponent("toggleCommandSpy")
|
||||
.append(Component.space())
|
||||
.append(plexPlayer.isCommandSpy() ? messageComponent("enabled") : messageComponent("disabled")));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||
public class ConsoleSayCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
return null;
|
||||
}
|
||||
}
|
70
server/src/main/java/dev/plex/command/impl/CreativeCMD.java
Normal file
70
server/src/main/java/dev/plex/command/impl/CreativeCMD.java
Normal file
@ -0,0 +1,70 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.api.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "creative", aliases = "gmc", description = "Set your own or another player's gamemode to creative mode")
|
||||
public class CreativeCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
if (!(playerSender == null))
|
||||
{
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender.getPlayer(), GameMode.CREATIVE));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||
messageComponent("gameModeSetTo", "creative");
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "creative"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
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 (checkTab(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
83
server/src/main/java/dev/plex/command/impl/DebugCMD.java
Normal file
83
server/src/main/java/dev/plex/command/impl/DebugCMD.java
Normal file
@ -0,0 +1,83 @@
|
||||
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.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@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)
|
||||
public class DebugCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("redis-reset"))
|
||||
{
|
||||
Player player = getNonNullPlayer(args[1]);
|
||||
if (plugin.getRedisConnection().getJedis().exists(player.getUniqueId().toString()))
|
||||
{
|
||||
plugin.getRedisConnection().getJedis().del(player.getUniqueId().toString());
|
||||
return componentFromString("Successfully reset " + player.getName() + "'s Redis punishments!").color(NamedTextColor.YELLOW);
|
||||
}
|
||||
return componentFromString("Couldn't find player in Redis punishments.");
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("gamerules"))
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
GameRuleUtil.commitGlobalGameRules(world);
|
||||
PlexLog.log("Set global gamerules for world: " + world.getName());
|
||||
}
|
||||
for (String world : plugin.config.getConfigurationSection("worlds").getKeys(false))
|
||||
{
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld != null)
|
||||
{
|
||||
GameRuleUtil.commitSpecificGameRules(bukkitWorld);
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
return mmString("<aqua>Re-applied game all the game rules!");
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("aliases"))
|
||||
{
|
||||
String commandName = args[1];
|
||||
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
|
||||
if (command == null)
|
||||
{
|
||||
return mmString("<red>That command could not be found!");
|
||||
}
|
||||
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
31
server/src/main/java/dev/plex/command/impl/DeopAllCMD.java
Normal file
31
server/src/main/java/dev/plex/command/impl/DeopAllCMD.java
Normal file
@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
40
server/src/main/java/dev/plex/command/impl/DeopCMD.java
Normal file
40
server/src/main/java/dev/plex/command/impl/DeopCMD.java
Normal file
@ -0,0 +1,40 @@
|
||||
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 java.util.List;
|
||||
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;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
103
server/src/main/java/dev/plex/command/impl/EntityWipeCMD.java
Normal file
103
server/src/main/java/dev/plex/command/impl/EntityWipeCMD.java
Normal file
@ -0,0 +1,103 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, 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
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
List<String> entityBlacklist = plugin.config.getStringList("entitywipe_list");
|
||||
|
||||
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
||||
|
||||
EntityType[] entityTypes = EntityType.values();
|
||||
entityWhitelist.removeIf(name ->
|
||||
{
|
||||
boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> name.equalsIgnoreCase(entityType.name()));
|
||||
if (res)
|
||||
{
|
||||
sender.sendMessage(messageComponent("invalidEntityType", name));
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
boolean useBlacklist = args.length == 0;
|
||||
|
||||
HashMap<String, Integer> entityCounts = new HashMap<>();
|
||||
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
String type = entity.getType().name();
|
||||
|
||||
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
|
||||
{
|
||||
entity.remove();
|
||||
|
||||
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum();
|
||||
|
||||
if (useBlacklist)
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("removedEntities", sender.getName(), entityCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entityCount == 0)
|
||||
{
|
||||
sender.sendMessage(messageComponent("noRemovedEntities"));
|
||||
return null;
|
||||
}
|
||||
String list = String.join(", ", entityCounts.keySet());
|
||||
list = list.replaceAll("(, )(?!.*\1)", (list.indexOf(", ") == list.lastIndexOf(", ") ? "" : ",") + " and ");
|
||||
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
List<String> entities = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
entities.add(entity.getType().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities.stream().toList();
|
||||
}
|
||||
}
|
32
server/src/main/java/dev/plex/command/impl/FlatlandsCMD.java
Normal file
32
server/src/main/java/dev/plex/command/impl/FlatlandsCMD.java
Normal file
@ -0,0 +1,32 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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)
|
||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||
public class FlatlandsCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
assert playerSender != null;
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0);
|
||||
playerSender.teleportAsync(loc);
|
||||
return messageComponent("teleportedToWorld", "flatlands");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
74
server/src/main/java/dev/plex/command/impl/FreezeCMD.java
Normal file
74
server/src/main/java/dev/plex/command/impl/FreezeCMD.java
Normal file
@ -0,0 +1,74 @@
|
||||
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.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
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;
|
||||
|
||||
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
|
||||
public class FreezeCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = getPlexPlayer(player);
|
||||
|
||||
if (punishedPlayer.isFrozen())
|
||||
{
|
||||
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));
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
punishment.setReason("");
|
||||
|
||||
plugin.getPunishmentManager().punish(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("frozePlayer", 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 && checkTab(sender, Rank.ADMIN, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
103
server/src/main/java/dev/plex/command/impl/GamemodeCMD.java
Normal file
103
server/src/main/java/dev/plex/command/impl/GamemodeCMD.java
Normal file
@ -0,0 +1,103 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.api.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm, egamemode, egamemode")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||
public class GamemodeCMD extends PlexCommand
|
||||
{
|
||||
private GameMode gamemode;
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "creative", "c", "1" ->
|
||||
{
|
||||
gamemode = GameMode.CREATIVE;
|
||||
update(sender, playerSender, GameMode.CREATIVE);
|
||||
return null;
|
||||
}
|
||||
case "survival", "s", "0" ->
|
||||
{
|
||||
gamemode = GameMode.SURVIVAL;
|
||||
update(sender, playerSender, GameMode.SURVIVAL);
|
||||
return null;
|
||||
}
|
||||
case "adventure", "a", "2" ->
|
||||
{
|
||||
gamemode = GameMode.ADVENTURE;
|
||||
update(sender, playerSender, GameMode.ADVENTURE);
|
||||
return null;
|
||||
}
|
||||
case "default", "d", "5" ->
|
||||
{
|
||||
gamemode = plugin.getServer().getDefaultGameMode();
|
||||
update(sender, playerSender, plugin.getServer().getDefaultGameMode());
|
||||
return null;
|
||||
}
|
||||
case "spectator", "sp", "3", "6" ->
|
||||
{
|
||||
gamemode = GameMode.SPECTATOR;
|
||||
checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator");
|
||||
update(sender, playerSender, GameMode.SPECTATOR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (args.length > 1)
|
||||
{
|
||||
checkRank(sender, Rank.ADMIN, "plex.gamemode.others");
|
||||
Player player = getNonNullPlayer(args[1]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void update(CommandSender sender, Player playerSender, GameMode gameMode)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
if (!(playerSender == null))
|
||||
{
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender.getPlayer(), gameMode));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("creative", "survival", "adventure", "spectator", "default");
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
71
server/src/main/java/dev/plex/command/impl/KickCMD.java
Normal file
71
server/src/main/java/dev/plex/command/impl/KickCMD.java
Normal file
@ -0,0 +1,71 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
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.exception.PlayerNotFoundException;
|
||||
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 dev.plex.util.WebUtils;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.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;
|
||||
|
||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||
public class KickCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
String reason = "No reason provided";
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
Player player = Bukkit.getPlayer(targetUUID);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.KICK);
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
punishment.setReason(reason);
|
||||
}
|
||||
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(false);
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
||||
player.kick(componentFromString(reason));
|
||||
return null;
|
||||
}
|
||||
}
|
55
server/src/main/java/dev/plex/command/impl/ListCMD.java
Normal file
55
server/src/main/java/dev/plex/command/impl/ListCMD.java
Normal file
@ -0,0 +1,55 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
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.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
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 = "list", description = "Show a list of all online players", aliases = "lsit")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
||||
@System(value = "ranks")
|
||||
public class ListCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
|
||||
Component list = Component.empty();
|
||||
Component header = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY)
|
||||
.append(Component.space())
|
||||
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
|
||||
.append(Component.space())
|
||||
.append(Component.text(players.size() == 1 ? "player" : "players").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(Component.text("online out of").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
|
||||
.append(Component.space())
|
||||
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
|
||||
send(sender, header);
|
||||
if (players.size() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player player = players.get(i);
|
||||
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
if (i != players.size() - 1)
|
||||
{
|
||||
list = list.append(Component.text(",")).append(Component.space());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
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.source.RequiredCommandSource;
|
||||
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;
|
||||
|
||||
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.spawnpoint", source = RequiredCommandSource.IN_GAME)
|
||||
public class LocalSpawnCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
assert playerSender != null;
|
||||
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
|
||||
return messageComponent("teleportedToWorldSpawn");
|
||||
}
|
||||
}
|
54
server/src/main/java/dev/plex/command/impl/LockupCMD.java
Normal file
54
server/src/main/java/dev/plex/command/impl/LockupCMD.java
Normal file
@ -0,0 +1,54 @@
|
||||
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.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
|
||||
public class LockupCMD 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]);
|
||||
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());
|
||||
PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedPlayer", 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 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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)
|
||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
public class MasterbuilderworldCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
assert playerSender != null;
|
||||
// TODO: Add masterbuilderworld settings
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("masterbuilderworld"), 0, 50, 0);
|
||||
playerSender.teleportAsync(loc);
|
||||
return messageComponent("teleportedToWorld", "Master Builder World");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
52
server/src/main/java/dev/plex/command/impl/MobPurgeCMD.java
Normal file
52
server/src/main/java/dev/plex/command/impl/MobPurgeCMD.java
Normal file
@ -0,0 +1,52 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.HashMap;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp")
|
||||
public class MobPurgeCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
HashMap<String, Integer> entityCounts = new HashMap<>();
|
||||
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity instanceof Mob)
|
||||
{
|
||||
String type = entity.getType().name();
|
||||
entity.remove();
|
||||
|
||||
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum();
|
||||
|
||||
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), entityCount));
|
||||
|
||||
/*entityCounts.forEach((entityName, numRemoved) -> {
|
||||
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
|
||||
});*/
|
||||
return null;
|
||||
}
|
||||
}
|
74
server/src/main/java/dev/plex/command/impl/MuteCMD.java
Normal file
74
server/src/main/java/dev/plex/command/impl/MuteCMD.java
Normal file
@ -0,0 +1,74 @@
|
||||
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.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
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;
|
||||
|
||||
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute")
|
||||
public class MuteCMD 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]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
|
||||
if (punishedPlayer.isMuted())
|
||||
{
|
||||
return messageComponent("playerMuted");
|
||||
}
|
||||
|
||||
if (isAdmin(getPlexPlayer(player)))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.MUTE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
punishment.setReason("");
|
||||
|
||||
plugin.getPunishmentManager().punish(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("mutedPlayer", 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 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.AshconInfo;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
|
||||
public class NameHistoryCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
String username = args[0];
|
||||
|
||||
AshconInfo info = MojangUtils.getInfo(username);
|
||||
if (info == null)
|
||||
{
|
||||
return messageComponent("nameHistoryDoesntExist");
|
||||
}
|
||||
PlexLog.debug("NameHistory UUID: " + info.getUuid());
|
||||
PlexLog.debug("NameHistory Size: " + info.getUsernameHistories().length);
|
||||
List<Component> historyList = Lists.newArrayList();
|
||||
Arrays.stream(info.getUsernameHistories()).forEach(history ->
|
||||
{
|
||||
if (history.getZonedDateTime() != null)
|
||||
{
|
||||
historyList.add(
|
||||
messageComponent("nameHistoryBody",
|
||||
history.getUsername(),
|
||||
TimeUtils.useTimezone(history.getZonedDateTime())));
|
||||
}
|
||||
else
|
||||
{
|
||||
historyList.add(
|
||||
Component.text(history.getUsername()).color(NamedTextColor.GOLD)
|
||||
.append(Component.space()));
|
||||
}
|
||||
});
|
||||
send(sender, messageComponent("nameHistoryTitle", username));
|
||||
send(sender, messageComponent("nameHistorySeparator"));
|
||||
historyList.forEach(component -> send(sender, component));
|
||||
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();
|
||||
}
|
||||
}
|
198
server/src/main/java/dev/plex/command/impl/NotesCMD.java
Normal file
198
server/src/main/java/dev/plex/command/impl/NotesCMD.java
Normal file
@ -0,0 +1,198 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
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.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 java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.notes")
|
||||
public class NotesCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
|
||||
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
return messageComponent("playerNotFound");
|
||||
}
|
||||
|
||||
switch (args[1].toLowerCase())
|
||||
{
|
||||
case "list":
|
||||
{
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
if (notes.size() == 0)
|
||||
{
|
||||
send(sender, messageComponent("noNotes"));
|
||||
return;
|
||||
}
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Note> notes = plexPlayer.getNotes();
|
||||
if (notes.size() == 0)
|
||||
{
|
||||
return messageComponent("noNotes");
|
||||
}
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
case "add":
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
String content = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
|
||||
if (playerSender != null)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
case "remove":
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
int id;
|
||||
try
|
||||
{
|
||||
id = Integer.parseInt(args[2]);
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
return messageComponent("unableToParseNumber", args[2]);
|
||||
}
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
boolean deleted = false;
|
||||
for (Note note : notes)
|
||||
{
|
||||
if (note.getId() == id)
|
||||
{
|
||||
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
|
||||
send(sender, messageComponent("removedNote", id)));
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
if (!deleted)
|
||||
{
|
||||
send(sender, messageComponent("noteNotFound"));
|
||||
}
|
||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
|
||||
{
|
||||
return messageComponent("removedNote", id);
|
||||
}
|
||||
return messageComponent("noteNotFound");
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readNotes(@NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes)
|
||||
{
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + TimeUtils.useTimezone(note.getTimestamp()));
|
||||
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote()));
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
send(sender, noteList.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
return Arrays.asList("list", "add", "remove", "clear");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
31
server/src/main/java/dev/plex/command/impl/OpAllCMD.java
Normal file
31
server/src/main/java/dev/plex/command/impl/OpAllCMD.java
Normal file
@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
40
server/src/main/java/dev/plex/command/impl/OpCMD.java
Normal file
40
server/src/main/java/dev/plex/command/impl/OpCMD.java
Normal file
@ -0,0 +1,40 @@
|
||||
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 java.util.List;
|
||||
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;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
142
server/src/main/java/dev/plex/command/impl/PlexCMD.java
Normal file
142
server/src/main/java/dev/plex/command/impl/PlexCMD.java
Normal file
@ -0,0 +1,142 @@
|
||||
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.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;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.plex", 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
|
||||
{
|
||||
// Don't modify this command
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
|
||||
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getHead()));
|
||||
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
||||
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
||||
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
||||
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, 2);
|
||||
return null;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
|
||||
plugin.config.load();
|
||||
send(sender, "Reloaded config file");
|
||||
plugin.messages.load();
|
||||
send(sender, "Reloaded messages file");
|
||||
plugin.indefBans.load(false);
|
||||
plugin.getPunishmentManager().mergeIndefiniteBans();
|
||||
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.setupPermissions() && plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
}
|
||||
plugin.getServiceManager().endServices();
|
||||
plugin.getServiceManager().startServices();
|
||||
send(sender, "Restarted services.");
|
||||
TimeUtils.TIMEZONE = plugin.config.getString("server.timezone");
|
||||
send(sender, "Set timezone to: " + TimeUtils.TIMEZONE);
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
return null;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("redis"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis");
|
||||
if (!plugin.getRedisConnection().isEnabled())
|
||||
{
|
||||
throw new CommandFailException("&cRedis is not enabled.");
|
||||
}
|
||||
plugin.getRedisConnection().getJedis().set("test", "123");
|
||||
send(sender, "Set test to 123. Now outputting key test...");
|
||||
send(sender, plugin.getRedisConnection().getJedis().get("test"));
|
||||
plugin.getRedisConnection().getJedis().close();
|
||||
return null;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("modules"))
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return mmString("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkRank(sender, Rank.EXECUTIVE, "plex.modules.reload");
|
||||
plugin.getModuleManager().reloadModules();
|
||||
return mmString("<green>All modules reloaded!");
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("update"))
|
||||
{
|
||||
if (sender instanceof Player && !PlexUtils.DEVELOPERS.contains(playerSender.getUniqueId().toString()))
|
||||
{
|
||||
return messageComponent("noPermissionRank", "a developer");
|
||||
}
|
||||
for (PlexModule module : plugin.getModuleManager().getModules())
|
||||
{
|
||||
plugin.getUpdateChecker().updateJar(sender, module.getPlexModuleFile().getName(), true);
|
||||
}
|
||||
plugin.getModuleManager().reloadModules();
|
||||
return mmString("<green>All modules updated and reloaded!");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("update"))
|
||||
{
|
||||
if (sender instanceof Player && !PlexUtils.DEVELOPERS.contains(playerSender.getUniqueId().toString()))
|
||||
{
|
||||
return messageComponent("noPermissionRank", "a developer");
|
||||
}
|
||||
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
|
||||
{
|
||||
return mmString("<red>Plex is already up to date!");
|
||||
}
|
||||
plugin.getUpdateChecker().updateJar(sender, "Plex", false);
|
||||
return mmString("<red>Alert: Restart the server for the new JAR file to be applied.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
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("reload", "redis", "modules");
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("modules"))
|
||||
{
|
||||
return List.of("reload");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.menu.PunishmentMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
@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)
|
||||
public class PunishmentsCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
new PunishmentMenu().openInv(playerSender, 0);
|
||||
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();
|
||||
}
|
||||
}
|
57
server/src/main/java/dev/plex/command/impl/RankCMD.java
Normal file
57
server/src/main/java/dev/plex/command/impl/RankCMD.java
Normal file
@ -0,0 +1,57 @@
|
||||
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 java.util.Collections;
|
||||
import java.util.List;
|
||||
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.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();
|
||||
}
|
||||
}
|
31
server/src/main/java/dev/plex/command/impl/RawSayCMD.java
Normal file
31
server/src/main/java/dev/plex/command/impl/RawSayCMD.java
Normal file
@ -0,0 +1,31 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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)
|
||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
||||
public class RawSayCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(StringUtils.join(args, " "));
|
||||
return null;
|
||||
}
|
||||
}
|
31
server/src/main/java/dev/plex/command/impl/SayCMD.java
Normal file
31
server/src/main/java/dev/plex/command/impl/SayCMD.java
Normal file
@ -0,0 +1,31 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.say", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||
public class SayCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
return null;
|
||||
}
|
||||
}
|
153
server/src/main/java/dev/plex/command/impl/SmiteCMD.java
Normal file
153
server/src/main/java/dev/plex/command/impl/SmiteCMD.java
Normal file
@ -0,0 +1,153 @@
|
||||
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.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 java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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.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
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
boolean silent = false;
|
||||
boolean clearinv = false;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-q"))
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-q"))
|
||||
{
|
||||
silent = true;
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
||||
}
|
||||
}
|
||||
else if (args[args.length - 1].equalsIgnoreCase("-ci"))
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-ci"))
|
||||
{
|
||||
clearinv = true;
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
}
|
||||
}
|
||||
|
||||
final Player player = getNonNullPlayer(args[0]);
|
||||
final PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
|
||||
Title title = Title.title(Component.text("You've been smitten.").color(NamedTextColor.RED), Component.text("Be sure to follow the rules!").color(NamedTextColor.YELLOW));
|
||||
player.showTitle(title);
|
||||
|
||||
if (!silent)
|
||||
{
|
||||
PlexUtils.broadcast(mmString("<red>" + player.getName() + " has been a naughty, naughty boy."));
|
||||
if (reason != null)
|
||||
{
|
||||
PlexUtils.broadcast(mmString(" <red>Reason: " + "<yellow>" + reason));
|
||||
}
|
||||
PlexUtils.broadcast(mmString(" <red>Smitten by: " + "<yellow>" + sender.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
send(sender, "Smitten " + player.getName() + " quietly.");
|
||||
}
|
||||
|
||||
// Deop
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
// Set gamemode to survival
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
// Clear inventory
|
||||
if (clearinv)
|
||||
{
|
||||
player.getInventory().clear();
|
||||
}
|
||||
|
||||
// Strike with lightning effect
|
||||
final Location targetPos = player.getLocation();
|
||||
final World world = player.getWorld();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
final Location strike_pos = new Location(world, targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
||||
world.strikeLightning(strike_pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Kill
|
||||
player.setHealth(0.0);
|
||||
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setType(PunishmentType.SMITE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
punishment.setReason(reason);
|
||||
send(player, mmString("<red>You've been smitten. Reason: <yellow>" + reason));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (checkTab(sender, Rank.ADMIN, "plex.smite") && args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
66
server/src/main/java/dev/plex/command/impl/SpectatorCMD.java
Normal file
66
server/src/main/java/dev/plex/command/impl/SpectatorCMD.java
Normal file
@ -0,0 +1,66 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.api.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
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.gamemode.spectator", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "spectator", aliases = "gmsp", description = "Set your own or another player's gamemode to spectator mode")
|
||||
public class SpectatorCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SPECTATOR));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
||||
messageComponent("gameModeSetTo", "spectator");
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "spectator"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SPECTATOR));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
67
server/src/main/java/dev/plex/command/impl/SurvivalCMD.java
Normal file
67
server/src/main/java/dev/plex/command/impl/SurvivalCMD.java
Normal file
@ -0,0 +1,67 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.api.event.GameModeUpdateEvent;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "survival", aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
|
||||
public class SurvivalCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
||||
send(targetPlayer, messageComponent("gameModeSetTo", "survival"));
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "survival"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SURVIVAL));
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
108
server/src/main/java/dev/plex/command/impl/TagCMD.java
Normal file
108
server/src/main/java/dev/plex/command/impl/TagCMD.java
Normal file
@ -0,0 +1,108 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
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)
|
||||
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
|
||||
public class TagCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return usage("/tag clear <player>");
|
||||
}
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("set"))
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
}
|
||||
assert playerSender != null;
|
||||
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
|
||||
if (args.length < 2)
|
||||
{
|
||||
return usage("/tag set <prefix>");
|
||||
}
|
||||
String prefix = StringUtils.join(args, " ", 1, args.length);
|
||||
|
||||
Component convertedComponent = removeEvents(PlexUtils.mmCustomDeserialize(prefix = prefix.replace("<newline>", "").replace("<br>", ""), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())); //noColorComponentFromString(prefix)
|
||||
|
||||
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
|
||||
{
|
||||
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
|
||||
}
|
||||
|
||||
player.setPrefix(prefix);
|
||||
DataUtils.update(player);
|
||||
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("clear"))
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
}
|
||||
|
||||
if (playerSender == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
|
||||
player.setPrefix("");
|
||||
DataUtils.update(player);
|
||||
return messageComponent("prefixCleared");
|
||||
}
|
||||
|
||||
checkRank(sender, Rank.ADMIN, "plex.tag.clear.others");
|
||||
Player target = getNonNullPlayer(args[1]);
|
||||
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
|
||||
plexTarget.setPrefix("");
|
||||
DataUtils.update(plexTarget);
|
||||
return messageComponent("otherPrefixCleared", target.getName());
|
||||
}
|
||||
return usage();
|
||||
}
|
||||
|
||||
private Component removeEvents(Component component)
|
||||
{
|
||||
if (component.clickEvent() != null)
|
||||
{
|
||||
component = component.clickEvent(null);
|
||||
}
|
||||
if (component.hoverEvent() != null)
|
||||
{
|
||||
component = component.hoverEvent(null);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
|
101
server/src/main/java/dev/plex/command/impl/TempbanCMD.java
Normal file
101
server/src/main/java/dev/plex/command/impl/TempbanCMD.java
Normal file
@ -0,0 +1,101 @@
|
||||
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.exception.PlayerNotFoundException;
|
||||
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 dev.plex.util.WebUtils;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.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;
|
||||
|
||||
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class TempbanCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length <= 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
String reason;
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.TEMPBAN);
|
||||
if (args.length > 2)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 2, args.length);
|
||||
punishment.setReason(reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
if (player != null)
|
||||
{
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
}
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
if (player != null)
|
||||
{
|
||||
player.kick(Punishment.generateBanMessage(punishment));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
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.source.RequiredCommandSource;
|
||||
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.toggledrops", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "toggledrops", description = "Toggle immediately removing drops.", usage = "/<command>", aliases = "td")
|
||||
public class ToggleDropsCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
plugin.config.set("allowdrops", !plugin.config.getBoolean("allowdrops"));
|
||||
plugin.config.save();
|
||||
send(sender, plugin.config.getBoolean("allowdrops") ? messageComponent("allowDropsEnabled") : messageComponent("allowDropsDisabled"));
|
||||
return null;
|
||||
}
|
||||
}
|
65
server/src/main/java/dev/plex/command/impl/UnbanCMD.java
Normal file
65
server/src/main/java/dev/plex/command/impl/UnbanCMD.java
Normal file
@ -0,0 +1,65 @@
|
||||
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.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 java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class UnbanCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
||||
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
||||
{
|
||||
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
|
||||
if (!aBoolean)
|
||||
{
|
||||
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
|
||||
return;
|
||||
}
|
||||
plugin.getPunishmentManager().unban(targetUUID);
|
||||
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
45
server/src/main/java/dev/plex/command/impl/UnfreezeCMD.java
Normal file
45
server/src/main/java/dev/plex/command/impl/UnfreezeCMD.java
Normal file
@ -0,0 +1,45 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
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.unfreeze")
|
||||
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
|
||||
public class UnfreezeCMD 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]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
if (!punishedPlayer.isFrozen())
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("playerNotFrozen"));
|
||||
}
|
||||
punishedPlayer.setFrozen(false);
|
||||
PlexUtils.broadcast(messageComponent("unfrozePlayer", 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 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
45
server/src/main/java/dev/plex/command/impl/UnmuteCMD.java
Normal file
45
server/src/main/java/dev/plex/command/impl/UnmuteCMD.java
Normal file
@ -0,0 +1,45 @@
|
||||
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.exception.CommandFailException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
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.unmute")
|
||||
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
|
||||
public class UnmuteCMD 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]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
if (!punishedPlayer.isMuted())
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("playerNotMuted"));
|
||||
}
|
||||
punishedPlayer.setMuted(false);
|
||||
PlexUtils.broadcast(messageComponent("unmutedPlayer", 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 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
46
server/src/main/java/dev/plex/command/impl/WorldCMD.java
Normal file
46
server/src/main/java/dev/plex/command/impl/WorldCMD.java
Normal file
@ -0,0 +1,46 @@
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.world", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
|
||||
public class WorldCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
assert playerSender != null;
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
World world = getNonNullWorld(args[0]);
|
||||
playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
|
||||
return messageComponent("playerWorldTeleport", world.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList());
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package dev.plex.command.source;
|
||||
|
||||
public enum RequiredCommandSource
|
||||
{
|
||||
IN_GAME,
|
||||
CONSOLE,
|
||||
ANY
|
||||
}
|
122
server/src/main/java/dev/plex/config/Config.java
Normal file
122
server/src/main/java/dev/plex/config/Config.java
Normal file
@ -0,0 +1,122 @@
|
||||
package dev.plex.config;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.util.PlexLog;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* Creates a custom Config object
|
||||
*/
|
||||
public class Config extends YamlConfiguration
|
||||
{
|
||||
/**
|
||||
* The plugin instance
|
||||
*/
|
||||
private Plex plugin;
|
||||
|
||||
/**
|
||||
* The File instance
|
||||
*/
|
||||
private File file;
|
||||
|
||||
/**
|
||||
* The file name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Whether new entries were added to the file automatically
|
||||
*/
|
||||
private boolean added = false;
|
||||
|
||||
/**
|
||||
* Creates a config object
|
||||
*
|
||||
* @param plugin The plugin instance
|
||||
* @param name The file name
|
||||
*/
|
||||
public Config(Plex plugin, String name)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.file = new File(plugin.getDataFolder(), name);
|
||||
this.name = name;
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
saveDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
this.load(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the configuration file
|
||||
*/
|
||||
public void load(boolean loadFromFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (loadFromFile)
|
||||
{
|
||||
YamlConfiguration externalYamlConfig = YamlConfiguration.loadConfiguration(file);
|
||||
InputStreamReader internalConfigFileStream = new InputStreamReader(plugin.getResource(name), StandardCharsets.UTF_8);
|
||||
YamlConfiguration internalYamlConfig = YamlConfiguration.loadConfiguration(internalConfigFileStream);
|
||||
|
||||
// Gets all the keys inside the internal file and iterates through all of it's key pairs
|
||||
for (String string : internalYamlConfig.getKeys(true))
|
||||
{
|
||||
// Checks if the external file contains the key already.
|
||||
if (!externalYamlConfig.contains(string))
|
||||
{
|
||||
// If it doesn't contain the key, we set the key based off what was found inside the plugin jar
|
||||
externalYamlConfig.setComments(string, internalYamlConfig.getComments(string));
|
||||
externalYamlConfig.setInlineComments(string, internalYamlConfig.getInlineComments(string));
|
||||
externalYamlConfig.set(string, internalYamlConfig.get(string));
|
||||
PlexLog.log("Setting key: " + string + " in " + this.name + " to the default value(s) since it does not exist!");
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
if (added)
|
||||
{
|
||||
externalYamlConfig.save(file);
|
||||
PlexLog.log("Saving new file...");
|
||||
added = false;
|
||||
}
|
||||
}
|
||||
super.load(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the configuration file
|
||||
*/
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.save(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/)
|
||||
*/
|
||||
private void saveDefault()
|
||||
{
|
||||
plugin.saveResource(name, false);
|
||||
}
|
||||
}
|
95
server/src/main/java/dev/plex/config/ModuleConfig.java
Normal file
95
server/src/main/java/dev/plex/config/ModuleConfig.java
Normal file
@ -0,0 +1,95 @@
|
||||
package dev.plex.config;
|
||||
|
||||
import dev.plex.module.PlexModule;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* Creates a custom Config object
|
||||
*/
|
||||
public class ModuleConfig extends YamlConfiguration
|
||||
{
|
||||
/**
|
||||
* The plugin instance
|
||||
*/
|
||||
private PlexModule module;
|
||||
|
||||
/**
|
||||
* The File instance
|
||||
*/
|
||||
private File file;
|
||||
|
||||
/**
|
||||
* Where the file is in the module JAR
|
||||
*/
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* Where it should be copied to in the module folder
|
||||
*/
|
||||
private String to;
|
||||
|
||||
/**
|
||||
* Creates a config object
|
||||
*
|
||||
* @param module The module instance
|
||||
* @param to The file name
|
||||
*/
|
||||
public ModuleConfig(PlexModule module, String from, String to)
|
||||
{
|
||||
this.module = module;
|
||||
this.file = new File(module.getDataFolder(), to);
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
saveDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.load(file);
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the configuration file
|
||||
*/
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.save(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/)
|
||||
*/
|
||||
private void saveDefault()
|
||||
{
|
||||
try
|
||||
{
|
||||
Files.copy(module.getClass().getResourceAsStream("/" + from), this.file.toPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
50
server/src/main/java/dev/plex/handlers/CommandHandler.java
Normal file
50
server/src/main/java/dev/plex/handlers/CommandHandler.java
Normal file
@ -0,0 +1,50 @@
|
||||
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.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandHandler implements PlexBase
|
||||
{
|
||||
public CommandHandler()
|
||||
{
|
||||
Set<Class<? extends PlexCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", PlexCommand.class);
|
||||
List<PlexCommand> commands = Lists.newArrayList();
|
||||
|
||||
commandSet.forEach(clazz ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (clazz.isAnnotationPresent(System.class))
|
||||
{
|
||||
System annotation = clazz.getDeclaredAnnotation(System.class);
|
||||
if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase()))
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
|
||||
if (plugin.config.getBoolean("debug") && annotation.debug())
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a command!");
|
||||
}
|
||||
});
|
||||
PlexLog.log(String.format("Registered %s commands from %s classes!", commands.size(), commandSet.size()));
|
||||
}
|
||||
}
|
45
server/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
45
server/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
@ -0,0 +1,45 @@
|
||||
package dev.plex.handlers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.annotation.Toggleable;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ListenerHandler implements PlexBase
|
||||
{
|
||||
public ListenerHandler()
|
||||
{
|
||||
Set<Class<? extends PlexListener>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", PlexListener.class);
|
||||
List<PlexListener> listeners = Lists.newArrayList();
|
||||
|
||||
listenerSet.forEach(clazz ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (clazz.isAnnotationPresent(Toggleable.class))
|
||||
{
|
||||
Toggleable annotation = clazz.getDeclaredAnnotation(Toggleable.class);
|
||||
if (plugin.config.get(annotation.value()) != null && plugin.config.getBoolean(annotation.value()))
|
||||
{
|
||||
listeners.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listeners.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a listener!");
|
||||
}
|
||||
});
|
||||
PlexLog.log(String.format("Registered %s listeners from %s classes!", listeners.size(), listenerSet.size()));
|
||||
}
|
||||
}
|
12
server/src/main/java/dev/plex/listener/PlexListener.java
Normal file
12
server/src/main/java/dev/plex/listener/PlexListener.java
Normal file
@ -0,0 +1,12 @@
|
||||
package dev.plex.listener;
|
||||
|
||||
import dev.plex.PlexBase;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class PlexListener implements Listener, PlexBase
|
||||
{
|
||||
public PlexListener()
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package dev.plex.listener.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Toggleable
|
||||
{
|
||||
String value();
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.api.event.AdminAddEvent;
|
||||
import dev.plex.api.event.AdminRemoveEvent;
|
||||
import dev.plex.api.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 = (PlexPlayer) 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 = (PlexPlayer) 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 = (PlexPlayer) event.getPlexPlayer();
|
||||
Rank newRank = (Rank) event.getRank();
|
||||
target.setRank(newRank.name().toLowerCase());
|
||||
DataUtils.update(target);
|
||||
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class AntiNukerListener extends PlexListener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 200L)
|
||||
{
|
||||
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 200L)
|
||||
{
|
||||
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.nukerCooldown.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class AntiSpamListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
TimingService.spamCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 8L)
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("Please refrain from spamming messages.").color(NamedTextColor.GRAY));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
TimingService.spamCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 8L)
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("Please refrain from spamming commands.").color(NamedTextColor.GRAY));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.spamCooldown.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
45
server/src/main/java/dev/plex/listener/impl/BanListener.java
Normal file
45
server/src/main/java/dev/plex/listener/impl/BanListener.java
Normal file
@ -0,0 +1,45 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
|
||||
public class BanListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
if (plugin.getPunishmentManager().isIndefUUIDBanned(event.getUniqueId()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateIndefBanMessage("UUID"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isIndefIPBanned(event.getAddress().getHostAddress()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateIndefBanMessage("IP"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isIndefUserBanned(event.getName()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateIndefBanMessage("username"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
|
||||
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateBanMessage(punishment)));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class BlockListener extends PlexListener
|
||||
{
|
||||
public List<String> blockedPlayers = new ArrayList<>();
|
||||
|
||||
private static final List<Material> blockedBlocks = new ArrayList<>();
|
||||
|
||||
private static List<String> cachedBlockedBlocksConfig = null;
|
||||
|
||||
private static final List<Material> SIGNS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SIGN")).toList();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
List<String> blockedBlocksConfig = plugin.config.getStringList("blocked_blocks");
|
||||
if (blockedBlocksConfig != cachedBlockedBlocksConfig)
|
||||
{
|
||||
blockedBlocks.clear();
|
||||
cachedBlockedBlocksConfig = blockedBlocksConfig;
|
||||
for (String block : blockedBlocksConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
blockedBlocks.add(Material.valueOf(block.toUpperCase()));
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (blockedPlayers.contains(event.getPlayer().getName()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (blockedBlocks.contains(block.getType()))
|
||||
{
|
||||
block.setType(Material.CAKE);
|
||||
PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5, 0.5, 0.5));
|
||||
}
|
||||
|
||||
if (SIGNS.contains(block.getType()))
|
||||
{
|
||||
Sign sign = (Sign)block.getState();
|
||||
boolean anythingChanged = false;
|
||||
for (int i = 0; i < sign.lines().size(); i++)
|
||||
{
|
||||
Component line = sign.line(i);
|
||||
if (line.clickEvent() != null)
|
||||
{
|
||||
anythingChanged = true;
|
||||
sign.line(i, line.clickEvent(null));
|
||||
}
|
||||
}
|
||||
if (anythingChanged)
|
||||
{
|
||||
sign.update(true);
|
||||
PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5, 0.5, 0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (blockedPlayers.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (blockedPlayers.contains(event.getPlayer().getName()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.annotation.Toggleable;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Toggleable("chat.enabled")
|
||||
public class ChatListener extends PlexListener
|
||||
{
|
||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||
|
||||
Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
|
||||
if (prefix != null)
|
||||
{
|
||||
renderer.hasPrefix = true;
|
||||
renderer.prefix = prefix;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.hasPrefix = false;
|
||||
renderer.prefix = null;
|
||||
}
|
||||
event.renderer(renderer);
|
||||
}
|
||||
|
||||
public static class PlexChatRenderer implements ChatRenderer
|
||||
{
|
||||
public boolean hasPrefix;
|
||||
public Component prefix;
|
||||
|
||||
@Override
|
||||
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
|
||||
{
|
||||
if (hasPrefix)
|
||||
{
|
||||
return Component.empty()
|
||||
.append(prefix)
|
||||
.append(Component.space())
|
||||
.append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", "<white>"))).append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(message);
|
||||
}
|
||||
return Component.empty()
|
||||
.append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", "<white>"))).append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(message);
|
||||
}
|
||||
}
|
||||
}
|
133
server/src/main/java/dev/plex/listener/impl/CommandListener.java
Normal file
133
server/src/main/java/dev/plex/listener/impl/CommandListener.java
Normal file
@ -0,0 +1,133 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
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 java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandListener extends PlexListener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
Bukkit.getOnlinePlayers().stream().filter(pl -> PlayerCache.getPlexPlayer(pl.getUniqueId()).isCommandSpy()).forEach(pl ->
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
String command = event.getMessage();
|
||||
if (pl != player)
|
||||
{
|
||||
pl.sendMessage(ChatColor.GRAY + player.getName() + ": " + command);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onCommandBlocking(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
String commandName = StringUtils.normalizeSpace(event.getMessage()).split(" ")[0].replaceFirst("/", "");
|
||||
String arguments = StringUtils.normalizeSpace(StringUtils.normalizeSpace(event.getMessage()).replace(event.getMessage().split(" ")[0], ""));
|
||||
PlexLog.debug("Checking Command: {0} with args {1}", commandName, arguments);
|
||||
AtomicReference<BlockedCommand> cmdRef = new AtomicReference<>();
|
||||
PlexLog.debug("Blocked Commands List: " + CommandBlockerService.getBLOCKED_COMMANDS().size());
|
||||
CommandBlockerService.getBLOCKED_COMMANDS().stream().filter(blockedCommand -> blockedCommand.getCommand() != null).forEach(blockedCommand ->
|
||||
{
|
||||
boolean matches = true;
|
||||
String[] args = blockedCommand.getCommand().split(" ");
|
||||
String[] cmdArgs = event.getMessage().replaceFirst("/", "").split(" ");
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
if (i + 1 > cmdArgs.length)
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
if (!args[i].equalsIgnoreCase(cmdArgs[i]))
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (matches)
|
||||
{
|
||||
PlexLog.debug("Used blocked command exactly matched");
|
||||
cmdRef.set(blockedCommand);
|
||||
return;
|
||||
}
|
||||
if (blockedCommand.getCommandAliases().stream().anyMatch(s -> s.equalsIgnoreCase(commandName)))
|
||||
{
|
||||
PlexLog.debug("Found a command name in a blocked command alias, checking arguments now.");
|
||||
String[] commandArgs = blockedCommand.getCommand().split(" ");
|
||||
if (arguments.toLowerCase(Locale.ROOT).startsWith(StringUtils.join(commandArgs, " ", 1, commandArgs.length).toLowerCase(Locale.ROOT)))
|
||||
{
|
||||
PlexLog.debug("Player attempted to use a blocked command with an alias.");
|
||||
cmdRef.set(blockedCommand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (cmdRef.get() == null)
|
||||
{
|
||||
CommandBlockerService.getBLOCKED_COMMANDS().forEach(blockedCommand ->
|
||||
{
|
||||
if (blockedCommand.getRegex() != null)
|
||||
{
|
||||
Pattern pattern = Pattern.compile(blockedCommand.getRegex(), Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(event.getMessage().replaceFirst("/", ""));
|
||||
if (matcher.find())
|
||||
{
|
||||
PlexLog.debug("Player attempted to use a blocked regex");
|
||||
cmdRef.set(blockedCommand);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (cmdRef.get() != null)
|
||||
{
|
||||
BlockedCommand cmd = cmdRef.get();
|
||||
switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
|
||||
{
|
||||
case "e" ->
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
case "a" ->
|
||||
{
|
||||
if (plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
case "s" ->
|
||||
{
|
||||
if (plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(Rank.SENIOR_ADMIN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class DropListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (!plugin.config.getBoolean("allowdrops"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class FreezeListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e)
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(e.getPlayer().getUniqueId());
|
||||
if (player.isFrozen())
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.api.event.GameModeUpdateEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class GameModeListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onGameModeUpdate(GameModeUpdateEvent event)
|
||||
{
|
||||
CommandSender userSender = event.getSender();
|
||||
Player target = event.getPlayer();
|
||||
if (userSender.getName().equals(target.getName()))
|
||||
{
|
||||
target.setGameMode(event.getGameMode());
|
||||
userSender.sendMessage(PlexUtils.messageComponent("gameModeSetTo", event.getGameMode().toString().toLowerCase()));
|
||||
}
|
||||
else
|
||||
{
|
||||
target.sendMessage(PlexUtils.messageComponent("playerSetOtherGameMode", userSender.getName(), event.getGameMode().toString().toLowerCase()));
|
||||
target.setGameMode(event.getGameMode());
|
||||
userSender.sendMessage(PlexUtils.messageComponent("setOtherPlayerGameModeTo", target.getName(), event.getGameMode().toString().toLowerCase()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
public class MuteListener extends PlexListener
|
||||
{
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
if (DataUtils.getPlayer(event.getPlayer().getUniqueId()).isMuted())
|
||||
{
|
||||
event.getPlayer().sendMessage(PlexUtils.messageComponent("muted"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
136
server/src/main/java/dev/plex/listener/impl/PlayerListener.java
Normal file
136
server/src/main/java/dev/plex/listener/impl/PlayerListener.java
Normal file
@ -0,0 +1,136 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerListener<T> extends PlexListener
|
||||
{
|
||||
// setting up a player's data
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerSetup(PlayerJoinEvent event)
|
||||
{
|
||||
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.");
|
||||
plexPlayer = new PlexPlayer(player.getUniqueId()); // it doesn't! okay so now create the object
|
||||
plexPlayer.setName(player.getName()); // set the name of the player
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); // set the arraylist of ips
|
||||
DataUtils.insert(plexPlayer); // insert data in some wack db
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
List<String> ips = plexPlayer.getIps();
|
||||
String currentIP = player.getAddress().getAddress().getHostAddress().trim();
|
||||
if (!ips.contains(currentIP))
|
||||
{
|
||||
PlexLog.debug("New IP address detected for player: " + player.getName() + ". Adding " + currentIP + " to the database.");
|
||||
ips.add(currentIP);
|
||||
plexPlayer.setIps(ips);
|
||||
DataUtils.update(plexPlayer);
|
||||
}
|
||||
if (!plexPlayer.getName().equals(player.getName()))
|
||||
{
|
||||
PlexLog.log(plexPlayer.getName() + " has a new name. Changing it to " + player.getName());
|
||||
plexPlayer.setName(player.getName());
|
||||
DataUtils.update(plexPlayer);
|
||||
}
|
||||
}
|
||||
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer);
|
||||
if (plexPlayer.isLockedUp())
|
||||
{
|
||||
player.openInventory(player.getInventory());
|
||||
}
|
||||
|
||||
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
|
||||
if (!loginMessage.isEmpty())
|
||||
{
|
||||
PlexUtils.broadcast(PlexUtils.mmDeserialize("<aqua>" + player.getName() + " is " + loginMessage));
|
||||
}
|
||||
|
||||
PermissionsUtil.setupPermissions(player);
|
||||
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plexPlayer.loadNotes();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// saving the player's data
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerSave(PlayerQuitEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.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);
|
||||
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInventoryClose(InventoryCloseEvent event)
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(event.getPlayer().getUniqueId());
|
||||
if (player.isLockedUp())
|
||||
{
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> event.getPlayer().openInventory(event.getInventory()), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(event.getWhoClicked().getUniqueId());
|
||||
if (player.isLockedUp())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.RandomUtil;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class ServerListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onServerPing(PaperServerListPingEvent event)
|
||||
{
|
||||
String baseMotd = plugin.config.getString("server.motd");
|
||||
baseMotd = baseMotd.replace("\\n", "\n");
|
||||
baseMotd = baseMotd.replace("%servername%", plugin.config.getString("server.name"));
|
||||
baseMotd = baseMotd.replace("%mcversion%", Bukkit.getBukkitVersion().split("-")[0]);
|
||||
if (plugin.config.getBoolean("server.colorize_motd"))
|
||||
{
|
||||
AtomicReference<Component> motd = new AtomicReference<>(Component.empty());
|
||||
for (final String word : baseMotd.split(" "))
|
||||
{
|
||||
motd.set(motd.get().append(Component.text(word).color(RandomUtil.getRandomColor())));
|
||||
motd.set(motd.get().append(Component.space()));
|
||||
}
|
||||
event.motd(motd.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.motd(PlexUtils.mmDeserialize(baseMotd.trim()));
|
||||
}
|
||||
if (plugin.config.contains("server.sample"))
|
||||
{
|
||||
List<String> samples = plugin.config.getStringList("server.sample");
|
||||
if (!samples.isEmpty())
|
||||
{
|
||||
event.getPlayerSample().clear();
|
||||
event.getPlayerSample().addAll(samples.stream().map(string -> string.replace("&", "§")).map(Bukkit::createProfile).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
131
server/src/main/java/dev/plex/listener/impl/SpawnListener.java
Normal file
131
server/src/main/java/dev/plex/listener/impl/SpawnListener.java
Normal file
@ -0,0 +1,131 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class SpawnListener extends PlexListener
|
||||
{
|
||||
private static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent event)
|
||||
{
|
||||
if (event.getEntity().getEntitySpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG)
|
||||
{
|
||||
// for the future, we can instead filter and restrict nbt tags right here.
|
||||
// currently, however, the entity from spawn eggs are spawned by other event handlers
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.config.getStringList("blocked_entities").stream().anyMatch(type -> type.equalsIgnoreCase(event.getEntityType().name())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Location location = event.getLocation();
|
||||
Collection<Player> coll = location.getNearbyEntitiesByType(Player.class, 10);
|
||||
PlexUtils.disabledEffectMultiple(coll.toArray(new Player[coll.size()]), location); // dont let intellij auto correct toArray to an empty array (for efficiency)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDispense(BlockDispenseEvent event)
|
||||
{
|
||||
ItemStack item = event.getItem();
|
||||
Material itemType = item.getType();
|
||||
if (SPAWN_EGGS.contains(itemType))
|
||||
{
|
||||
Block block = event.getBlock();
|
||||
Location blockLoc = block.getLocation().add(0.5, 0.5, 0.5).add(((Directional)block.getBlockData()).getFacing().getDirection().multiply(0.8));
|
||||
EntityType eggType = spawnEggToEntityType(itemType);
|
||||
if (eggType != null)
|
||||
{
|
||||
blockLoc.getWorld().spawnEntity(blockLoc, eggType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityClick(PlayerInteractEntityEvent event)
|
||||
{
|
||||
Material handItem = event.getPlayer().getEquipment().getItem(event.getHand()).getType();
|
||||
if (event.getRightClicked() instanceof Ageable entity)
|
||||
{
|
||||
if (SPAWN_EGGS.contains(handItem))
|
||||
{
|
||||
EntityType eggType = spawnEggToEntityType(handItem);
|
||||
if (eggType != null)
|
||||
{
|
||||
Entity spawned = entity.getWorld().spawnEntity(entity.getLocation(), eggType);
|
||||
if (spawned instanceof Ageable ageable)
|
||||
{
|
||||
ageable.setBaby();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
if (SPAWN_EGGS.contains(event.getMaterial()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
if (clickedBlock == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityType eggType = spawnEggToEntityType(event.getMaterial());
|
||||
if (eggType != null)
|
||||
{
|
||||
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection().multiply(0.8)).add(0.5, 0.5, 0.5), eggType);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static EntityType spawnEggToEntityType(Material mat)
|
||||
{
|
||||
EntityType eggType;
|
||||
try
|
||||
{
|
||||
if (mat == Material.MOOSHROOM_SPAWN_EGG)
|
||||
{
|
||||
eggType = EntityType.MUSHROOM_COW;
|
||||
}
|
||||
else
|
||||
{
|
||||
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return eggType;
|
||||
}
|
||||
}
|
60
server/src/main/java/dev/plex/listener/impl/TabListener.java
Normal file
60
server/src/main/java/dev/plex/listener/impl/TabListener.java
Normal file
@ -0,0 +1,60 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.api.event.AdminAddEvent;
|
||||
import dev.plex.api.event.AdminRemoveEvent;
|
||||
import dev.plex.api.event.AdminSetRankEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class TabListener extends PlexListener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
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 = (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 = (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 = (PlexPlayer) event.getPlexPlayer();
|
||||
Player player = event.getPlexPlayer().getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
||||
}
|
||||
}
|
198
server/src/main/java/dev/plex/listener/impl/WorldListener.java
Normal file
198
server/src/main/java/dev/plex/listener/impl/WorldListener.java
Normal file
@ -0,0 +1,198 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldListener extends PlexListener
|
||||
{
|
||||
private final List<String> EDIT_COMMANDS = Arrays.asList("bigtree", "ebigtree", "largetree", "elargetree",
|
||||
"break", "ebreak", "antioch", "nuke", "editsign", "tree", "etree");
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e)
|
||||
{
|
||||
if (!checkPermission(e.getPlayer(), true))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e)
|
||||
{
|
||||
if (!checkPermission(e.getPlayer(), true))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent e)
|
||||
{
|
||||
if (e.getEntityType() != EntityType.SLIME)
|
||||
{
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
// If the person has permission to modify the world, we don't need to block WorldEdit
|
||||
if (checkPermission(event.getPlayer(), false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String message = event.getMessage();
|
||||
// Don't check the arguments
|
||||
message = message.replaceAll("\\s.*", "").replaceFirst("/", "");
|
||||
Command command = Bukkit.getCommandMap().getCommand(message);
|
||||
if (command != null)
|
||||
{
|
||||
// This does check for aliases
|
||||
boolean isWeCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||
boolean isFaweCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
|
||||
if (isWeCommand || isFaweCommand || EDIT_COMMANDS.contains(message.toLowerCase()))
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("You do not have permission to use that command in this world.").color(NamedTextColor.RED));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add an entry setting in the config.yml and allow checking for all worlds
|
||||
@EventHandler
|
||||
public void onWorldTeleport(PlayerTeleportEvent e)
|
||||
{
|
||||
final World adminworld = Bukkit.getWorld("adminworld");
|
||||
if (adminworld == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(e.getPlayer().getUniqueId());
|
||||
if (e.getTo().getWorld().equals(adminworld))
|
||||
{
|
||||
if (plugin.getSystem().equals("ranks") && !plexPlayer.isAdminActive())
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
else if (plugin.getSystem().equals("permissions") && !e.getPlayer().hasPermission("plex.adminworld.enter"))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player, boolean showMessage)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
World world = player.getWorld();
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
String permission = plugin.config.getString("plex." + world.getName().toLowerCase() + ".permission");
|
||||
if (permission == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission(permission))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
|
||||
{
|
||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
|
||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (showMessage)
|
||||
{
|
||||
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||
if (noEdit != null)
|
||||
{
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
195
server/src/main/java/dev/plex/menu/PunishedPlayerMenu.java
Normal file
195
server/src/main/java/dev/plex/menu/PunishedPlayerMenu.java
Normal file
@ -0,0 +1,195 @@
|
||||
package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class PunishedPlayerMenu extends AbstractMenu
|
||||
{
|
||||
private final PlexPlayer punishedPlayer;
|
||||
|
||||
private final List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public PunishedPlayerMenu(PlexPlayer player)
|
||||
{
|
||||
super("§c§lPunishments");
|
||||
this.punishedPlayer = player;
|
||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
ItemStack back = new ItemStack(Material.BARRIER);
|
||||
ItemMeta meta3 = back.getItemMeta();
|
||||
meta3.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
||||
back.setItemMeta(meta3);
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
inventory.setItem(49, back);
|
||||
inventory.setItem(48, previousPage);
|
||||
inventories.add(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Inventory> getInventory()
|
||||
{
|
||||
return inventories;
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index)
|
||||
{
|
||||
int currentItemIndex = 0;
|
||||
int currentInvIndex = 0;
|
||||
for (Punishment punishment : punishedPlayer.getPunishments())
|
||||
{
|
||||
Inventory inv = inventories.get(currentInvIndex);
|
||||
if (currentInvIndex > inventories.size() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentItemIndex == inv.getSize() - 1)
|
||||
{
|
||||
currentInvIndex++;
|
||||
currentItemIndex = 0;
|
||||
inv = inventories.get(currentInvIndex);
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.NETHER_STAR);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.displayName(Component.text(punishment.getType().name().toUpperCase()).color(NamedTextColor.RED));
|
||||
meta.lore(Collections.singletonList(Component.text("Reason: ").color(NamedTextColor.YELLOW).append(Component.newline()).append(Component.text(punishment.getReason()).color(NamedTextColor.GRAY))));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inv.setItem(currentItemIndex, item);
|
||||
|
||||
currentItemIndex++;
|
||||
}
|
||||
player.openInventory(inventories.get(index));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getCurrentItem() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (!item.hasItemMeta())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!item.getItemMeta().hasDisplayName())
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().displayName().equals(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE)))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
}
|
||||
else if (item.getItemMeta().displayName().equals(Component.text("Previous Page").color(NamedTextColor.LIGHT_PURPLE)))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (item.getType() == Material.BARRIER)
|
||||
{
|
||||
new PunishmentMenu().openInv((Player)event.getWhoClicked(), 0);
|
||||
}
|
||||
else if (item.getType() == Material.PLAYER_HEAD)
|
||||
{
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
OfflinePlayer player = meta.getOwningPlayer();
|
||||
assert player != null;
|
||||
PlexPlayer punishedPlayer = DataUtils.getPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPlexPlayer(player.getUniqueId());
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
event.getWhoClicked().sendMessage(ChatColor.RED + "This player does not exist. Try doing /punishments <player> instead.");
|
||||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getCurrentInventoryIndex(Inventory inventory)
|
||||
{
|
||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
||||
{
|
||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean isValidInventory(Inventory inventory)
|
||||
{
|
||||
return inventories.contains(inventory);
|
||||
}
|
||||
}
|
179
server/src/main/java/dev/plex/menu/PunishmentMenu.java
Normal file
179
server/src/main/java/dev/plex/menu/PunishmentMenu.java
Normal file
@ -0,0 +1,179 @@
|
||||
package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class PunishmentMenu extends AbstractMenu
|
||||
{
|
||||
|
||||
private List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public PunishmentMenu()
|
||||
{
|
||||
super("§c§lPunishments");
|
||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.displayName(PlexUtils.mmDeserialize("<light_purple>Next Page"));
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.displayName(PlexUtils.mmDeserialize("<light_purple>Previous Page"));
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
inventory.setItem(48, previousPage);
|
||||
inventories.add(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Inventory> getInventory()
|
||||
{
|
||||
return inventories;
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index)
|
||||
{
|
||||
int currentItemIndex = 0;
|
||||
int currentInvIndex = 0;
|
||||
for (Player players : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
Inventory inv = inventories.get(currentInvIndex);
|
||||
if (currentInvIndex > inventories.size() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentItemIndex == inv.getSize() - 1)
|
||||
{
|
||||
currentInvIndex++;
|
||||
currentItemIndex = 0;
|
||||
inv = inventories.get(currentInvIndex);
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
meta.setOwningPlayer(players);
|
||||
meta.displayName(PlexUtils.mmDeserialize("<!italic><yellow>" + players.getName()));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inv.setItem(currentItemIndex, item);
|
||||
|
||||
currentItemIndex++;
|
||||
}
|
||||
player.openInventory(inventories.get(index));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getCurrentItem() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().hasItemMeta())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Next Page")))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
}
|
||||
else if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Previous Page")))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (item.getType() == Material.PLAYER_HEAD)
|
||||
{
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
OfflinePlayer player = meta.getOwningPlayer();
|
||||
assert player != null;
|
||||
PlexPlayer punishedPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
event.getWhoClicked().sendMessage(ChatColor.RED + "This player does not exist. Try doing /punishments <player> instead.");
|
||||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
new PunishedPlayerMenu(punishedPlayer).openInv((Player)event.getWhoClicked(), 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int getCurrentInventoryIndex(Inventory inventory)
|
||||
{
|
||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
||||
{
|
||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean isValidInventory(Inventory inventory)
|
||||
{
|
||||
return inventories.contains(inventory);
|
||||
}
|
||||
}
|
152
server/src/main/java/dev/plex/module/ModuleManager.java
Normal file
152
server/src/main/java/dev/plex/module/ModuleManager.java
Normal file
@ -0,0 +1,152 @@
|
||||
package dev.plex.module;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.module.exception.ModuleLoadException;
|
||||
import dev.plex.module.loader.LibraryLoader;
|
||||
import dev.plex.util.PlexLog;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@Getter
|
||||
public class ModuleManager
|
||||
{
|
||||
|
||||
private final List<PlexModule> modules = Lists.newArrayList();
|
||||
private final LibraryLoader libraryLoader;
|
||||
|
||||
public ModuleManager()
|
||||
{
|
||||
this.libraryLoader = new LibraryLoader(Plex.get().getLogger());
|
||||
}
|
||||
|
||||
public void loadAllModules()
|
||||
{
|
||||
this.modules.clear();
|
||||
PlexLog.debug(String.valueOf(Plex.get().getModulesFolder().listFiles().length));
|
||||
Arrays.stream(Plex.get().getModulesFolder().listFiles()).forEach(file ->
|
||||
{
|
||||
if (file.getName().endsWith(".jar"))
|
||||
{
|
||||
try
|
||||
{
|
||||
URLClassLoader loader = new URLClassLoader(
|
||||
new URL[]{file.toURI().toURL()},
|
||||
Plex.class.getClassLoader()
|
||||
);
|
||||
|
||||
InputStreamReader internalModuleFile = new InputStreamReader(loader.getResourceAsStream("module.yml"), StandardCharsets.UTF_8);
|
||||
YamlConfiguration internalModuleConfig = YamlConfiguration.loadConfiguration(internalModuleFile);
|
||||
|
||||
String name = internalModuleConfig.getString("name");
|
||||
if (name == null)
|
||||
{
|
||||
throw new ModuleLoadException("Plex module name can't be null!");
|
||||
}
|
||||
|
||||
String main = internalModuleConfig.getString("main");
|
||||
if (main == null)
|
||||
{
|
||||
throw new ModuleLoadException("Plex module main class can't be null!");
|
||||
}
|
||||
|
||||
String description = internalModuleConfig.getString("description", "A Plex module");
|
||||
String version = internalModuleConfig.getString("version", "1.0");
|
||||
List<String> libraries = internalModuleConfig.getStringList("libraries");
|
||||
|
||||
PlexModuleFile plexModuleFile = new PlexModuleFile(name, main, description, version);
|
||||
plexModuleFile.setLibraries(libraries);
|
||||
Class<? extends PlexModule> module = (Class<? extends PlexModule>)Class.forName(main, true, loader);
|
||||
|
||||
PlexModule plexModule = module.getConstructor().newInstance();
|
||||
plexModule.setPlex(Plex.get());
|
||||
plexModule.setPlexModuleFile(plexModuleFile);
|
||||
|
||||
plexModule.setDataFolder(new File(Plex.get().getModulesFolder() + File.separator + plexModuleFile.getName()));
|
||||
if (!plexModule.getDataFolder().exists())
|
||||
{
|
||||
plexModule.getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
plexModule.setLogger(LogManager.getLogger(plexModuleFile.getName()));
|
||||
modules.add(plexModule);
|
||||
}
|
||||
catch (MalformedURLException | ClassNotFoundException | InvocationTargetException |
|
||||
InstantiationException | IllegalAccessException | NoSuchMethodException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadModules()
|
||||
{
|
||||
this.modules.forEach(module ->
|
||||
{
|
||||
PlexLog.log("Loading module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
|
||||
module.load();
|
||||
// this.libraryLoader.createLoader(module, module.getPlexModuleFile());
|
||||
});
|
||||
}
|
||||
|
||||
public void enableModules()
|
||||
{
|
||||
this.modules.forEach(module ->
|
||||
{
|
||||
PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
|
||||
module.enable();
|
||||
});
|
||||
}
|
||||
|
||||
public void disableModules()
|
||||
{
|
||||
this.modules.forEach(module ->
|
||||
{
|
||||
PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
|
||||
module.getCommands().stream().toList().forEach(plexCommand ->
|
||||
{
|
||||
module.unregisterCommand(plexCommand);
|
||||
Plex.get().getServer().getCommandMap().getKnownCommands().remove(plexCommand.getName());
|
||||
plexCommand.getAliases().forEach(alias -> Plex.get().getServer().getCommandMap().getKnownCommands().remove(alias));
|
||||
});
|
||||
module.getListeners().stream().toList().forEach(module::unregisterListener);
|
||||
module.disable();
|
||||
});
|
||||
}
|
||||
|
||||
public void unloadModules()
|
||||
{
|
||||
this.disableModules();
|
||||
this.modules.forEach(module ->
|
||||
{
|
||||
try
|
||||
{
|
||||
((URLClassLoader)module.getClass().getClassLoader()).close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void reloadModules()
|
||||
{
|
||||
unloadModules();
|
||||
loadAllModules();
|
||||
loadModules();
|
||||
enableModules();
|
||||
}
|
||||
}
|
95
server/src/main/java/dev/plex/module/PlexModule.java
Normal file
95
server/src/main/java/dev/plex/module/PlexModule.java
Normal file
@ -0,0 +1,95 @@
|
||||
package dev.plex.module;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Getter
|
||||
@Setter(AccessLevel.MODULE)
|
||||
public abstract class PlexModule
|
||||
{
|
||||
@Getter(AccessLevel.MODULE)
|
||||
private final List<PlexCommand> commands = Lists.newArrayList();
|
||||
|
||||
@Getter(AccessLevel.MODULE)
|
||||
private final List<PlexListener> listeners = Lists.newArrayList();
|
||||
|
||||
private Plex plex;
|
||||
private PlexModuleFile plexModuleFile;
|
||||
private File dataFolder;
|
||||
private Logger logger;
|
||||
|
||||
public void load()
|
||||
{
|
||||
}
|
||||
|
||||
public void enable()
|
||||
{
|
||||
}
|
||||
|
||||
public void disable()
|
||||
{
|
||||
}
|
||||
|
||||
public void registerListener(PlexListener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void unregisterListener(PlexListener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
HandlerList.unregisterAll(listener);
|
||||
}
|
||||
|
||||
public void registerCommand(PlexCommand command)
|
||||
{
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
public void unregisterCommand(PlexCommand command)
|
||||
{
|
||||
commands.remove(command);
|
||||
}
|
||||
|
||||
public PlexCommand getCommand(String name)
|
||||
{
|
||||
return commands.stream().filter(plexCommand -> plexCommand.getName().equalsIgnoreCase(name) || plexCommand.getAliases().stream().map(String::toLowerCase).toList().contains(name.toLowerCase(Locale.ROOT))).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InputStream getResource(@NotNull String filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = this.getClass().getClassLoader().getResource(filename);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setUseCaches(false);
|
||||
return connection.getInputStream();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
17
server/src/main/java/dev/plex/module/PlexModuleFile.java
Normal file
17
server/src/main/java/dev/plex/module/PlexModuleFile.java
Normal file
@ -0,0 +1,17 @@
|
||||
package dev.plex.module;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlexModuleFile
|
||||
{
|
||||
private final String name;
|
||||
private final String main;
|
||||
private final String description;
|
||||
private final String version;
|
||||
|
||||
//TODO: does not work
|
||||
private List<String> libraries = ImmutableList.of();
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package dev.plex.module.exception;
|
||||
|
||||
public class ModuleLoadException extends RuntimeException
|
||||
{
|
||||
public ModuleLoadException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package dev.plex.module.loader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class CustomClassLoader extends URLClassLoader
|
||||
{
|
||||
/*public CustomClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
for (URL url : urls) {
|
||||
super.addURL(url);
|
||||
}
|
||||
}*/
|
||||
|
||||
public CustomClassLoader(URL jarInJar, ClassLoader parent)
|
||||
{
|
||||
super(new URL[]{extractJar(jarInJar)}, parent);
|
||||
addURL(jarInJar);
|
||||
}
|
||||
|
||||
|
||||
static URL extractJar(URL jarInJar) throws RuntimeException
|
||||
{
|
||||
// get the jar-in-jar resource
|
||||
if (jarInJar == null)
|
||||
{
|
||||
throw new RuntimeException("Could not locate jar-in-jar");
|
||||
}
|
||||
|
||||
// create a temporary file
|
||||
// on posix systems by default this is only read/writable by the process owner
|
||||
Path path;
|
||||
try
|
||||
{
|
||||
path = Files.createTempFile("plex-jarinjar", ".jar.tmp");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to create a temporary file", e);
|
||||
}
|
||||
|
||||
// mark that the file should be deleted on exit
|
||||
path.toFile().deleteOnExit();
|
||||
|
||||
// copy the jar-in-jar to the temporary file path
|
||||
try (InputStream in = jarInJar.openStream())
|
||||
{
|
||||
Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to copy jar-in-jar to temporary path", e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return path.toUri().toURL();
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to get URL from path", e);
|
||||
}
|
||||
}
|
||||
}
|
265
server/src/main/java/dev/plex/module/loader/LibraryLoader.java
Normal file
265
server/src/main/java/dev/plex/module/loader/LibraryLoader.java
Normal file
@ -0,0 +1,265 @@
|
||||
package dev.plex.module.loader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.module.PlexModule;
|
||||
import dev.plex.module.PlexModuleFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.collection.CollectRequest;
|
||||
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.impl.DefaultServiceLocator;
|
||||
import org.eclipse.aether.repository.LocalRepository;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
import org.eclipse.aether.repository.RepositoryPolicy;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
import org.eclipse.aether.resolution.DependencyRequest;
|
||||
import org.eclipse.aether.resolution.DependencyResolutionException;
|
||||
import org.eclipse.aether.resolution.DependencyResult;
|
||||
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
|
||||
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
|
||||
import org.eclipse.aether.transfer.AbstractTransferListener;
|
||||
import org.eclipse.aether.transfer.TransferCancelledException;
|
||||
import org.eclipse.aether.transfer.TransferEvent;
|
||||
import org.eclipse.aether.transport.http.HttpTransporterFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
//TODO: doesn't work
|
||||
|
||||
public class LibraryLoader
|
||||
{
|
||||
private final Logger logger;
|
||||
private final RepositorySystem repository;
|
||||
private final DefaultRepositorySystemSession session;
|
||||
private final List<RemoteRepository> repositories;
|
||||
|
||||
public LibraryLoader(@NotNull Logger logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
|
||||
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
|
||||
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
|
||||
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
|
||||
|
||||
this.repository = locator.getService(RepositorySystem.class);
|
||||
this.session = MavenRepositorySystemUtils.newSession();
|
||||
|
||||
session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
|
||||
session.setLocalRepositoryManager(repository.newLocalRepositoryManager(session, new LocalRepository("libraries")));
|
||||
session.setTransferListener(new AbstractTransferListener()
|
||||
{
|
||||
@Override
|
||||
public void transferStarted(@NotNull TransferEvent event) throws TransferCancelledException
|
||||
{
|
||||
logger.log(Level.INFO, "Downloading {0}", event.getResource().getRepositoryUrl() + event.getResource().getResourceName());
|
||||
}
|
||||
});
|
||||
session.setReadOnly();
|
||||
|
||||
this.repositories = repository.newResolutionRepositories(session, Arrays.asList(new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ClassLoader createLoader(@NotNull PlexModule module, @NotNull PlexModuleFile moduleFile)
|
||||
{
|
||||
if (moduleFile.getLibraries().isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
logger.log(Level.INFO, "Loading libraries for {0}", new Object[]{moduleFile.getName()});
|
||||
logger.log(Level.INFO, "[{0}] Loading {1} libraries... please wait", new Object[]
|
||||
{
|
||||
moduleFile.getName(), moduleFile.getLibraries().size()
|
||||
});
|
||||
|
||||
List<Dependency> dependencies = new ArrayList<>();
|
||||
List<Class<?>> classes = Lists.newArrayList();
|
||||
List<File> files = Lists.newArrayList();
|
||||
for (String library : moduleFile.getLibraries())
|
||||
{
|
||||
Artifact artifact = new DefaultArtifact(library);
|
||||
Dependency dependency = new Dependency(artifact, null);
|
||||
|
||||
dependencies.add(dependency);
|
||||
}
|
||||
|
||||
DependencyResult result;
|
||||
try
|
||||
{
|
||||
result = repository.resolveDependencies(session, new DependencyRequest(new CollectRequest((Dependency)null, dependencies, repositories), null));
|
||||
}
|
||||
catch (DependencyResolutionException ex)
|
||||
{
|
||||
throw new RuntimeException("Error resolving libraries", ex);
|
||||
}
|
||||
|
||||
List<URL> jarFiles = new ArrayList<>();
|
||||
for (ArtifactResult artifact : result.getArtifactResults())
|
||||
{
|
||||
File file = artifact.getArtifact().getFile();
|
||||
files.add(file);
|
||||
URL url;
|
||||
try
|
||||
{
|
||||
url = file.toURI().toURL();
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
|
||||
jarFiles.add(url);
|
||||
logger.log(Level.INFO, "[{0}] Loaded library {1}", new Object[]
|
||||
{
|
||||
moduleFile.getName(), file
|
||||
});
|
||||
}
|
||||
|
||||
/*List<URL> jarFiles = Lists.newArrayList();
|
||||
List<Artifact> artifacts = Lists.newArrayList();
|
||||
|
||||
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
|
||||
for (String library : moduleFile.getLibraries()) {
|
||||
Artifact artifact = new DefaultArtifact(library);
|
||||
ArtifactRequest request = new ArtifactRequest();
|
||||
request.setArtifact(artifact);
|
||||
request.addRepository(this.repositories.get(0));
|
||||
try {
|
||||
ArtifactResult result = this.repository.resolveArtifact(this.session, request);
|
||||
artifact = result.getArtifact();
|
||||
jarFiles.add(artifact.getFile().toURI().toURL());
|
||||
logger.log(Level.INFO, "Loaded library {0} for {1}", new Object[]{
|
||||
artifact.getFile().toURI().toURL().toString(),
|
||||
moduleFile.getName()
|
||||
});
|
||||
artifacts.add(artifact);
|
||||
} catch (ArtifactResolutionException | MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}*/
|
||||
logger.log(Level.INFO, "Loaded {0} libraries for {1}", new Object[]{jarFiles.size(), moduleFile.getName()});
|
||||
|
||||
// jarFiles.forEach(jar -> new CustomClassLoader(jar, Plex.class.getClassLoader()));
|
||||
// jarFiles.forEach(jar -> new CustomClassLoader(jar, Plex.class.getClassLoader()));
|
||||
|
||||
/*URLClassLoader loader = new URLClassLoader(jarFiles.toArray(URL[]::new), Plex.class.getClassLoader());
|
||||
|
||||
dependencies.forEach(artifact -> {
|
||||
ArrayList<String> classNames;
|
||||
try {
|
||||
classNames = getClassNamesFromJar(new JarFile(artifact.getArtifact().getFile()));
|
||||
for (String className : classNames) {
|
||||
Class<?> classToLoad = Class.forName(className, true, loader);
|
||||
classes.add(classToLoad);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
classes.forEach(clazz -> logger.log(Level.INFO, "Loading class {0}", new Object[]{clazz.getName()}));*/
|
||||
jarFiles.forEach(url ->
|
||||
{
|
||||
JarURLConnection connection;
|
||||
try
|
||||
{
|
||||
URL url2 = new URL("jar:" + url.toString() + "!/");
|
||||
/*
|
||||
connection = (JarURLConnection) url2.openConnection();
|
||||
logger.log(Level.INFO, "Jar File: " + connection.getJarFileURL().toString());*/
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return new URLClassLoader(files.stream().map(File::toURI).map(uri ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return uri.toURL();
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}).toList().toArray(URL[]::new)/*jarFiles.stream().map(url -> {
|
||||
try {
|
||||
return new URL("jar:" + url.toString() + "!/");
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}).toList().toArray(URL[]::new)*/, Plex.class.getClassLoader())/*new CustomClassLoader(jarFiles.toArray(URL[]::new), Plex.class.getClassLoader())*/;
|
||||
}
|
||||
|
||||
/*public List<Class<?>> loadDependency(List<Path> paths) throws Exception {
|
||||
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
|
||||
for (Path path : paths) {
|
||||
|
||||
URL url = path.toUri().toURL();
|
||||
URLClassLoader child = new URLClassLoader(new URL[]{url}, this.getClass().getClassLoader());
|
||||
|
||||
ArrayList<String> classNames = getClassNamesFromJar(path.toString());
|
||||
|
||||
for (String className : classNames) {
|
||||
Class classToLoad = Class.forName(className, true, child);
|
||||
classes.add(classToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
return classes;
|
||||
}*/
|
||||
|
||||
|
||||
private ArrayList<String> getClassNamesFromJar(JarFile file) throws Exception
|
||||
{
|
||||
ArrayList<String> classNames = new ArrayList<>();
|
||||
try
|
||||
{
|
||||
//Iterate through the contents of the jar file
|
||||
Enumeration<JarEntry> entries = file.entries();
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
JarEntry entry = entries.nextElement();
|
||||
//Pick file that has the extension of .class
|
||||
if ((entry.getName().endsWith(".class")))
|
||||
{
|
||||
String className = entry.getName().replaceAll("/", "\\.");
|
||||
String myClass = className.substring(0, className.lastIndexOf('.'));
|
||||
classNames.add(myClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Error while getting class names from jar", e);
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
}
|
14
server/src/main/java/dev/plex/permission/Permission.java
Normal file
14
server/src/main/java/dev/plex/permission/Permission.java
Normal file
@ -0,0 +1,14 @@
|
||||
package dev.plex.permission;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import java.util.UUID;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class Permission
|
||||
{
|
||||
private final UUID uuid;
|
||||
private final String permission;
|
||||
private boolean allowed = true;
|
||||
}
|
147
server/src/main/java/dev/plex/player/PlexPlayer.java
Normal file
147
server/src/main/java/dev/plex/player/PlexPlayer.java
Normal file
@ -0,0 +1,147 @@
|
||||
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.api.player.IPlexPlayer;
|
||||
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 java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity(value = "players", useDiscriminator = false)
|
||||
public class PlexPlayer implements IPlexPlayer
|
||||
{
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Indexed(options = @IndexOptions(unique = true))
|
||||
private UUID uuid;
|
||||
|
||||
@Indexed
|
||||
private String name;
|
||||
private transient Player player;
|
||||
|
||||
private String loginMessage;
|
||||
private String prefix;
|
||||
|
||||
private boolean vanished;
|
||||
private boolean commandSpy;
|
||||
|
||||
// These fields are transient so MongoDB doesn't automatically drop them in.
|
||||
private transient boolean frozen;
|
||||
private transient boolean muted;
|
||||
private transient boolean lockedUp;
|
||||
|
||||
private boolean adminActive;
|
||||
|
||||
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;
|
||||
|
||||
public PlexPlayer()
|
||||
{
|
||||
}
|
||||
|
||||
public PlexPlayer(UUID playerUUID)
|
||||
{
|
||||
this.uuid = playerUUID;
|
||||
|
||||
this.id = uuid.toString().substring(0, 8);
|
||||
|
||||
this.name = "";
|
||||
this.player = Bukkit.getPlayer(name);
|
||||
|
||||
this.loginMessage = "";
|
||||
this.prefix = "";
|
||||
|
||||
this.vanished = false;
|
||||
this.commandSpy = false;
|
||||
|
||||
this.coins = 0;
|
||||
|
||||
this.rank = "";
|
||||
this.loadPunishments();
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
|
||||
}
|
||||
}
|
||||
|
||||
public String displayName()
|
||||
{
|
||||
return PlainTextComponentSerializer.plainText().serialize(player.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 CompletableFuture<List<Note>> loadNotes()
|
||||
{
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getSqlNotes().getNotes(this.getUuid());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
65
server/src/main/java/dev/plex/punishment/Punishment.java
Normal file
65
server/src/main/java/dev/plex/punishment/Punishment.java
Normal file
@ -0,0 +1,65 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class Punishment
|
||||
{
|
||||
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
||||
private final UUID punished;
|
||||
private final UUID punisher;
|
||||
private String ip;
|
||||
private String punishedUsername;
|
||||
private PunishmentType type;
|
||||
private String reason;
|
||||
private boolean customTime;
|
||||
private boolean active; // Field is only for bans
|
||||
private ZonedDateTime endDate;
|
||||
|
||||
public Punishment()
|
||||
{
|
||||
this.punished = null;
|
||||
this.punisher = null;
|
||||
}
|
||||
|
||||
public Punishment(UUID punished, UUID punisher)
|
||||
{
|
||||
this.punished = punished;
|
||||
this.punisher = punisher;
|
||||
}
|
||||
|
||||
public static Component generateBanMessage(Punishment punishment)
|
||||
{
|
||||
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
||||
}
|
||||
|
||||
public static Component generateIndefBanMessage(String type)
|
||||
{
|
||||
return PlexUtils.messageComponent("indefBanMessage", type, banUrl);
|
||||
}
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
261
server/src/main/java/dev/plex/punishment/PunishmentManager.java
Normal file
261
server/src/main/java/dev/plex/punishment/PunishmentManager.java
Normal file
@ -0,0 +1,261 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PunishmentManager implements PlexBase
|
||||
{
|
||||
@Getter
|
||||
private final List<IndefiniteBan> indefiniteBans = Lists.newArrayList();
|
||||
|
||||
public void mergeIndefiniteBans()
|
||||
{
|
||||
this.indefiniteBans.clear();
|
||||
Plex.get().indefBans.getKeys(false).forEach(key ->
|
||||
{
|
||||
IndefiniteBan ban = new IndefiniteBan();
|
||||
ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips"));
|
||||
ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users"));
|
||||
ban.uuids.addAll(Plex.get().getIndefBans().getStringList(key + ".uuids").stream().map(UUID::fromString).toList());
|
||||
this.indefiniteBans.add(ban);
|
||||
});
|
||||
|
||||
PlexLog.log("Loaded {0} UUID(s), {1} IP(s), and {2} username(s) as indefinitely banned", this.indefiniteBans.stream().map(IndefiniteBan::getUuids).mapToLong(Collection::size).sum(), this.indefiniteBans.stream().map(IndefiniteBan::getIps).mapToLong(Collection::size).sum(), this.indefiniteBans.stream().map(IndefiniteBan::getUsernames).mapToLong(Collection::size).sum());
|
||||
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
PlexLog.log("Asynchronously uploading all indefinite bans to Redis");
|
||||
Plex.get().getRedisConnection().runAsync(jedis ->
|
||||
{
|
||||
jedis.set("indefbans", new Gson().toJson(indefiniteBans));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIndefUUIDBanned(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
PlexLog.debug("Checking if UUID is banned in Redis");
|
||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||
{
|
||||
}.getType());
|
||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
|
||||
}
|
||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
|
||||
}
|
||||
|
||||
public boolean isIndefIPBanned(String ip)
|
||||
{
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
PlexLog.debug("Checking if IP is banned in Redis");
|
||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||
{
|
||||
}.getType());
|
||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
|
||||
}
|
||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
|
||||
}
|
||||
|
||||
public boolean isIndefUserBanned(String username)
|
||||
{
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
PlexLog.debug("Checking if username is banned in Redis");
|
||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||
{
|
||||
}.getType());
|
||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
|
||||
}
|
||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> isAsyncBanned(UUID uuid)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(uuid);
|
||||
player.loadPunishments();
|
||||
return player.getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isBanned(UUID uuid)
|
||||
{
|
||||
// TODO: If a person is using MongoDB, this will error out because it is checking for bans on a player that doesn't exist yet
|
||||
/*if (!DataUtils.hasPlayedBefore(uuid))
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
|
||||
}
|
||||
|
||||
public boolean isBanned(PlexPlayer player)
|
||||
{
|
||||
return isBanned(player.getUuid());
|
||||
}
|
||||
|
||||
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<>();
|
||||
Plex.get().getSqlPunishment().getPunishments().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
//PlexLog.debug("Received Punishments");
|
||||
List<Punishment> punishmentList = punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
|
||||
//PlexLog.debug("Completing with {0} punishments", punishmentList.size());
|
||||
future.complete(punishmentList);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
||||
public void unban(Punishment punishment)
|
||||
{
|
||||
this.unban(punishment.getPunished());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (punishment.getType() == PunishmentType.FREEZE)
|
||||
{
|
||||
player.setFrozen(true);
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
ZonedDateTime then = punishment.getEndDate();
|
||||
long seconds = ChronoUnit.SECONDS.between(now, then);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!player.isFrozen())
|
||||
{
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
player.setFrozen(false);
|
||||
Bukkit.broadcast(PlexUtils.messageComponent("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(player.getUuid()).getName()));
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||
}
|
||||
else if (punishment.getType() == PunishmentType.MUTE)
|
||||
{
|
||||
player.setMuted(true);
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
ZonedDateTime then = punishment.getEndDate();
|
||||
long seconds = ChronoUnit.SECONDS.between(now, then);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!player.isMuted())
|
||||
{
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
player.setMuted(false);
|
||||
Bukkit.broadcast(PlexUtils.messageComponent("unmutedPlayer", "Plex", Bukkit.getOfflinePlayer(player.getUuid()).getName()));
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||
}
|
||||
}
|
||||
|
||||
public void punish(PlexPlayer player, Punishment punishment)
|
||||
{
|
||||
issuePunishment(player, punishment);
|
||||
doPunishment(player, punishment);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class IndefiniteBan
|
||||
{
|
||||
private final List<String> usernames = Lists.newArrayList();
|
||||
private final List<UUID> uuids = Lists.newArrayList();
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
public enum PunishmentType
|
||||
{
|
||||
MUTE, FREEZE, BAN, KICK, SMITE, TEMPBAN
|
||||
}
|
26
server/src/main/java/dev/plex/punishment/extra/Note.java
Normal file
26
server/src/main/java/dev/plex/punishment/extra/Note.java
Normal file
@ -0,0 +1,26 @@
|
||||
package dev.plex.punishment.extra;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class Note
|
||||
{
|
||||
private final UUID uuid;
|
||||
private final String note;
|
||||
private final UUID writtenBy;
|
||||
private final ZonedDateTime timestamp;
|
||||
|
||||
private int id; // This will be automatically set from addNote
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
174
server/src/main/java/dev/plex/rank/RankManager.java
Normal file
174
server/src/main/java/dev/plex/rank/RankManager.java
Normal file
@ -0,0 +1,174 @@
|
||||
package dev.plex.rank;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.rank.enums.Title;
|
||||
import dev.plex.util.PlexUtils;
|
||||
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;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
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 getPrefix(PlexPlayer player)
|
||||
{
|
||||
if (!player.getPrefix().equals(""))
|
||||
{
|
||||
return PlexUtils.mmCustomDeserialize(player.getPrefix(), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition());
|
||||
}
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
{
|
||||
return Title.OWNER.getPrefix();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(player.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(player.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getPrefix();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||
{
|
||||
return player.getRankFromString().getPrefix();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLoginMessage(PlexPlayer player)
|
||||
{
|
||||
if (!player.getLoginMessage().isEmpty())
|
||||
{
|
||||
return player.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
{
|
||||
return Title.OWNER.getLoginMessage();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return Title.DEV.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||
{
|
||||
return player.getRankFromString().getLoginMessage();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public NamedTextColor getColor(PlexPlayer player)
|
||||
{
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
{
|
||||
return Title.OWNER.getColor();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(player.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(player.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getColor();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||
{
|
||||
return player.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();
|
||||
}
|
||||
}
|
61
server/src/main/java/dev/plex/rank/enums/Rank.java
Normal file
61
server/src/main/java/dev/plex/rank/enums/Rank.java
Normal file
@ -0,0 +1,61 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import dev.plex.api.rank.IRank;
|
||||
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 implements IRank
|
||||
{
|
||||
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;
|
||||
|
||||
@Setter
|
||||
private String loginMessage;
|
||||
|
||||
@Setter
|
||||
private String readable;
|
||||
|
||||
@Setter
|
||||
private String prefix;
|
||||
|
||||
@Getter
|
||||
private NamedTextColor color;
|
||||
|
||||
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(IRank 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);
|
||||
}
|
||||
}
|
52
server/src/main/java/dev/plex/rank/enums/Title.java
Normal file
52
server/src/main/java/dev/plex/rank/enums/Title.java
Normal file
@ -0,0 +1,52 @@
|
||||
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;
|
||||
|
||||
@Setter
|
||||
private String loginMessage;
|
||||
|
||||
@Setter
|
||||
private String readable;
|
||||
|
||||
@Setter
|
||||
private String prefix;
|
||||
|
||||
@Getter
|
||||
private NamedTextColor color;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
31
server/src/main/java/dev/plex/services/AbstractService.java
Normal file
31
server/src/main/java/dev/plex/services/AbstractService.java
Normal file
@ -0,0 +1,31 @@
|
||||
package dev.plex.services;
|
||||
|
||||
import dev.plex.PlexBase;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractService implements IService, PlexBase
|
||||
{
|
||||
private boolean asynchronous;
|
||||
private boolean repeating;
|
||||
|
||||
@Setter
|
||||
private int taskId;
|
||||
|
||||
public AbstractService(boolean repeating, boolean async)
|
||||
{
|
||||
this.repeating = repeating;
|
||||
this.asynchronous = async;
|
||||
}
|
||||
|
||||
public void onStart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void onEnd()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
server/src/main/java/dev/plex/services/IService.java
Normal file
8
server/src/main/java/dev/plex/services/IService.java
Normal file
@ -0,0 +1,8 @@
|
||||
package dev.plex.services;
|
||||
|
||||
public interface IService
|
||||
{
|
||||
void run();
|
||||
|
||||
int repeatInSeconds();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user