This commit is contained in:
rayzsyt committed 2025-07-24 03:39:13 +02:00
1 parent d66c02d0ec
commit 6b743772cb
34 files changed
+2287

No files matched your search

@@ -0,0 +1,45 @@
package de.rayzs.pat.api.command;
import de.rayzs.pat.utils.*;
import java.util.*;
public abstract class ProCommand {
private final String name;
private final List<String> aliases;
protected boolean proxyOnly = false, serverCommand = false;
public ProCommand(String name, String... aliases) {
this.name = name.toLowerCase();
this.aliases = aliases != null && !aliases[0].isBlank() ? Arrays.asList(aliases) : new ArrayList<>();
}
public String getName() {
return name;
}
public boolean isProxyOnly() {
return proxyOnly;
}
public boolean isServerCommand() {
return serverCommand;
}
public List<String> getAliases() {
return aliases;
}
public boolean isCommand(String label) {
String commandName = StringUtils.getFirstArg(label);
if (name.equalsIgnoreCase(commandName))
return true;
return !aliases.isEmpty() && aliases.stream().anyMatch(commandName::equalsIgnoreCase);
}
public abstract boolean execute(CommandSender sender, String[] args);
public abstract List<String> tabComplete(CommandSender sender, String[] args);
}
@@ -0,0 +1,37 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.utils.permission.PermissionUtil;
public class AutoLowercaseCommandsSection extends ConfigStorage {
public boolean ENABLED;
public AutoLowercaseCommandsSection() {
super("auto-lowercase-commands");
}
@Override
public void load() {
super.load();
if (Reflection.isProxyServer())
return;
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
}
public boolean isCommand(String command) {
if(!ENABLED) return false;
return !StringUtils.isLowercased(command);
}
public boolean doesBypass(Object targetObj) {
return !ENABLED || PermissionUtil.hasPermission(targetObj, "auto-lowercase");
}
}
@@ -0,0 +1,33 @@
package de.rayzs.pat.plugin;
import de.rayzs.pat.utils.CommandsCache;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public interface PluginLoader {
HashMap<String, CommandsCache> getCommandsCacheMap();
void updateCommandCache();
List<String> getServerNames();
UUID getUUIDByName(String playerName);
String getNameByUUID(UUID uuid);
String getPlayerServerName(UUID uuid);
boolean isPlayerOnline(String playerName);
boolean doesPlayerExist(String playerName);
List<String> getOnlinePlayerNames(String server);
List<UUID> getPlayerIdsByServer(String server);
List<UUID> getPlayerIds();
List<String> getPlayerNames();
List<String> getOnlinePlayerNames();
List<String> getOfflinePlayerNames();
}
@@ -0,0 +1,3 @@
package de.rayzs.pat.plugin.logger;
public enum LoggerPriority { INFO, WARNING, DEBUG }
@@ -0,0 +1,23 @@
package de.rayzs.pat.plugin.logger;
import java.text.SimpleDateFormat;
import java.util.List;
public interface LoggerTemplate {
SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss:SS");
List<String> getLogs();
void info(List<String> messages);
void warn(List<String> messages);
void debug(List<String> messages);
void send(LoggerPriority priority, List<String> messages);
void info(String message);
void warn(String message);
void debug(String message);
void send(LoggerPriority priority, String message);
}
@@ -0,0 +1,79 @@
package de.rayzs.pat.plugin.logger.impl;
import de.rayzs.pat.plugin.BukkitLoader;
import de.rayzs.pat.plugin.logger.LoggerPriority;
import de.rayzs.pat.plugin.logger.LoggerTemplate;
import de.rayzs.pat.utils.message.MessageTranslator;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class BukkitLogger implements LoggerTemplate {
private final List<String> LOGS = new ArrayList<>();
private final java.util.logging.Logger logger = BukkitLoader.getPluginLogger();
@Override
public List<String> getLogs() {
return LOGS;
}
@Override
public void info(List<String> messages) {
messages.forEach(this::info);
}
@Override
public void warn(List<String> messages) {
messages.forEach(this::warn);
}
@Override
public void debug(List<String> messages) {
messages.forEach(this::debug);
}
@Override
public void send(LoggerPriority priority, List<String> messages) {
messages.forEach(message -> send(priority, message));
}
@Override
public void info(String message) {
send(LoggerPriority.INFO, message);
}
@Override
public void warn(String message) {
send(LoggerPriority.WARNING, message);
}
@Override
public void debug(String message) {
send(LoggerPriority.DEBUG, message);
}
@Override
public void send(LoggerPriority priority, String message) {
message = MessageTranslator.replaceMessage(message);
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
LOGS.add("[" + priority.name() + " | " + time + "] " + MessageTranslator.colorless(message));
if (priority == LoggerPriority.DEBUG)
return;
if (message.contains("§")) {
MessageTranslator.send(Bukkit.getServer().getConsoleSender(), message);
return;
}
switch (priority) {
case INFO -> logger.info(message);
case WARNING -> logger.warning(message);
}
}
}
@@ -0,0 +1,79 @@
package de.rayzs.pat.plugin.logger.impl;
import de.rayzs.pat.plugin.BungeeLoader;
import de.rayzs.pat.plugin.logger.LoggerPriority;
import de.rayzs.pat.plugin.logger.LoggerTemplate;
import de.rayzs.pat.utils.message.MessageTranslator;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class BungeeLogger implements LoggerTemplate {
private final List<String> LOGS = new ArrayList<>();
private final java.util.logging.Logger logger = BungeeLoader.getPluginLogger();
@Override
public List<String> getLogs() {
return LOGS;
}
@Override
public void info(List<String> messages) {
messages.forEach(this::info);
}
@Override
public void warn(List<String> messages) {
messages.forEach(this::warn);
}
@Override
public void debug(List<String> messages) {
messages.forEach(this::debug);
}
@Override
public void send(LoggerPriority priority, List<String> messages) {
messages.forEach(message -> send(priority, message));
}
@Override
public void info(String message) {
send(LoggerPriority.INFO, message);
}
@Override
public void warn(String message) {
send(LoggerPriority.WARNING, message);
}
@Override
public void debug(String message) {
send(LoggerPriority.DEBUG, message);
}
@Override
public void send(LoggerPriority priority, String message) {
message = MessageTranslator.replaceMessage(message);
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
LOGS.add("[" + priority.name() + " | " + time + "] " + MessageTranslator.colorless(message));
if (priority == LoggerPriority.DEBUG)
return;
if (message.contains("§")) {
MessageTranslator.send(Bukkit.getServer().getConsoleSender(), message);
return;
}
switch (priority) {
case INFO -> logger.info(message);
case WARNING -> logger.warning(message);
}
}
}
@@ -0,0 +1,80 @@
package de.rayzs.pat.plugin.logger.impl;
import de.rayzs.pat.plugin.VelocityLoader;
import de.rayzs.pat.plugin.logger.LoggerPriority;
import de.rayzs.pat.plugin.logger.LoggerTemplate;
import de.rayzs.pat.utils.message.MessageTranslator;
import org.bukkit.Bukkit;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class VelocityLogger implements LoggerTemplate {
private final List<String> LOGS = new ArrayList<>();
private final Logger logger = VelocityLoader.getPluginLogger();
@Override
public List<String> getLogs() {
return LOGS;
}
@Override
public void info(List<String> messages) {
messages.forEach(this::info);
}
@Override
public void warn(List<String> messages) {
messages.forEach(this::warn);
}
@Override
public void debug(List<String> messages) {
messages.forEach(this::debug);
}
@Override
public void send(LoggerPriority priority, List<String> messages) {
messages.forEach(message -> send(priority, message));
}
@Override
public void info(String message) {
send(LoggerPriority.INFO, message);
}
@Override
public void warn(String message) {
send(LoggerPriority.WARNING, message);
}
@Override
public void debug(String message) {
send(LoggerPriority.DEBUG, message);
}
@Override
public void send(LoggerPriority priority, String message) {
message = MessageTranslator.replaceMessage(message);
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
LOGS.add("[" + priority.name() + " | " + time + "] " + MessageTranslator.colorless(message));
if (priority == LoggerPriority.DEBUG)
return;
if (message.contains("§")) {
MessageTranslator.send(Bukkit.getServer().getConsoleSender(), message);
return;
}
switch (priority) {
case INFO -> logger.info(message);
case WARNING -> logger.warn(message);
}
}
}
@@ -0,0 +1,45 @@
package de.rayzs.pat.plugin.process.impl.local.info;
import de.rayzs.pat.api.communication.Communicator;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.*;
import java.util.List;
public class InfoCommand extends ProCommand {
public InfoCommand() {
super(
"info",
""
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
String message = StringUtils.getStringList(Storage.ConfigSections.Messages.INFO.MESSAGE.getLines(), "\n");
String syncTime = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED || Reflection.isProxyServer()
? Storage.ConfigSections.Messages.INFO.SYNC_TIME.replace("%time%", TimeConverter.calcAndGetTime(Reflection.isProxyServer()
? Communicator.LAST_DATA_UPDATE : Communicator.LAST_BUKKIT_SYNC))
: Storage.ConfigSections.Messages.INFO.SYNC_DISABLED;
String versionStatus = Storage.OUTDATED
? Storage.ConfigSections.Messages.INFO.VERSION_OUTDATED
: Storage.ConfigSections.Messages.INFO.VERSION_UPDATED;
message = StringUtils.replace(message,
"%sync_time%", syncTime,
"%version_status%", versionStatus
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return List.of();
}
}
@@ -0,0 +1,45 @@
package de.rayzs.pat.plugin.process.impl.local.info;
import de.rayzs.pat.utils.permission.PermissionUtil;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import java.util.*;
public class PermsCommand extends ProCommand {
public PermsCommand() {
super(
"perms",
""
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0)
return false;
String name = args[0];
UUID uuid = Storage.getLoader().getUUIDByName(name);
boolean online = uuid != null;
if (online) {
name = Storage.getLoader().getNameByUUID(uuid);
}
sender.sendMessage((online
? Storage.ConfigSections.Messages.PERMS_CHECK.MESSAGE.replace("%permissions%", PermissionUtil.getPermissionsAsString(uuid))
: Storage.ConfigSections.Messages.PERMS_CHECK.PLAYER_NOT_ONLINE
).replace("%player%", name)
);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? Storage.getLoader().getPlayerNames() : null;
}
}
@@ -0,0 +1,72 @@
package de.rayzs.pat.plugin.process.impl.local.info;
import de.rayzs.pat.api.communication.client.ClientInfo;
import de.rayzs.pat.api.communication.Communicator;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.*;
import java.util.List;
public class StatsCommand extends ProCommand {
public StatsCommand() {
super(
"stats",
""
);
proxyOnly = true;
}
@Override
public boolean execute(CommandSender sender, String[] args) {
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if(backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
final int length = Communicator.CLIENTS.size() - 1;
boolean tmpFound = false;
StringBuilder statsBuilder = new StringBuilder();
for (int i = 0; i < Communicator.CLIENTS.size(); i++) {
ClientInfo client = Communicator.CLIENTS.get(i);
if (!client.hasSentFeedback())
continue;
if (!tmpFound)
tmpFound = true;
statsBuilder.append(StringUtils.replace(Storage.ConfigSections.Messages.STATS.SERVER,
"%updated%", client.getSyncTime(), "%servername%", client.getName()
));
if (i <= length)
statsBuilder.append(Storage.ConfigSections.Messages.STATS.SPLITTER);
}
final boolean found = tmpFound;
Storage.ConfigSections.Messages.STATS.STATISTIC.getLines().forEach(message -> {
message = StringUtils.replace(message,
"%server_count%", String.valueOf(Communicator.SERVER_DATA_SYNC_COUNT),
"%last_sync_time%", TimeConverter.calcAndGetTime(Communicator.LAST_DATA_UPDATE),
"%servers%", found ? statsBuilder.toString() : Storage.ConfigSections.Messages.STATS.NO_SERVER
);
sender.sendMessage(message);
});
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return List.of();
}
}
@@ -0,0 +1,55 @@
package de.rayzs.pat.plugin.process.impl.local.info;
import de.rayzs.pat.api.event.PATEventHandler;
import de.rayzs.pat.utils.group.GroupManager;
import de.rayzs.pat.utils.permission.PermissionUtil;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import java.util.*;
public class UpdateCommand extends ProCommand {
public UpdateCommand() {
super(
"update",
""
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0) {
PermissionUtil.reloadPermissions();
sender.sendMessage(Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.UPDATE_ALL);
return true;
}
String name = args[0];
UUID uuid = Storage.getLoader().getUUIDByName(name);
boolean exist = uuid != null;
if (exist) {
name = Storage.getLoader().getNameByUUID(uuid);
}
String message = exist
? Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.UPDATE_SPECIFIC
: Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.PLAYER_NOT_ONLINE;
message = message.replace("%target%", name);
if (exist) {
PermissionUtil.reloadPermissions(uuid);
}
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? Storage.getLoader().getPlayerNames() : null;
}
}
@@ -0,0 +1,128 @@
package de.rayzs.pat.plugin.process.impl.local.modify;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.BukkitLoader;
import de.rayzs.pat.utils.group.*;
import de.rayzs.pat.utils.*;
import java.util.*;
public class AddCommand extends ProCommand {
public AddCommand() {
super(
"add",
""
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0)
return false;
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if (backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
String fullString = String.join(" ", args);
String command = fullString;
if (!command.startsWith("\"")) {
command = args[0];
} else {
command = command.substring(1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
return false;
}
command = command.substring(0, lastIndex);
fullString = fullString.replace("\"" + command + "\"", ":::");
args = fullString.split(" ");
}
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
if (command.isEmpty())
return false;
final int length = args.length;
if (length == 1) {
boolean exist = command.contains(" ")
? Storage.Blacklist.getBlacklist().getCommands().contains(command)
: Storage.Blacklist.getBlacklist().isListed(command);
if (!exist) {
Storage.Blacklist.getBlacklist().add(command).save();
Storage.handleChange();
}
String message = exist ? Storage.ConfigSections.Messages.BLACKLIST.ADD_FAILED : Storage.ConfigSections.Messages.BLACKLIST.ADD_SUCCESS;
message = StringUtils.replace(message, "%command%", command);
sender.sendMessage(message);
return true;
}
String groupName = args[1];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
return true;
}
boolean exist = group.contains(command);
if (!exist) {
group.add(command);
Storage.handleChange();
}
String message = exist ? Storage.ConfigSections.Messages.GROUP.ADD_FAILED : Storage.ConfigSections.Messages.GROUP.ADD_SUCCESS;
message = StringUtils.replace(message, "%group%", groupName, "%command%", command);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
if (args.length == 0 || args.length == 1 && !args[0].startsWith("\"")) {
if (Reflection.isProxyServer())
return null;
return BukkitLoader.getNotBlockedCommands();
}
String fullString = String.join(" ", args);
String command = fullString;
if (args[0].startsWith("\"")) {
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
return null;
}
command = command.substring(0, lastIndex);
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
}
final int length = args.length;
return length == 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,74 @@
package de.rayzs.pat.plugin.process.impl.local.modify;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import java.util.concurrent.TimeUnit;
import de.rayzs.pat.utils.group.*;
import de.rayzs.pat.utils.*;
import java.util.*;
public class ClearCommand extends ProCommand {
private final ExpireCache<UUID, String> CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS);
public ClearCommand() {
super(
"clear",
"clr"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0) {
final String confirmationString = "clear";
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
sender.sendMessage(Storage.ConfigSections.Messages.BLACKLIST.CLEAR_CONFIRM);
return true;
}
Storage.Blacklist.getBlacklist().clear().save();
Storage.handleChange();
CONFIRMATION.remove(sender.getUniqueId());
sender.sendMessage(Storage.ConfigSections.Messages.BLACKLIST.CLEAR);
return true;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
return true;
}
groupName = group.getGroupName();
final String confirmationString = "clear " + groupName;
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.CLEAR_CONFIRM);
return true;
}
group.clear();
Storage.handleChange();
CONFIRMATION.remove(sender.getUniqueId());
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.CLEAR.replace("%group%", groupName));
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,55 @@
package de.rayzs.pat.plugin.process.impl.local.modify;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.List;
public class CreateGroupCommand extends ProCommand {
public CreateGroupCommand() {
super(
"creategroup",
"cg"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0) {
return false;
}
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if (backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
boolean registered = group != null;
if (!registered) {
GroupManager.registerGroup(groupName);
} else groupName = group.getGroupName();
String message = registered ? Storage.ConfigSections.Messages.GROUP.ALREADY_EXIST : Storage.ConfigSections.Messages.GROUP.CREATE;
message = StringUtils.replace(message, "%group%", groupName);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,74 @@
package de.rayzs.pat.plugin.process.impl.local.modify;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.ExpireCache;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class DeleteGroupCommand extends ProCommand {
private final ExpireCache<UUID, String> CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS);
public DeleteGroupCommand() {
super(
"deletegroup",
"dg"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0) {
return false;
}
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if (backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
boolean registered = group != null;
if (!registered) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
return true;
}
groupName = group.getGroupName();
String confirmationString = "deletegroup " + groupName;
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DELETE_CONFIRM);
return true;
}
GroupManager.unregisterGroup(groupName);
CONFIRMATION.remove(sender.getUniqueId());
String message = registered ? Storage.ConfigSections.Messages.GROUP.DELETE : Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST;
message = StringUtils.replace(message, "%group%", groupName);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,135 @@
package de.rayzs.pat.plugin.process.impl.local.modify;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.group.*;
import de.rayzs.pat.utils.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public class RemoveCommand extends ProCommand {
public RemoveCommand() {
super(
"remove",
"rem", "rm"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0)
return false;
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if (backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
String fullString = String.join(" ", args);
String command = fullString;
if (!command.startsWith("\"")) {
command = args[0];
} else {
command = command.substring(1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
return false;
}
command = command.substring(0, lastIndex);
fullString = fullString.replace("\"" + command + "\"", ":::");
args = fullString.split(" ");
}
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
if (command.isEmpty())
return false;
final int length = args.length;
if (length == 1) {
boolean exist = command.contains(" ")
? Storage.Blacklist.getBlacklist().getCommands().contains(command)
: Storage.Blacklist.getBlacklist().isListed(command);
if (exist) {
Storage.Blacklist.getBlacklist().remove(command).save();
Storage.handleChange();
}
String message = !exist ? Storage.ConfigSections.Messages.BLACKLIST.REMOVE_FAILED : Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SUCCESS;
message = StringUtils.replace(message, "%command%", command);
sender.sendMessage(message);
return true;
}
String groupName = args[1];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
return true;
}
boolean exist = group.contains(command);
if (exist) {
group.remove(command);
Storage.handleChange();
}
String message = !exist ? Storage.ConfigSections.Messages.GROUP.REMOVE_FAILED : Storage.ConfigSections.Messages.GROUP.REMOVE_SUCCESS;
message = StringUtils.replace(message, "%group%", groupName, "%command%", command);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
if (args.length == 0 || args.length == 1 && !args[0].startsWith("\"")) {
return new ArrayList<>(Storage.Blacklist.getBlacklist().getCommands()).stream().filter(str -> !str.contains(" ")).toList();
}
String fullString = String.join(" ", args);
String command = fullString;
if (args[0].startsWith("\"")) {
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
if (args.length == 1) {
Stream<String> stream = new ArrayList<>(Storage.Blacklist.getBlacklist().getCommands())
.stream()
.filter(str -> str.contains(" "));
if (!Reflection.isProxyServer())
stream = stream.map(str -> "\"" + str + "\"");
return stream.toList();
}
return null;
}
command = command.substring(0, lastIndex);
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
}
final int length = args.length;
return length == 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,69 @@
package de.rayzs.pat.plugin.process.impl.local.modify;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.List;
public class SetPriorityCommand extends ProCommand {
public SetPriorityCommand() {
super(
"setpriority",
"sp"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if (backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
if (args.length < 2) {
return false;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
return true;
}
String priorityStr = args[1];
try {
int priority = Integer.parseInt(priorityStr);
if (priority > 0) {
group.setPriority(priority);
GroupManager.sort();
Storage.handleChange();
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.PRIORITY_SUCCESS.replace("%group%", group.getGroupName()).replace("%priority%", priorityStr));
return true;
}
} catch (Exception ignored) {}
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.PRIORITY_FAILED.replace("%group%", groupName).replace("%priority%", priorityStr));
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,66 @@
package de.rayzs.pat.plugin.process.impl.local.modify.list;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import java.util.List;
public class ListCommand extends ProCommand {
public ListCommand() {
super(
"list",
"ls"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 0) {
String commandsListMessage = StringUtils.getStringList(
Storage.Blacklist.getBlacklist().getCommands(),
Storage.ConfigSections.Messages.BLACKLIST.LIST_SPLITTER
);
String message = Storage.ConfigSections.Messages.BLACKLIST.LIST_MESSAGE;
message = StringUtils.replace(message,
"%size%", String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size()),
"%commands%", commandsListMessage
);
sender.sendMessage(message);
return true;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
return true;
}
String commandsListMessage = StringUtils.getStringList(
group.getCommands(),
Storage.ConfigSections.Messages.GROUP.LIST_SPLITTER
);
String message = Storage.ConfigSections.Messages.GROUP.LIST_MESSAGE;
message = StringUtils.replace(message,
"%group%", groupName,
"%size%", String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size()),
"%commands%", commandsListMessage
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,39 @@
package de.rayzs.pat.plugin.process.impl.local.modify.list;
import de.rayzs.pat.utils.group.GroupManager;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.*;
import java.util.List;
public class ListGroupsCommand extends ProCommand {
public ListGroupsCommand() {
super(
"listgroups",
"lg"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
String groupsListMessage = StringUtils.getStringList(
GroupManager.getGroupNames(),
Storage.ConfigSections.Messages.GROUP.LIST_SPLITTER
);
String message = Storage.ConfigSections.Messages.GROUP.LIST_GROUP_MESSAGE;
message = StringUtils.replace(message,
"%size%", String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size()),
"%groups%", groupsListMessage
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return null;
}
}
@@ -0,0 +1,59 @@
package de.rayzs.pat.plugin.process.impl.local.modify.list;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.List;
public class ListPrioritiesCommand extends ProCommand {
public ListPrioritiesCommand() {
super(
"listpriorities",
"lp"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
String groupsPriorityListMessage = buildGroupPriorityMessage(
GroupManager.getGroups(),
Storage.ConfigSections.Messages.GROUP.LIST_PRIORITY_SPLITTER,
Storage.ConfigSections.Messages.GROUP.LIST_PRIORITY_GROUPS
);
String message = StringUtils.replace(groupsPriorityListMessage,
"%size%", String.valueOf(GroupManager.getGroups().size()),
"%groups%", groupsPriorityListMessage
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length < 2 ? GroupManager.getGroupNames() : null;
}
private String buildGroupPriorityMessage(List<Group> list, String splitter, String format) {
StringBuilder builder = new StringBuilder();
boolean end;
Group group;
for (int i = 0; i < list.size(); i++) {
end = i >= list.size() - 1;
group = list.get(i);
builder.append(format.replace("%group%", group.getGroupName()).replace("%priority%", String.valueOf(group.getPriority())));
if (!end && splitter != null) builder.append(splitter);
}
return builder.toString();
}
}
@@ -0,0 +1,55 @@
package de.rayzs.pat.plugin.process.impl.local.system;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.Reflection;
import java.util.List;
public class NotifyCommand extends ProCommand {
public NotifyCommand() {
super(
"notify",
""
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
if (backend) {
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
return true;
}
boolean enabled = false;
if (sender.isConsole()) {
enabled = Storage.SEND_CONSOLE_NOTIFICATION;
Storage.SEND_CONSOLE_NOTIFICATION = !Storage.SEND_CONSOLE_NOTIFICATION;
} else {
enabled = Storage.NOTIFY_PLAYERS.contains(sender.getUniqueId());
if (enabled)
Storage.NOTIFY_PLAYERS.remove(sender.getUniqueId());
else
Storage.NOTIFY_PLAYERS.add(sender.getUniqueId());
}
String message = enabled
? Storage.ConfigSections.Messages.NOTIFICATION.DISABLED
: Storage.ConfigSections.Messages.NOTIFICATION.ENABLED;
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return null;
}
}
@@ -0,0 +1,35 @@
package de.rayzs.pat.plugin.process.impl.local.system;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.api.storage.Storage;
import java.util.*;
public class PostDebugCommand extends ProCommand {
public PostDebugCommand() {
super(
"postdebug",
""
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
try {
sender.sendMessage(Storage.ConfigSections.Messages.POST_DEBUG.SUCCESS.replace("%link%", Objects.requireNonNull(Logger.post())));
} catch (Exception exception) {
sender.sendMessage(Storage.ConfigSections.Messages.POST_DEBUG.FAILED);
exception.printStackTrace();
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return List.of();
}
}
@@ -0,0 +1,55 @@
package de.rayzs.pat.plugin.process.impl.local.system;
import de.rayzs.pat.api.communication.BackendUpdater;
import de.rayzs.pat.api.brand.CustomServerBrand;
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
import de.rayzs.pat.utils.group.GroupManager;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.Reflection;
import java.util.List;
public class ReloadCommand extends ProCommand {
public ReloadCommand() {
super(
"reload",
"rl"
);
}
@Override
public boolean execute(CommandSender sender, String[] args) {
boolean proxy = Reflection.isProxyServer();
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !proxy;
sender.sendMessage(Storage.ConfigSections.Messages.RELOAD.LOADING);
Storage.loadAll(Reflection.isProxyServer() || !backend);
CustomServerBrand.initialize();
GroupManager.clearAllGroups();
GroupManager.initialize();
if (!proxy) {
BackendUpdater.stop();
BackendUpdater.start();
}
ConfigUpdater.broadcastMissingParts();
if (!backend) {
Storage.handleChange();
}
ConfigUpdater.initialize();
sender.sendMessage(Storage.ConfigSections.Messages.RELOAD.DONE);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return null;
}
}
@@ -0,0 +1,149 @@
package de.rayzs.pat.plugin.process.impl.server;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
import de.rayzs.pat.plugin.BukkitLoader;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.NumberUtils;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ServAddCommand extends ProCommand {
public ServAddCommand() {
super(
"add",
""
);
proxyOnly = true;
serverCommand = true;
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length < 2)
return false;
String serverName = args[0];
args = Arrays.copyOfRange(args, 1, args.length);
String fullString = String.join(" ", args);
String command = fullString;
if (!command.startsWith("\"")) {
command = args[0];
} else {
command = command.substring(1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
return false;
}
command = command.substring(0, lastIndex);
fullString = fullString.replace("\"" + command + "\"", ":::");
args = fullString.split(" ");
}
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
if (command.isEmpty())
return false;
final int length = args.length;
if (length == 1) {
GeneralBlacklist blacklist = Storage.Blacklist.getServerBlacklist(serverName);
boolean exist = command.contains(" ")
? blacklist.getCommands().contains(command)
: blacklist.isListed(command);
if (!exist) {
blacklist.add(command).save();
Storage.handleChange(serverName);
}
String message = exist
? Storage.ConfigSections.Messages.BLACKLIST.ADD_SERVER_FAILED
: Storage.ConfigSections.Messages.BLACKLIST.ADD_SERVER_SUCCESS;
message = StringUtils.replace(message,
"%command%", command,
"%server%", serverName
);
sender.sendMessage(message);
return true;
}
String groupName = args[1];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER.replace("%group%", groupName));
return true;
}
boolean exist = group.contains(command, serverName);
if (!exist) {
group.add(command, serverName);
Storage.handleChange(serverName);
}
String message = exist
? Storage.ConfigSections.Messages.GROUP.ADD_SERVER_FAILED
: Storage.ConfigSections.Messages.GROUP.ADD_SERVER_SUCCESS;
message = StringUtils.replace(message,
"%group%", groupName,
"%command%", command,
"%server%", serverName
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
if (args.length < 2) {
return Storage.getServers(true);
}
args = Arrays.copyOfRange(args, 1, args.length);
String fullString = String.join(" ", args);
String command = fullString;
if (args[0].startsWith("\"")) {
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
return null;
}
command = command.substring(0, lastIndex);
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
}
final int length = args.length;
return length == 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,114 @@
package de.rayzs.pat.plugin.process.impl.server;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.ExpireCache;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class ServClearCommand extends ProCommand {
private final ExpireCache<UUID, String> CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS);
public ServClearCommand() {
super(
"clear",
"clr"
);
proxyOnly = true;
serverCommand = true;
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length < 1)
return false;
String serverName = args[0];
args = Arrays.copyOfRange(args, 1, args.length);
if (args.length == 0) {
final String confirmationString = "clear";
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
sender.sendMessage(
Storage.ConfigSections.Messages.BLACKLIST.CLEAR_SERVER_CONFIRM
.replace("%server%", serverName)
);
return true;
}
Storage.Blacklist.getServerBlacklist(serverName).clear().save();
Storage.handleChange(serverName);
CONFIRMATION.remove(sender.getUniqueId());
sender.sendMessage(
Storage.ConfigSections.Messages.BLACKLIST.CLEAR_SERVER
.replace("%server%", serverName)
);
return true;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(
Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER
.replace("%group%", groupName)
.replace("%server%", serverName)
);
return true;
}
groupName = group.getGroupName();
final String confirmationString = "clear " + groupName;
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
sender.sendMessage(
Storage.ConfigSections.Messages.GROUP.CLEAR_SERVER_CONFIRM
.replace("%group%", groupName)
.replace("%server%", serverName)
);
return true;
}
group.clear(serverName);
Storage.handleChange(serverName);
CONFIRMATION.remove(sender.getUniqueId());
sender.sendMessage(
Storage.ConfigSections.Messages.GROUP.CLEAR_SERVER
.replace("%group%", groupName)
.replace("%server%", serverName)
);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
final int length = args.length;
return length < 2 ? Storage.Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList() :
length < 3 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,167 @@
package de.rayzs.pat.plugin.process.impl.server;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
public class ServRemoveCommand extends ProCommand {
public ServRemoveCommand() {
super(
"remove",
"rem", "rm"
);
proxyOnly = true;
serverCommand = true;
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length < 2)
return false;
String serverName = args[0];
args = Arrays.copyOfRange(args, 1, args.length);
String fullString = String.join(" ", args);
String command = fullString;
if (!command.startsWith("\"")) {
command = args[0];
} else {
command = command.substring(1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
return false;
}
command = command.substring(0, lastIndex);
fullString = fullString.replace("\"" + command + "\"", ":::");
args = fullString.split(" ");
}
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
if (command.isEmpty())
return false;
final int length = args.length;
if (length == 1) {
GeneralBlacklist blacklist = Storage.Blacklist.getServerBlacklist(serverName);
boolean exist = command.contains(" ")
? blacklist.getCommands().contains(command)
: blacklist.isListed(command);
if (exist) {
blacklist.remove(command).save();
Storage.handleChange(serverName);
}
String message = !exist
? Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SERVER_FAILED
: Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SERVER_SUCCESS;
message = StringUtils.replace(message,
"%command%", command,
"%server%", serverName
);
sender.sendMessage(message);
return true;
}
String groupName = args[1];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(
Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER
.replace("%group%", groupName)
.replace("%server%", serverName)
);
return true;
}
boolean exist = group.contains(command, serverName);
if (exist) {
group.remove(command, serverName);
Storage.handleChange(serverName);
}
String message = !exist
? Storage.ConfigSections.Messages.GROUP.REMOVE_SERVER_FAILED
: Storage.ConfigSections.Messages.GROUP.REMOVE_SERVER_SUCCESS;
message = StringUtils.replace(message,
"%group%", groupName,
"%command%", command,
"%server%", serverName
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
if (args.length < 2) {
return Storage.Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList();
}
String serverName = args[0];
args = Arrays.copyOfRange(args, 1, args.length);
String fullString = String.join(" ", args);
String command = fullString;
if (args[0].startsWith("\"")) {
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
int lastIndex = command.indexOf("\"");
if (lastIndex == -1) {
if (args.length == 1) {
Stream<String> stream = new ArrayList<>(Storage.Blacklist.getServerBlacklist(serverName).getCommands())
.stream()
.filter(str -> str.contains(" "));
if (!Reflection.isProxyServer())
stream = stream.map(str -> "\"" + str + "\"");
return stream.toList();
}
return null;
}
command = command.substring(0, lastIndex);
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
}
final int length = args.length;
return length == 2 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,87 @@
package de.rayzs.pat.plugin.process.impl.server.list;
import de.rayzs.pat.api.command.ProCommand;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
import de.rayzs.pat.utils.CommandSender;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.Group;
import de.rayzs.pat.utils.group.GroupManager;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class ServListCommand extends ProCommand {
public ServListCommand() {
super(
"list",
"ls"
);
proxyOnly = true;
serverCommand = true;
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length < 1)
return false;
String serverName = args[0];
args = Arrays.copyOfRange(args, 1, args.length);
if (args.length == 0) {
GeneralBlacklist blacklist = Storage.Blacklist.getServerBlacklist(serverName);
String commandsListMessage = StringUtils.getStringList(
blacklist.getCommands(),
Storage.ConfigSections.Messages.BLACKLIST.LIST_SERVER_SPLITTER
);
String message = Storage.ConfigSections.Messages.BLACKLIST.LIST_SERVER_MESSAGE;
message = StringUtils.replace(message,
"%size%", String.valueOf(blacklist.getCommands().size()),
"%commands%", commandsListMessage,
"%server%", serverName
);
sender.sendMessage(message);
return true;
}
String groupName = args[0];
Group group = GroupManager.getGroupByName(groupName);
if (group == null) {
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER.replace("%group%", groupName));
return true;
}
String commandsListMessage = StringUtils.getStringList(
group.getCommands(serverName),
Storage.ConfigSections.Messages.GROUP.LIST_SERVER_SPLITTER
);
String message = Storage.ConfigSections.Messages.GROUP.LIST_SERVER_MESSAGE;
message = StringUtils.replace(message,
"%group%", groupName,
"%size%", String.valueOf(group.getCommands(serverName).size()),
"%commands%", commandsListMessage,
"%server%", serverName
);
sender.sendMessage(message);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
final int length = args.length;
return length < 2 ? Storage.Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList() :
length < 3 ? GroupManager.getGroupNames() : null;
}
}
@@ -0,0 +1,31 @@
package de.rayzs.pat.utils;
public class NumberUtils {
public static boolean isBetween(int n, int l, int r) {
int min = Math.min(l, r);
int max = Math.max(l, r);
return n >= min && n <= max;
}
public static boolean isDigit(String str) {
if (str == null || str.isBlank())
return false;
int length = str.length();
for (int i = 0; i < length; i++) {
char c = str.charAt(i);
if (c == '.' || c == ',')
continue;
if (!Character.isDigit(c))
return false;
}
return true;
}
}
@@ -0,0 +1,102 @@
package de.rayzs.pat.utils.node;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.*;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class CommandNodeHelper<T> {
private final RootCommandNode<T> rootNode;
public CommandNodeHelper(RootCommandNode<T> rootNode) {
this.rootNode = rootNode;
}
public List<String> getChildrenNames() {
return rootNode.getChildren().stream().map(CommandNode::getName).collect(Collectors.toList());
}
public CommandNodeHelper<T> removeIf(CommandNode<T> node, Predicate<String> predicate) {
if (node != null && node.getRedirect() != null)
node = node.getRedirect();
List<Object> objs = new ArrayList<>();
for (CommandNode<T> n : node.getChildren()) {
if (n == null)
continue;
String name = n.getName();
if (predicate.test(name)) {
objs.add(n);
}
}
for (Object obj : objs) {
node.getChildren().remove(obj);
}
return this;
}
public CommandNodeHelper<T> removeIf(String childName, Predicate<String> predicate) {
CommandNode<T> node = rootNode.getChild(childName);
return removeIf(node, predicate);
}
public CommandNodeHelper<T> removeIf(Predicate<String> predicate) {
return removeIf(rootNode, predicate);
}
public CommandNodeHelper<T> clear() {
rootNode.getChildren().clear();
return this;
}
public CommandNodeHelper<T> clear(String childName) {
CommandNode child = rootNode.getChild(childName);
if (child != null) {
child.getChildren().clear();
}
return this;
}
public CommandNodeHelper<T> remove(Object obj) {
rootNode.getChildren().remove(obj);
return this;
}
public CommandNodeHelper<T> remove(CommandNode node, Object obj) {
node.getChildren().remove(obj);
return this;
}
public CommandNodeHelper<T> add(String commandPath) {
if (commandPath.endsWith("_-"))
commandPath = commandPath.substring(0, commandPath.length() - 3);
String[] args = commandPath.split(" ");
add(rootNode, args, 0);
return this;
}
private void add(CommandNode<T> parent, String[] args, int index) {
if (index >= args.length) return;
String part = args[index];
CommandNode<T> childNode = parent.getChild(part);
if (childNode == null) {
LiteralCommandNode<T> newNode = LiteralArgumentBuilder.<T>literal(part).build();
parent.addChild(newNode);
childNode = newNode;
}
add(childNode, args, index + 1);
}
}
@@ -0,0 +1,57 @@
package de.rayzs.pat.utils.subargs;
import java.util.*;
public class ArgumentBuilder {
private final ArgumentSource source;
public ArgumentBuilder(ArgumentSource source) {
this.source = source;
}
public List<String> getInputs() {
return source.INPUTS;
}
public List<String> getResult(String input) {
String firstInputArg = input.contains(" ") ? input.split(" ")[0] : input;
for (Map.Entry<String, ArgumentStack> entry : source.ARGUMENT_STACKS.entrySet()) {
if(!entry.getKey().equals(firstInputArg)) continue;
return source.ARGUMENT_STACKS.get(entry.getKey()).getResult(input);
}
return Collections.emptyList();
}
public void clearAllArguments() {
source.INPUTS.clear();
source.ARGUMENT_STACKS.clear();
}
public void buildArgumentStacks(String input) {
if(!input.contains(" ")) return;
if(!source.INPUTS.contains(input))
source.INPUTS.add(input);
boolean first = true;
ArgumentStack argumentStack = null;
for (String s : input.split(" ")) {
if(!first) {
argumentStack = argumentStack.createAndGetArgumentStack(s);
continue;
}
argumentStack = source.ARGUMENT_STACKS.get(s);
if (argumentStack == null) {
argumentStack = new ArgumentStack();
source.ARGUMENT_STACKS.put(s, argumentStack);
}
first = false;
}
}
}
@@ -0,0 +1,35 @@
package de.rayzs.pat.utils.subargs;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ArgumentSource {
private final ArgumentBuilder GENERAL = new ArgumentBuilder(this);
public final List<String> INPUTS = new ArrayList<>();
public final HashMap<String, ArgumentStack> ARGUMENT_STACKS = new HashMap<>();
public ArgumentBuilder getGeneralArgument() {
ArgumentBuilder copiedGeneralArguments = new ArgumentBuilder(this);
GENERAL.getInputs().forEach(copiedGeneralArguments::buildArgumentStacks);
return copiedGeneralArguments;
}
public List<String> getOptions(String input) {
return GENERAL.getResult(input);
}
public void clearArguments() {
GENERAL.clearAllArguments();
}
public void buildArguments(String input) {
GENERAL.buildArgumentStacks(input);
}
public List<String> getAllInputs() {
return GENERAL.getInputs();
}
}
@@ -0,0 +1,57 @@
package de.rayzs.pat.utils.subargs;
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
import de.rayzs.pat.utils.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ArgumentStack {
private final HashMap<String, ArgumentStack> argumentStacks = new HashMap<>();
private final List<String> suggestions = new ArrayList<>();
public List<String> getResult(String input) {
String current;
while(input.contains(" ")) {
current = input.split(" ")[0];
if(suggestions.contains("%online_players%"))
current = StringUtils.replaceElementsFromString(current, SubArgsModule.getPlayerNames(), "%online_players%");
if(suggestions.contains("%hidden_online_players%"))
current = StringUtils.replaceElementsFromString(current, SubArgsModule.getPlayerNames(), "%hidden_online_players%");
input = StringUtils.replaceFirst(input, current, "");
input = input.startsWith(" ") ? StringUtils.replaceFirst(input, " ", "") : input;
for (Map.Entry<String, ArgumentStack> entry : argumentStacks.entrySet()) {
if(!entry.getKey().startsWith(current)) continue;
if(entry.getKey().contains("%online_players%"))
input = StringUtils.replaceElementsFromString(input, SubArgsModule.getPlayerNames(), "%online_players%");
if(entry.getKey().contains("%hidden_online_players%"))
input = StringUtils.replaceElementsFromString(input, SubArgsModule.getPlayerNames(), "%hidden_online_players%");
return entry.getValue().getResult(input);
}
}
return suggestions;
}
public ArgumentStack createAndGetArgumentStack(String origin) {
if(!suggestions.contains(origin))
suggestions.add(origin);
if(!argumentStacks.containsKey(origin)) {
ArgumentStack argumentStack = new ArgumentStack();
argumentStacks.put(origin, argumentStack);
return argumentStack;
}
return argumentStacks.get(origin);
}
}
@@ -0,0 +1,48 @@
package de.rayzs.pat.utils.subargs;
import de.rayzs.pat.api.storage.Storage;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class Arguments {
public static Arguments ARGUMENTS = new Arguments();
public ArgumentSource CHAT_ARGUMENTS = new ArgumentSource();
public ArgumentSource TAB_ARGUMENTS = new ArgumentSource();
public List<String> getResultChat(String input) {
return CHAT_ARGUMENTS.getGeneralArgument().getResult(input);
}
public List<String> getResultTab(String input) {
return TAB_ARGUMENTS.getGeneralArgument().getResult(input);
}
public void buildArgumentStacks(String input) {
Storage.Blacklist.BlockType type = Storage.Blacklist.BlockTypeFetcher.getType(input);
input = Storage.Blacklist.BlockTypeFetcher.modify(input, type);
switch (type) {
case TAB:
TAB_ARGUMENTS.getGeneralArgument().buildArgumentStacks(input);
break;
case CHAT:
CHAT_ARGUMENTS.getGeneralArgument().buildArgumentStacks(input);
break;
case BOTH: default:
CHAT_ARGUMENTS.buildArguments(input);
TAB_ARGUMENTS.buildArguments(input);
break;
}
}
public void clearArguments() {
CHAT_ARGUMENTS.clearArguments();
TAB_ARGUMENTS.clearArguments();
}
}