Compare commits

..
33 Commits
Author SHA1 Message Date
rayzsyt 263e3e6896 Removed unnecessary boolean 2025-08-08 04:34:42 +02:00
rayzsyt 26f326668f Fixed commands-update issue when reloading 2025-08-08 04:33:17 +02:00
rayzsyt 74e26a05f3 Update version name 2025-08-08 04:32:58 +02:00
rayzsyt 36145b1ee7 Update version name 2025-08-07 18:26:43 +02:00
rayzsyt 5f457c6e4a Fixed wrong display of blocked command in chat 2025-08-07 18:26:00 +02:00
rayzsyt 65dc540577 Improved performance of getAllCommands method 2025-08-07 01:59:32 +02:00
rayzsyt c338e29ec4 Changed method call 2025-08-07 01:59:08 +02:00
rayzsyt c253f6684b Small refactoring 2025-08-07 01:58:56 +02:00
rayzsyt aa740ffabf Fixed potential Folia incompatibility 2025-08-07 01:58:38 +02:00
rayzsyt e9ffe83a93 Integrated new methods from Loader 2025-08-07 01:58:19 +02:00
rayzsyt c83e83bb06 Integrated new method from Loader 2025-08-07 01:58:04 +02:00
rayzsyt b3c2e014c1 Add new methods 2025-08-07 01:57:54 +02:00
rayzsyt 6631da42e1 Fixed BLACKLIST mode issues 2025-08-07 01:57:44 +02:00
rayzsyt ac5233582f Change version name & integrated new default methods 2025-08-07 01:57:18 +02:00
rayzsyt 32a1f4351a Change version name 2025-08-07 01:57:01 +02:00
rayzsyt 2ff88eeb03 Fixed 1.8.8 incompatibility 2025-08-04 21:44:52 +02:00
rayzsyt 62b505450a Update version name 2025-08-04 21:44:11 +02:00
rayzsyt f7fd9dd42a Update version name 2025-08-04 18:31:55 +02:00
rayzsyt acd8e9291a Fix unnecessary offline-player cache spam 2025-08-02 16:20:17 +02:00
rayzsyt 50c80fc708 Change version name 2025-08-02 16:19:47 +02:00
rayzsyt bb02672085 Apply %args[.-.]% for in-game messages as well 2025-07-31 03:17:43 +02:00
rayzsyt f2e7efeaa6 Fix 0 commands 2025-07-31 03:04:39 +02:00
rayzsyt aa0863e726 Fix missing notification on /pl or /ver 2025-07-30 22:16:32 +02:00
rayzsyt 71cec6933f Add setDoesNotify function 2025-07-30 22:16:03 +02:00
rayzsyt c2d407cd62 Improved Update-Notifier 2025-07-30 22:15:54 +02:00
rayzsyt 61adaa19db Improved notification dedicator 2025-07-30 20:53:55 +02:00
rayzsyt 4c1cc0683d Add exceptional version names 2025-07-30 20:53:35 +02:00
rayzsyt ce3b42af38 Improved VersionComparer 2025-07-30 19:46:21 +02:00
rayzsyt 61c204ade0 Improved replaceArgsVariables Function 2025-07-30 17:18:34 +02:00
rayzsyt e13fae6e67 Removed Skript 2025-07-30 05:23:36 +02:00
rayzsyt 31e4c3caa4 Added variable examples for %args[.-.]% 2025-07-30 05:21:52 +02:00
rayzsyt bccb77667d Added variable %args[from-to]% 2025-07-30 05:18:25 +02:00
rayzsyt 4ab0791740 Updated version name 2025-07-30 05:18:04 +02:00
29 changed files with 560 additions and 379 deletions

No files matched your search

+1 -16
View File
@@ -6,7 +6,7 @@
<groupId>de.rayzs.pat</groupId>
<artifactId>ProAntiTab</artifactId>
<version>2.0.4</version>
<version>2.0.9</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
@@ -72,25 +72,10 @@
<url>https://repo.william278.net/papiproxybridge</url>
</repository>
<repository>
<id>skript-releases</id>
<name>Skript Repository</name>
<url>https://repo.skriptlang.org/releases</url>
</repository>
</repositories>
<dependencies>
<!--
<dependency>
<groupId>org.skriptlang</groupId>
<artifactId>Skript</artifactId>
<version>2.10.1</version>
<scope>provided</scope>
</dependency>
!-->
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
@@ -10,8 +10,8 @@ public class PATEventHandler {
private static List<PATEvent> EVENTS = new ArrayList<>();
public static ExecuteCommandEvent callExecuteCommandEvents(Object senderObj, String command, boolean blocked) {
ExecuteCommandEvent event = EmptyEvent.createEmptyExecuteCommandEvent(senderObj, command, blocked);
public static ExecuteCommandEvent callExecuteCommandEvents(Object senderObj, String command, boolean blocked, boolean notify) {
ExecuteCommandEvent event = EmptyEvent.createEmptyExecuteCommandEvent(senderObj, command, blocked, notify);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof ExecuteCommandEvent) {
@@ -169,8 +169,8 @@ public class PATEventHandler {
};
}
public static ExecuteCommandEvent createEmptyExecuteCommandEvent(Object senderObj, String command, boolean blocked) {
return new ExecuteCommandEvent(senderObj, command, blocked) {
public static ExecuteCommandEvent createEmptyExecuteCommandEvent(Object senderObj, String command, boolean blocked, boolean notify) {
return new ExecuteCommandEvent(senderObj, command, blocked, notify) {
@Override
public void handle(ExecuteCommandEvent event) {
@@ -5,18 +5,24 @@ import de.rayzs.pat.api.event.PATEvent;
public abstract class ExecuteCommandEvent extends PATEvent<ExecuteCommandEvent> {
private final String command;
private boolean blocked;
private boolean blocked, notify;
public ExecuteCommandEvent() {
super(null);
this.blocked = false;
this.notify = false;
this.command = null;
}
public ExecuteCommandEvent(Object senderObj, String command, boolean blocked) {
public ExecuteCommandEvent(Object senderObj, String command, boolean blocked, boolean notify) {
super(senderObj);
this.blocked = blocked;
this.command = command;
this.notify = notify;
}
public void setDoesNotify(boolean notify) {
this.notify = notify;
}
public String getCommand() {
@@ -27,6 +33,10 @@ public abstract class ExecuteCommandEvent extends PATEvent<ExecuteCommandEvent>
return blocked;
}
public boolean doesNotify() {
return notify;
}
public void setBlocked(boolean blocked) {
this.blocked = blocked;
}
@@ -204,6 +204,8 @@ public class Storage {
} else {
Storage.Blacklist.Experimental.forceCacheReset();
if (isVelocity) {
List<UUID> playerIds = Storage.getLoader().getPlayerIds();
@@ -384,6 +386,19 @@ public class Storage {
public static class Blacklist {
public static class Experimental {
public static void forceCacheReset() {
for (Object o : CACHED_SERVER_BLACKLIST.getCache().asMap().keySet()) {
String s = (String) o;
clearServerBlacklists(s);
loadCachedServerBlacklists(s);
}
}
}
public enum BlockType {
CHAT("[CMD]"),
TAB("[TAB]"),
@@ -428,14 +443,9 @@ public class Storage {
BLACKLIST.getConfig().getKeys("global.servers", true).forEach(key -> {
GeneralBlacklist blacklist = BlacklistCreator.createGeneralBlacklist(key);
blacklist.load();
SERVER_BLACKLISTS.put(key, blacklist);
});
loadAllCachedServerBlacklists();
}
private static void loadAllCachedServerBlacklists() {
getServers().forEach(Blacklist::loadCachedServerBlacklists);
}
@@ -443,9 +453,7 @@ public class Storage {
List<GeneralBlacklist> blacklists = SERVER_BLACKLISTS.entrySet().stream()
.filter(entry ->
isServer(entry.getKey(), server)
).map(entry ->
entry.getValue()
).toList();
).map(Map.Entry::getValue).toList();
CACHED_SERVER_BLACKLIST.put(server, blacklists);
}
@@ -550,7 +558,12 @@ public class Storage {
boolean listed = isListed(command, type, server),
turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
return !(listed && turn);
if (turn) {
return !listed;
} else {
return listed;
}
}
private static boolean isListed(String unmodifiedCommand, BlockType type, String server) {
@@ -35,12 +35,17 @@ import java.util.*;
public class BukkitLoader extends JavaPlugin implements PluginLoader {
private static List<String> commands = new ArrayList<>(), allowedCommands = new ArrayList<>();
private static Plugin plugin;
private static java.util.logging.Logger logger;
private static boolean loaded = false, checkUpdate = false, suggestions = false;
private static boolean loaded = false, suggestions = false;
private static Map<String, Command> commandsMap = null;
private PATSchedulerTask updaterTask;
private final List<String> offlinePlayerNames = new ArrayList<>();
private long lastCommandsLoad = -1;
@Override
public void onLoad() {
Configurator.createResourcedFile("files\\bukkit-config.yml", "config.yml", false);
@@ -54,6 +59,10 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
plugin = this;
logger = getLogger();
for (OfflinePlayer offlinePlayerName : Bukkit.getOfflinePlayers()) {
offlinePlayerNames.add(offlinePlayerName.getName());
}
loadCommandMap();
CommandProcess.initialize();
@@ -61,7 +70,7 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
ConfigUpdater.initialize();
Storage.initialize(this, getDescription().getVersion());
VersionComparer.setCurrentVersion(Storage.CURRENT_VERSION);
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
Storage.loadAll(true);
@@ -104,12 +113,15 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
if (getServer().getPluginManager().getPlugin("ViaVersion") != null)
ViaVersionAdapter.initialize();
if (Storage.USE_SIMPLECLOUD)
if (Storage.USE_SIMPLECLOUD) {
Logger.warning("Detected SimpleCloud. Therefore, MiniMessages are disabled!");
}
ConfigUpdater.broadcastMissingParts();
ActionHandler.initialize();
SubArgsModule.initialize();
PATScheduler.createScheduler(this::loadAllCommands);
}
@Override
@@ -128,6 +140,21 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
}
}
@Override
public void handleReload() {
loadAllCommands();
}
@Override
public boolean doesCommandExist(String command) {
if (commandsMap == null)
return false;
loadAllCommands();
return getAllCommands().contains(command);
}
@Override
public Object getConsoleSender() {
return Bukkit.getConsoleSender();
@@ -158,7 +185,7 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
@Override
public boolean doesPlayerExist(String playerName) {
return getOfflinePlayerNames().contains(playerName);
return ArrayUtils.containsIgnoreCase(getPlayerNames(), playerName);
}
@Override
@@ -188,15 +215,14 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
@Override
public List<String> getOfflinePlayerNames() {
return new ArrayList<>(List.of(Bukkit.getOfflinePlayers())).stream().map(OfflinePlayer::getName).toList();
return offlinePlayerNames;
}
@Override
public List<String> getPlayerNames() {
List<String> playerNames = new ArrayList<>();
List<String> playerNames = new ArrayList<>(offlinePlayerNames);
playerNames.addAll(getOnlinePlayerNames());
playerNames.addAll(getOfflinePlayerNames());
return playerNames;
}
@@ -219,41 +245,13 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
}
public void startUpdaterTask() {
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED)
return;
updaterTask = PATScheduler.createAsyncScheduler(() -> {
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
.setProperties("ProAntiTab", "4654").connect().getResponse();
if (result == null)
result = "/";
if (!result.equals("/")) {
Storage.NEWER_VERSION = result;
VersionComparer.setNewestVersion(Storage.NEWER_VERSION);
if (VersionComparer.isDeveloperVersion()) {
updaterTask.cancelTask();
Logger.info("§8[§fPAT | Bukkit§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
} else if (!checkUpdate && (VersionComparer.isNewest() || VersionComparer.isUnreleased())) {
updaterTask.cancelTask();
checkUpdate = true;
if (VersionComparer.isUnreleased()) {
Logger.info("§8[§fPAT | Bukkit§8] §7Please be aware that you are currently using an §eunreleased §7version of ProAntiTab.");
return;
}
Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines().forEach(Logger::warning);
} else if (VersionComparer.isOutdated()) {
updaterTask.cancelTask();
Storage.OUTDATED = true;
Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines().forEach(Logger::warning);
}
} else {
Logger.warning("Failed to connect to plugin page! Version comparison cannot be made. (No internet?)");
}
if (VersionComparer.get().computeComparison())
updaterTask.cancelTask();
}, 20L, 20L * Storage.ConfigSections.Settings.UPDATE.PERIOD);
}
@@ -332,12 +330,12 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
PATEventHandler.callReceiveSyncEvents(packetBundle);
}
public static boolean doesCommandExist(String command, boolean replace) {
if (commandsMap == null)
return false;
public static List<String> getAllCommands() {
return new ArrayList<>(commands);
}
if (replace) command = StringUtils.replaceFirst(command, "/", "");
return getAllCommands().contains(command);
public static List<String> getAllowedCommands() {
return new ArrayList<>(allowedCommands);
}
private void loadCommandMap() {
@@ -348,45 +346,65 @@ public class BukkitLoader extends JavaPlugin implements PluginLoader {
SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getPluginManager());
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
commandsMap = (Map<String, Command>)knownCommandsField.get(simpleCommandMap);
commandsMap = (Map<String, Command>) knownCommandsField.get(simpleCommandMap);
}
} catch (Throwable ignored) { }
if(commandsMap == null)
if (commandsMap == null) {
Logger.warning("Failed to get server commands!");
}
}
public static List<String> getNotBlockedCommands() {
List<String> commands = new ArrayList<>();
Bukkit.getHelpMap().getHelpTopics().stream()
.filter(topic -> !topic.getName().contains(":") && topic.getName().startsWith("/") && !Storage.Blacklist.getBlacklist().isListed(topic.getName().replaceFirst("/", "")))
.forEach(topic -> commands.add(topic.getName().replaceFirst("/", "")));
return commands;
}
private void loadAllCommands() {
public static List<String> getAllCommands() {
if (commandsMap == null) return getNotBlockedCommands();
if (lastCommandsLoad != -1 && System.currentTimeMillis() - lastCommandsLoad < 1000)
return;
List<String> result = new LinkedList<>();
for (String command : commandsMap.keySet()) if(!result.contains(command)) result.add(command);
List<String> result = new ArrayList<>();
if(Reflection.getMinor() == 20 && Reflection.getRelease() >= 5 || Reflection.getMinor() >= 21)
for (String s : commandsMap.keySet()) {
if (commandsMap.containsKey(s)) {
if (!commandsMap.get(s).getAliases().isEmpty()) {
for (String alias : commandsMap.get(s).getAliases()) {
if (!result.contains(alias)) result.add(alias);
}
if (commandsMap == null) {
result.addAll(
Bukkit.getHelpMap().getHelpTopics().stream()
.map(topic -> {
String name = topic.getName();
} else if (Bukkit.getServer().getCommandAliases().get(s) != null)
for (String alias : Bukkit.getServer().getCommandAliases().get(s))
if (!result.contains(alias)) result.add(alias);
}
if (name.startsWith("/"))
name = name.substring(1);
return name;
}).toList()
);
return;
}
commandsMap.entrySet().forEach(entry -> {
String key = entry.getKey();
Command command = entry.getValue();
result.add(key);
if (!command.getAliases().isEmpty()) {
result.addAll(command.getAliases());
}
});
boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
List<String> allowedCommands = new ArrayList<>(result).stream().filter(command -> {
if (turn) {
return Storage.Blacklist.getBlacklist().isListed(command);
} else {
return !Storage.Blacklist.getBlacklist().isListed(command);
}
return result;
}
}).toList();
lastCommandsLoad = System.currentTimeMillis();
BukkitLoader.commands = result;
BukkitLoader.allowedCommands = allowedCommands;
}
public static boolean useSuggestions() {
return suggestions;
@@ -33,7 +33,6 @@ public class BungeeLoader extends Plugin implements PluginLoader {
private static Plugin plugin;
private static java.util.logging.Logger logger;
private static boolean checkUpdate = false;
private static final HashMap<String, CommandsCache> commandsCacheMap = new HashMap<>();
@Override
@@ -56,7 +55,7 @@ public class BungeeLoader extends Plugin implements PluginLoader {
Storage.USE_SIMPLECLOUD = Reflection.doesClassExist("eu.thesimplecloud.plugin.startup.CloudPlugin");
Storage.initialize(this, getDescription().getVersion());
VersionComparer.setCurrentVersion(Storage.CURRENT_VERSION);
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
Storage.loadAll(true);
@@ -113,6 +112,14 @@ public class BungeeLoader extends Plugin implements PluginLoader {
}
}
@Override
public void handleReload() {}
@Override
public boolean doesCommandExist(String command) {
return false;
}
@Override
public Object getConsoleSender() {
return ProxyServer.getInstance().getConsole();
@@ -226,43 +233,14 @@ public class BungeeLoader extends Plugin implements PluginLoader {
}
public void startUpdaterTask() {
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED)
return;
updaterTask = getProxy().getScheduler().schedule(this, () -> {
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
.setProperties("ProAntiTab", "4654").connect().getResponse();
if (result == null)
result = "/";
if (VersionComparer.get().computeComparison())
getProxy().getScheduler().cancel(updaterTask);
if (!result.equals("/")) {
Storage.NEWER_VERSION = result;
VersionComparer.setNewestVersion(Storage.NEWER_VERSION);
if(VersionComparer.isDeveloperVersion()) {
getProxy().getScheduler().cancel(updaterTask);
Logger.info("§8[§fPAT | Proxy§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
} else if(!checkUpdate && (VersionComparer.isNewest() || VersionComparer.isUnreleased())) {
getProxy().getScheduler().cancel(updaterTask);
checkUpdate = true;
if(VersionComparer.isUnreleased()) {
Logger.info("§8[§fPAT | Proxy§8] §7Please be aware that you are currently using an §eunreleased §7version of ProAntiTab.");
return;
}
checkUpdate = true;
Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines().forEach(Logger::warning);
} else if(VersionComparer.isOutdated()) {
Storage.OUTDATED = true;
Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines().forEach(Logger::warning);
}
} else {
Logger.warning("Failed to connect to plugin page! Version comparison cannot be made. (No internet?)");
}
}, 20L, Storage.ConfigSections.Settings.UPDATE.PERIOD, TimeUnit.MILLISECONDS);
}
@@ -8,6 +8,9 @@ import java.util.UUID;
public interface PluginLoader {
void handleReload();
boolean doesCommandExist(String command);
HashMap<String, CommandsCache> getCommandsCacheMap();
void updateCommandCache();
@@ -38,7 +38,7 @@ import java.util.*;
@Plugin(name = "ProAntiTab",
id = "proantitab",
version = "2.0.4",
version = "2.0.9",
authors = "Rayzs_YT",
description = "Hide more than just your plugins. Hide almost everything!",
url = "https://www.rayzs.de/products/proantitab/page",
@@ -58,7 +58,6 @@ public class VelocityLoader implements PluginLoader {
private ScheduledTask updaterTask;
private static final HashMap<String, CommandsCache> commandsCacheMap = new HashMap<>();
private static boolean checkUpdate = false;
@Inject
public VelocityLoader(ProxyServer server, org.slf4j.Logger logger, VelocityMetrics.Factory metricsFactory) {
@@ -85,7 +84,7 @@ public class VelocityLoader implements PluginLoader {
Storage.USE_SIMPLECLOUD = Reflection.doesClassExist("eu.thesimplecloud.plugin.startup.CloudPlugin");
Storage.initialize(this, pluginContainer.getDescription().getVersion().get());
VersionComparer.setCurrentVersion(Storage.CURRENT_VERSION);
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
Storage.loadAll(true);
MessageTranslator.initialize();
@@ -145,6 +144,14 @@ public class VelocityLoader implements PluginLoader {
}).delay(1, TimeUnit.SECONDS).schedule();
}
@Override
public void handleReload() {}
@Override
public boolean doesCommandExist(String command) {
return false;
}
@Override
public Object getConsoleSender() {
return server.getConsoleCommandSource();
@@ -271,59 +278,13 @@ public class VelocityLoader implements PluginLoader {
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
updaterTask = server.getScheduler().buildTask(this, () -> {
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
.setProperties("ProAntiTab", "4654").connect().getResponse();
if (result == null)
result = "/";
if (VersionComparer.get().computeComparison())
updaterTask.cancel();
if (!result.equals("/")) {
Storage.NEWER_VERSION = result;
VersionComparer.setNewestVersion(Storage.NEWER_VERSION);
if (VersionComparer.isDeveloperVersion()) {
updaterTask.cancel();
MessageTranslator.send(server.getConsoleCommandSource(), "<dark_gray>[</dark_gray><white>PAT | Proxy</white><dark_gray>]</dark_gray> <gray>Please be aware that you are currently using a</gray> <aqua>developer</aqua> <gray>version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.</gray>");
} else if (!checkUpdate && (VersionComparer.isNewest() || VersionComparer.isUnreleased())) {
updaterTask.cancel();
checkUpdate = true;
if (VersionComparer.isUnreleased()) {
MessageTranslator.send(server.getConsoleCommandSource(), "<dark_gray>[</dark_gray><white>PAT | Proxy</white><dark_gray>]</dark_gray> <gray>Please be aware that you are currently using an</gray> <yellow>unreleased</yellow> <gray>version of ProAntiTab.</gray>");
return;
}
checkUpdate = true;
MessageTranslator.send(server.getConsoleCommandSource(), Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines());
} else if (VersionComparer.isOutdated()) {
Storage.OUTDATED = true;
MessageTranslator.send(server.getConsoleCommandSource(), Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines());
}
} else {
Logger.warning("Failed to connect to plugin page! Version comparison cannot be made. (No internet?)");
}
}).delay(1, TimeUnit.SECONDS).repeat(Storage.ConfigSections.Settings.UPDATE.PERIOD, TimeUnit.SECONDS).schedule();
}
public static String getServerNameByPlayerUUID(UUID uuid) {
Optional<Player> optPlayer = server.getPlayer(uuid);
if(!optPlayer.isPresent()) return null;
Player player = optPlayer.get();
Optional<ServerConnection> optServer = player.getCurrentServer();
if(!optServer.isPresent()) return null;
ServerConnection server = optServer.get();
if(server.getServerInfo() == null) return null;
return server.getServerInfo().getName();
}
public static ProxyServer getServer() {
return server;
}
@@ -13,7 +13,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import de.rayzs.pat.api.event.PATEventHandler;
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.BukkitLoader;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.message.MessageTranslator;
@@ -25,14 +24,20 @@ public class BukkitBlockCommandListener implements Listener {
public void onUnknownCommandRecognition(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
String rawCommand = StringUtils.getFirstArg(event.getMessage()),
command = rawCommand.substring(1);
if (!Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED || event.isCancelled()) return;
if (PermissionUtil.hasBypassPermission(player)) return;
//if (BukkitLoader.doesCommandExist(command, false)) return;
if (Bukkit.getHelpMap().getHelpTopic(rawCommand) != null) return;
if (PermissionUtil.hasBypassPermission(player))
return;
if (Storage.getLoader().doesCommandExist(command))
return;
if (Bukkit.getHelpMap().getHelpTopic(rawCommand) != null)
return;
event.setCancelled(true);
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE, "%command%", command, "%world%", world.getName());
@@ -65,9 +70,7 @@ public class BukkitBlockCommandListener implements Listener {
command = command.substring(1);
command = StringUtils.getFirstArg(command);
final String displayName = command;
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
final String displayName = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
command = command.toLowerCase();
List<String> notificationMessage = MessageTranslator.replaceMessageList(
@@ -86,12 +89,17 @@ public class BukkitBlockCommandListener implements Listener {
return;
if (!Storage.Blacklist.canPlayerAccessChat(player, command)) {
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), true);
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
player,
event.getMessage(),
true,
!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED
);
if (executeCommandEvent.isBlocked()) {
event.setCancelled(true);
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
if (!executeCommandEvent.doesNotify())
return;
if (Storage.SEND_CONSOLE_NOTIFICATION)
@@ -108,7 +116,7 @@ public class BukkitBlockCommandListener implements Listener {
return;
}
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), false);
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), false, false);
if (executeCommandEvent.isBlocked())
event.setCancelled(true);
}
@@ -5,10 +5,12 @@ import de.rayzs.pat.api.event.PATEventHandler;
import de.rayzs.pat.api.event.events.ServerPlayersChangeEvent;
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
import de.rayzs.pat.api.communication.BackendUpdater;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.message.MessageTranslator;
import de.rayzs.pat.utils.permission.PermissionUtil;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.BukkitLoader;
import de.rayzs.pat.utils.scheduler.PATScheduler;
import org.bukkit.event.player.*;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
@@ -30,10 +32,21 @@ public class BukkitPlayerConnectionListener implements Listener {
if(CustomServerBrand.isEnabled())
CustomServerBrand.sendBrandToPlayer(player);
if(!BukkitPacketAnalyzer.inject(player)) player.kickPlayer("Failed to inject player!");
if(!BukkitPacketAnalyzer.inject(player)) {
PATScheduler.createScheduler(() -> {
if (player.isOnline()) {
if (!BukkitPacketAnalyzer.inject(player)) {
Logger.warning("Failed to inject into player! (" + player.getName() + ")" );
player.kickPlayer("Failed to inject player!");
}
}
}, 10);
}
if(Storage.OUTDATED && PermissionUtil.hasPermission(player, "joinupdate")) {
Bukkit.getScheduler().runTaskLater(BukkitLoader.getPlugin(), () -> {
PATScheduler.createScheduler(() -> {
if (player.isOnline()) {
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines());
}
@@ -36,9 +36,8 @@ public class BungeeBlockCommandListener implements Listener {
command = command.startsWith("/") ? command.substring(1) : command;
command = StringUtils.getFirstArg(command);
final String displayCommand = command;
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
command = command.toLowerCase();
List<String> notificationMessage = MessageTranslator.replaceMessageList(
@@ -51,12 +50,17 @@ public class BungeeBlockCommandListener implements Listener {
return;
if (!Storage.Blacklist.canPlayerAccessChat(player, command, serverName)) {
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), true);
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
player,
event.getMessage(),
true,
!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED
);
if (executeCommandEvent.isBlocked()) {
event.setCancelled(true);
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
if (!executeCommandEvent.doesNotify())
return;
if (Storage.SEND_CONSOLE_NOTIFICATION)
@@ -76,7 +80,7 @@ public class BungeeBlockCommandListener implements Listener {
return;
}
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), false);
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), false, false);
if (executeCommandEvent.isBlocked())
event.setCancelled(true);
}
@@ -39,9 +39,8 @@ public class VelocityBlockCommandListener {
if (bypassPermission)
return event;
final String displayCommand = command;
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
command = command.toLowerCase();
@@ -56,12 +55,16 @@ public class VelocityBlockCommandListener {
return event;
if (!Storage.Blacklist.canPlayerAccessChat(player, command, serverName)) {
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getCommand(), true);
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
player,
event.getCommand(),
true,
!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
if (executeCommandEvent.isBlocked()) {
event.setResult(CommandExecuteEvent.CommandResult.denied());
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
if (!executeCommandEvent.doesNotify())
return event;
if (Storage.SEND_CONSOLE_NOTIFICATION)
@@ -79,7 +82,7 @@ public class VelocityBlockCommandListener {
return event;
}
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getCommand(), false);
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getCommand(), false, false);
if (executeCommandEvent.isBlocked())
event.setResult(CommandExecuteEvent.CommandResult.denied());
@@ -1,5 +1,6 @@
package de.rayzs.pat.plugin.metrics.impl;
import de.rayzs.pat.utils.scheduler.PATScheduler;
import org.bukkit.configuration.file.YamlConfiguration;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.HttpsURLConnection;
@@ -171,7 +172,7 @@ public class BukkitMetrics {
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, this::submitData);
PATScheduler.createScheduler(this::submitData);
};
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution of requests on the
@@ -23,7 +23,10 @@ public class ExecuteCommand extends ExecuteCommandEvent {
? command.substring(1)
: command;
final String displayCommand = StringUtils.getFirstArg(command);
final String displayCommand = StringUtils.replaceTriggers(
command, "",
"\\", "<", ">", "&"
);
CommandSender sender = CommandSenderHandler.from(event.getSenderObj());
@@ -37,11 +40,12 @@ public class ExecuteCommand extends ExecuteCommandEvent {
MessageTranslator.send(
event.getSenderObj(),
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE,
"%command%", displayCommand
"%command%", StringUtils.getFirstArg(displayCommand)
);
event.setBlocked(true);
event.setCancelled(true);
event.setDoesNotify(true);
return;
}
@@ -50,11 +54,12 @@ public class ExecuteCommand extends ExecuteCommandEvent {
MessageTranslator.send(
event.getSenderObj(),
Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE,
"%command%", displayCommand
"%command%", StringUtils.getFirstArg(displayCommand)
);
event.setBlocked(true);
event.setCancelled(true);
event.setDoesNotify(true);
return;
}
@@ -64,7 +69,7 @@ public class ExecuteCommand extends ExecuteCommandEvent {
MessageTranslator.send(event.getSenderObj(),
ResponseHandler.getResponse(uuid, event.getCommand()),
"%command%", command);
"%command%", displayCommand);
return;
}
@@ -77,7 +82,7 @@ public class ExecuteCommand extends ExecuteCommandEvent {
MessageTranslator.send(
event.getSenderObj(),
ResponseHandler.getResponse(uuid, event.getCommand(), Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines()),
"%command%", displayCommand
"%command%", StringUtils.getFirstArg(displayCommand)
);
}
@@ -91,6 +96,7 @@ public class ExecuteCommand extends ExecuteCommandEvent {
final String unmodifiable = command;
final String firstArgUnmodifiable = StringUtils.getFirstArg(unmodifiable);
if (commands.stream().noneMatch(c -> StringUtils.getFirstArg(c).equalsIgnoreCase(firstArgUnmodifiable))) {
return true;
}
@@ -107,8 +113,9 @@ public class ExecuteCommand extends ExecuteCommandEvent {
StringUtils.getFirstArg(s).equalsIgnoreCase(firstArgUnmodifiable) && s.contains("%")
).toList();
if (!placeholderCommands.isEmpty())
if (!placeholderCommands.isEmpty()) {
command = SubArgsModule.replacePlaceholders(command);
}
String cpyCommand;
for (String c : commands) {
@@ -107,7 +107,7 @@ public class AddCommand extends ProCommand {
if (Reflection.isProxyServer())
return null;
return BukkitLoader.getNotBlockedCommands();
return BukkitLoader.getAllowedCommands();
}
String fullString = String.join(" ", args);
@@ -2,6 +2,7 @@ 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.api.storage.blacklist.impl.GeneralBlacklist;
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
import de.rayzs.pat.utils.group.GroupManager;
import de.rayzs.pat.api.command.ProCommand;
@@ -26,6 +27,7 @@ public class ReloadCommand extends ProCommand {
sender.sendMessage(Storage.ConfigSections.Messages.RELOAD.LOADING);
Storage.loadAll(Reflection.isProxyServer() || !backend);
CustomServerBrand.initialize();
GroupManager.clearAllGroups();
GroupManager.initialize();
@@ -42,6 +44,7 @@ public class ReloadCommand extends ProCommand {
}
ConfigUpdater.initialize();
Storage.getLoader().handleReload();
sender.sendMessage(Storage.ConfigSections.Messages.RELOAD.DONE);
return true;
@@ -37,16 +37,21 @@ public class ConnectionBuilder {
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
if(parameters != null && parameters.length > 0) {
Object firstParam = null, secondParam = null;
for (Object parameter : parameters) {
if(firstParam == null) firstParam = parameter;
else if(secondParam == null) secondParam = parameter;
else {
connection.setRequestProperty((String) firstParam, (String) secondParam);
firstParam = null;
secondParam = null;
if (firstParam == null) {
firstParam = parameter;
continue;
}
secondParam = parameter;
connection.setRequestProperty((String) firstParam, (String) secondParam);
firstParam = null;
}
}
@@ -1,121 +1,179 @@
package de.rayzs.pat.utils;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.logger.Logger;
import java.util.Arrays;
import java.util.List;
public class VersionComparer {
private static Version CURRENT_VERSION, NEWEST_VERSION;
public enum VersionState { NEWER, UPDATED, OUTDATED }
public static void setCurrentVersion(String versionName) {
if(CURRENT_VERSION != null && CURRENT_VERSION.getVersionName().equals(versionName)) return;
CURRENT_VERSION = new Version(versionName);
private static final VersionComparer instance = new VersionComparer();
public static VersionComparer get() {
return instance;
}
public static void setNewestVersion(String versionName) {
if(NEWEST_VERSION != null && NEWEST_VERSION.getVersionName().equals(versionName))
private VersionComparer() {}
private final List<String> ignoreVersions = Arrays.asList("1.9.1", "1.9.2");
private final String versionUrl = "https://www.rayzs.de/proantitab/api/version.php";
private final int versionLength = 3;
private Version currentVersion, newestVersion;
private VersionState versionState = VersionState.UPDATED;
private boolean shouldAnnounce = true;
public boolean computeComparison() {
String result = new ConnectionBuilder().setUrl(versionUrl)
.setProperties("ProAntiTab", "4454")
.connect()
.getResponse();
if (result == null)
result = "/";
if (result.equals("/")) {
Logger.warning("Failed to connect to plugin page! Version comparison cannot be made. (No internet?)");
return false;
}
Storage.NEWER_VERSION = result;
VersionComparer.get().setNewestVersion(Storage.NEWER_VERSION);
if (VersionComparer.get().isNewer()) {
if (shouldAnnounce) {
shouldAnnounce = false;
Logger.info("§8[§fPAT | Bukkit§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
}
return true;
}
if (VersionComparer.get().isUpdated()) {
if (shouldAnnounce) {
shouldAnnounce = false;
Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines().forEach(Logger::warning);
}
return false;
}
if (VersionComparer.get().isOutdated()) {
if (shouldAnnounce) {
shouldAnnounce = false;
Storage.OUTDATED = true;
Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines().forEach(Logger::warning);
}
return true;
}
return false;
}
public void setCurrentVersion(String version) {
if (version == null)
return;
NEWEST_VERSION = new Version(versionName);
currentVersion = new Version(version);
}
public static Version getCurrentVersion() {
return CURRENT_VERSION;
public void setNewestVersion(String version) {
if (version == null)
return;
if (ignoreVersions.contains(version))
return;
newestVersion = new Version(version);
compute();
}
public static Version getNewestVersion() {
return NEWEST_VERSION;
public VersionState getVersionState() {
return versionState;
}
public static boolean isNewest() {
if(CURRENT_VERSION == null || NEWEST_VERSION == null) return true;
return CURRENT_VERSION.isSame(NEWEST_VERSION);
public boolean isUpdated() {
return versionState == VersionState.UPDATED;
}
public static boolean isUnreleased() {
if(CURRENT_VERSION == null || NEWEST_VERSION == null) return true;
return CURRENT_VERSION.isNewer(NEWEST_VERSION);
public boolean isOutdated() {
return versionState == VersionState.OUTDATED;
}
public static boolean isOutdated() {
if(CURRENT_VERSION == null || NEWEST_VERSION == null) return false;
return CURRENT_VERSION.isOlder(NEWEST_VERSION);
public boolean isNewer() {
return versionState == VersionState.NEWER;
}
public static boolean isDeveloperVersion() {
return CURRENT_VERSION.getState() == State.DEV;
}
private void compute() {
if (currentVersion == null || newestVersion == null)
return;
public static class Version {
private final String versionName;
private int release = -1, major = -1, patch = -1;
private State state = State.RELEASE;
int[] crntNum = currentVersion.getVersionNums();
int[] newNum = newestVersion.getVersionNums();
public Version(String version) {
this.versionName = version;
for (int i = 0; i < versionLength; i++) {
try {
String[] versionSplit = version.split("\\.");
release = Integer.parseInt(versionSplit[0]);
major = Integer.parseInt(versionSplit[1]);
String patchAsString = versionSplit[2];
patchAsString = patchAsString.contains("-") ? patchAsString.split("-")[0] : patchAsString;
patch = Integer.parseInt(patchAsString);
if(!version.contains("-")) return;
String stateName = version.split("-")[1].toUpperCase();
state = State.valueOf(stateName);
} catch (Throwable throwable) {
Logger.warning("Failed to read version name! [" + version + "]");
throwable.printStackTrace();
if (crntNum[i] > newNum[i]) {
versionState = VersionState.NEWER;
return;
}
if (crntNum[i] < newNum[i]) {
versionState = VersionState.OUTDATED;
return;
}
}
}
private class Version {
private final int[] versionNums = new int[versionLength];
private final String versionString;
public Version(String versionString) {
this.versionString = versionString;
setVersionNums();
}
public String getVersionName() {
return versionName;
return versionString;
}
public boolean isSame(Version version) {
return version.getVersionName().equals(versionName);
public int[] getVersionNums() {
return versionNums;
}
public boolean isNewer(Version comparedVersion) {
return !isSame(comparedVersion) && !isOlder(comparedVersion);
private void setVersionNums() {
if (!versionString.contains("."))
return;
String[] details = versionString.split("\\.");
for (int i = 0; i < details.length; i++) {
if (i >= versionLength)
break;
String detailString = details[i];
if (!NumberUtils.isDigit(detailString))
continue;
int detail = Integer.parseInt(detailString);
versionNums[i] = detail;
}
}
public boolean isOlder(Version comparedVersion) {
if(release > comparedVersion.getRelease()) return false;
if(major > comparedVersion.getMajor()) return false;
return patch < comparedVersion.getPatch();
}
public int getRelease() {
return release;
}
public int getMajor() {
return major;
}
public int getPatch() {
return patch;
}
public State getState() {
return state;
}
public boolean isInvalid() {
return release == -1 || major == -1 || patch == -1;
}
}
public enum State {
RELEASE, DEV, ALPHA, BETA
}
}
@@ -7,6 +7,7 @@ import de.rayzs.pat.utils.*;
import de.rayzs.pat.utils.response.action.ActionHandler;
import java.util.*;
import java.util.stream.Collectors;
public class ResponseHandler {
@@ -23,12 +24,61 @@ public class ResponseHandler {
});
}
public static String replaceArgsVariables(String input, String command) {
if (!input.contains(" "))
return input;
String[] commandSplit = command.contains(" ") ? command.split(" ") : new String[]{command};
String[] split = input.split(" ");
for (int i = 0; i < split.length; i++) {
String part = split[i];
if (! (part.startsWith("%args[") && part.endsWith("]%")))
continue;
part = part.substring(part.indexOf('[') + 1, part.lastIndexOf(']'));
int length = commandSplit.length, fromIndex, toIndex;
if (part.contains("-")) {
String[] indexSplit = part.split("-");
fromIndex = Integer.parseInt(indexSplit[0]) - 1;
toIndex = Integer.parseInt(indexSplit[1]);
} else {
fromIndex = Integer.parseInt(part);
toIndex = fromIndex;
}
if (fromIndex < 0 || toIndex > length) {
Logger.warning("Custom response contains an error! (" + input + ")");
Logger.warning("Out of bounds! (Input: " + input + ", Possible: " + (length > 1 ? "1-" : "") + length + ")");
continue;
}
String replacement;
if (fromIndex == toIndex) {
replacement = commandSplit[fromIndex - 1];
} else {
replacement = String.join(" ", Arrays.copyOfRange(commandSplit, fromIndex, toIndex));;
}
split[i] = replacement;
}
return String.join(" ", split);
}
public static List<String> getResponse(UUID uuid, String input) {
return getResponse(uuid, input, Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE.getLines());
}
public static List<String> getResponse(UUID uuid, String input, List<String> defaultMessage) {
final String finalInput = input.startsWith("/") ? StringUtils.replaceFirst(input, "/", "") : input;
final String finalInput = input.startsWith("/") && input.length() > 1
? input.substring(1)
: input;
final Optional<Response> optionalResponse = RESPONSES.stream().filter(response -> {
for (String trigger : response.triggers)
@@ -39,8 +89,11 @@ public class ResponseHandler {
}).findFirst();
if (uuid != null && optionalResponse.isPresent()) {
optionalResponse.get().executeAction(uuid);
return optionalResponse.get().message;
optionalResponse.get().executeAction(uuid, finalInput);
return new ArrayList<>(optionalResponse.get().message)
.stream().map(s -> replaceArgsVariables(s, finalInput))
.collect(Collectors.toList());
}
return defaultMessage;
@@ -56,7 +109,7 @@ public class ResponseHandler {
this.actions = (List<String>) Storage.Files.CUSTOM_RESPONSES.getOrSet(key + ".actions", new ArrayList<>());
}
public void executeAction(UUID uuid) {
public void executeAction(UUID uuid, String command) {
String[] split;
for (String action : actions) {
@@ -142,7 +195,7 @@ public class ResponseHandler {
continue;
}
ActionHandler.sendTitle(action, uuid, split[1], split[2], fadeIn, stay, fadeOut);
ActionHandler.sendTitle(action, uuid, command, split[1], split[2], fadeIn, stay, fadeOut);
continue;
case "sound":
@@ -192,7 +245,7 @@ public class ResponseHandler {
Logger.warning(" > e.g: console::say Hello world!");
}
ActionHandler.executeConsoleCommand(action, uuid, split[1]);
ActionHandler.executeConsoleCommand(action, uuid, command, split[1]);
case "execute":
if (split.length == 1) {
@@ -203,7 +256,7 @@ public class ResponseHandler {
Logger.warning(" > e.g: execute::help");
}
ActionHandler.executePlayerCommand(action, uuid, split[1]);
ActionHandler.executePlayerCommand(action, uuid, command, split[1]);
case "actionbar":
if (split.length == 1) {
@@ -214,7 +267,7 @@ public class ResponseHandler {
Logger.warning(" > e.g: actionbar::I like COOKIES");
}
ActionHandler.sendActionbar(action, uuid, split[1]);
ActionHandler.sendActionbar(action, uuid, command, split[1]);
}
}
@@ -4,11 +4,11 @@ import java.util.UUID;
public interface Action {
void executeConsoleCommand(String action, UUID uuid, String command);
void executePlayerCommand(String action, UUID uuid, String command);
void sendTitle(String action, UUID uuid, String title, String subTitle, int fadeIn, int stay, int fadeOut);
void executeConsoleCommand(String action, UUID uuid, String command, String message);
void executePlayerCommand(String action, UUID uuid, String command, String message);
void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut);
void addPotionEffect(String action, UUID uuid, String potionEffectTypeName, int duration, int amplifier);
void playSound(String action, UUID uuid, String soundName, float volume, float pitch);
void sendActionbar(String action, UUID uuid, String text);
void sendActionbar(String action, UUID uuid, String command, String message);
}
@@ -6,20 +6,23 @@ import java.util.UUID;
public class ActionHandler {
private static final Action ACTION = Reflection.isProxyServer() ? Reflection.isVelocityServer() ? new VelocityAction() : new BungeeAction() : Reflection.getMinor() <= 16 ? new OldBukkitAction() : new ModernBukkitAction();
private static final Action ACTION = Reflection.isProxyServer() ? Reflection.isVelocityServer()
? new VelocityAction() : new BungeeAction()
: Reflection.getMinor() <= 16
? new OldBukkitAction() : new ModernBukkitAction();
public static void initialize() {}
public static void executeConsoleCommand(String action, UUID uuid, String command) {
ACTION.executeConsoleCommand(action, uuid, command);
public static void executeConsoleCommand(String action, UUID uuid, String command, String message) {
ACTION.executeConsoleCommand(action, uuid, command, message);
}
public static void executePlayerCommand(String action, UUID uuid, String command) {
ACTION.executePlayerCommand(action, uuid, command);
public static void executePlayerCommand(String action, UUID uuid, String command, String message) {
ACTION.executePlayerCommand(action, uuid, command, message);
}
public static void sendTitle(String action, UUID uuid, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
ACTION.sendTitle(action, uuid, title, subTitle, fadeIn, stay, fadeOut);
public static void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
ACTION.sendTitle(action, uuid, command, title, subTitle, fadeIn, stay, fadeOut);
}
public static void addPotionEffect(String action, UUID uuid, String potionEffectType, int duration, int amplifier) {
@@ -30,7 +33,7 @@ public class ActionHandler {
ACTION.playSound(action, uuid, soundName, volume, pitch);
}
public static void sendActionbar(String action, UUID uuid, String text) {
ACTION.sendActionbar(action, uuid, text);
public static void sendActionbar(String action, UUID uuid, String command, String message) {
ACTION.sendActionbar(action, uuid, command, message);
}
}
@@ -2,6 +2,7 @@ package de.rayzs.pat.utils.response.action.impl;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.response.ResponseHandler;
import de.rayzs.pat.utils.response.action.Action;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.ProxyServer;
@@ -14,28 +15,32 @@ import java.util.UUID;
public class BungeeAction implements Action {
@Override
public void executeConsoleCommand(String action, UUID uuid, String command) {
public void executeConsoleCommand(String action, UUID uuid, String command, String message) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player != null)
command = command.replace("%player%", player.getName());
message = message.replace("%player%", player.getName());
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command);
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), message);
}
@Override
public void executePlayerCommand(String action, UUID uuid, String command) {
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player != null)
command = command.replace("%player%", player.getName());
message = command.replace("%player%", player.getName());
ProxyServer.getInstance().getPluginManager().dispatchCommand(player, command);
ProxyServer.getInstance().getPluginManager().dispatchCommand(player, message);
}
@Override
public void sendTitle(String action, UUID uuid, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
title = ResponseHandler.replaceArgsVariables(title, command);
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
if (player == null)
return;
@@ -58,12 +63,13 @@ public class BungeeAction implements Action {
}
@Override
public void sendActionbar(String action, UUID uuid, String text) {
public void sendActionbar(String action, UUID uuid, String command, String message) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player == null)
return;
player.sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(StringUtils.replace(text, "%player%", player.getName())));
player.sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(StringUtils.replace(message, "%player%", player.getName())));
}
}
@@ -3,6 +3,7 @@ package de.rayzs.pat.utils.response.action.impl;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
import de.rayzs.pat.utils.response.ResponseHandler;
import de.rayzs.pat.utils.response.action.Action;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
@@ -17,35 +18,39 @@ import java.util.UUID;
public class ModernBukkitAction implements Action {
@Override
public void executeConsoleCommand(String action, UUID uuid, String command) {
public void executeConsoleCommand(String action, UUID uuid, String command, String message) {
Player player = Bukkit.getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player != null)
command = command.replace("%player%", player.getName());
message = message.replace("%player%", player.getName());
if (command.contains("%"))
command = PlaceholderReplacer.replace(player, command);
if (message.contains("%"))
message = PlaceholderReplacer.replace(player, message);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message);
}
@Override
public void executePlayerCommand(String action, UUID uuid, String command) {
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
Player player = Bukkit.getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if(player != null)
command = command.replace("%player%", player.getName());
message = message.replace("%player%", player.getName());
if (command.contains("%"))
command = PlaceholderReplacer.replace(player, command);
if (message.contains("%"))
message = PlaceholderReplacer.replace(player, message);
if (player != null)
Bukkit.dispatchCommand(player, command);
Bukkit.dispatchCommand(player, message);
}
@Override
public void sendTitle(String action, UUID uuid, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
Player player = Bukkit.getPlayer(uuid);
title = ResponseHandler.replaceArgsVariables(title, command);
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
if (player == null)
return;
@@ -98,14 +103,15 @@ public class ModernBukkitAction implements Action {
}
@Override
public void sendActionbar(String action, UUID uuid, String text) {
public void sendActionbar(String action, UUID uuid, String command, String message) {
Player player = Bukkit.getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player == null)
return;
text = PlaceholderReplacer.replace(player, StringUtils.replace(text, "&", "§", "%player%", player.getName()));
message = PlaceholderReplacer.replace(player, StringUtils.replace(message, "&", "§", "%player%", player.getName()));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(text));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
}
}
@@ -4,6 +4,7 @@ import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
import de.rayzs.pat.utils.response.ResponseHandler;
import de.rayzs.pat.utils.response.action.Action;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
@@ -21,33 +22,40 @@ public class OldBukkitAction implements Action {
private String versionPackage = null;
@Override
public void executeConsoleCommand(String action, UUID uuid, String command) {
public void executeConsoleCommand(String action, UUID uuid, String command, String message) {
Player player = Bukkit.getPlayer(uuid);
if(player != null) command = command.replace("%player%", player.getName());
message = ResponseHandler.replaceArgsVariables(message, command);
if (command.contains("%"))
command = PlaceholderReplacer.replace(player, command);
if(player != null)
message = message.replace("%player%", player.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
if (message.contains("%"))
message = PlaceholderReplacer.replace(player, message);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message);
}
@Override
public void executePlayerCommand(String action, UUID uuid, String command) {
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
Player player = Bukkit.getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player != null)
command = command.replace("%player%", player.getName());
message = message.replace("%player%", player.getName());
if (command.contains("%"))
command = PlaceholderReplacer.replace(player, command);
if (message.contains("%"))
message = PlaceholderReplacer.replace(player, message);
if (player != null)
Bukkit.dispatchCommand(player, command);
Bukkit.dispatchCommand(player, message);
}
@Override
public void sendTitle(String action, UUID uuid, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
Player player = Bukkit.getPlayer(uuid);
title = ResponseHandler.replaceArgsVariables(title, command);
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
if (player == null) return;
title = PlaceholderReplacer.replace(player, StringUtils.replace(title, "&", "§", "%player%", player.getName()));
@@ -98,13 +106,14 @@ public class OldBukkitAction implements Action {
}
@Override
public void sendActionbar(String action, UUID uuid, String text) {
public void sendActionbar(String action, UUID uuid, String command, String message) {
Player player = Bukkit.getPlayer(uuid);
message = ResponseHandler.replaceArgsVariables(message, command);
if (player == null)
return;
text = PlaceholderReplacer.replace(player, StringUtils.replace(text, "&", "§", "%player%", player.getName()));
message = PlaceholderReplacer.replace(player, StringUtils.replace(message, "&", "§", "%player%", player.getName()));
try {
if (versionPackage == null)
@@ -112,7 +121,7 @@ public class OldBukkitAction implements Action {
Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
Constructor<?> constructor = (Objects.<Class<?>>requireNonNull(Class.forName("net.minecraft.server." + versionPackage + ".PacketPlayOutChat"))).getConstructor(Class.forName("net.minecraft.server." + versionPackage + ".IChatBaseComponent"), byte.class);
Object iChatBaseComponent = (Objects.requireNonNull(Class.forName("net.minecraft.server." + versionPackage + ".IChatBaseComponent"))).getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + text + "\"}");
Object iChatBaseComponent = (Objects.requireNonNull(Class.forName("net.minecraft.server." + versionPackage + ".IChatBaseComponent"))).getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + message + "\"}");
Object actionbarPacket = constructor.newInstance(iChatBaseComponent, (byte) 2);
Object playerConnection = entityPlayer.getClass().getField("playerConnection").get(entityPlayer);
playerConnection.getClass().getMethod("sendPacket", Class.forName("net.minecraft.server." + versionPackage + ".Packet")).invoke(playerConnection, actionbarPacket);
@@ -123,6 +132,7 @@ public class OldBukkitAction implements Action {
| InvocationTargetException
| NoSuchFieldException
| InstantiationException exception) {
Logger.warning("! Failed to run action: " + action);
Logger.warning(" > Actionbars are not supported in this server version!");
}
@@ -2,6 +2,7 @@ package de.rayzs.pat.utils.response.action.impl;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.utils.message.MessageTranslator;
import de.rayzs.pat.utils.response.ResponseHandler;
import net.kyori.adventure.text.minimessage.MiniMessage;
import de.rayzs.pat.utils.response.action.Action;
import com.velocitypowered.api.proxy.Player;
@@ -14,22 +15,33 @@ import java.time.*;
public class VelocityAction implements Action {
@Override
public void executeConsoleCommand(String action, UUID uuid, String command) {
public void executeConsoleCommand(String action, UUID uuid, String command, String message) {
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
if (optPlayer.isPresent()) command = command.replace("%player%", optPlayer.get().getUsername());
VelocityLoader.getServer().getCommandManager().executeAsync(VelocityLoader.getServer().getConsoleCommandSource(), command);
message = ResponseHandler.replaceArgsVariables(message, command);
if (optPlayer.isPresent())
message = message.replace("%player%", optPlayer.get().getUsername());
VelocityLoader.getServer().getCommandManager().executeAsync(VelocityLoader.getServer().getConsoleCommandSource(), message);
}
@Override
public void executePlayerCommand(String action, UUID uuid, String command) {
public void executePlayerCommand(String action, UUID uuid, String command, String message) {
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
if (optPlayer.isPresent()) command = command.replace("%player%", optPlayer.get().getUsername());
VelocityLoader.getServer().getCommandManager().executeAsync(optPlayer.get(), command);
message = ResponseHandler.replaceArgsVariables(message, command);
if (optPlayer.isPresent())
message = command.replace("%player%", optPlayer.get().getUsername());
VelocityLoader.getServer().getCommandManager().executeAsync(optPlayer.get(), message);
}
@Override
public void sendTitle(String action, UUID uuid, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
public void sendTitle(String action, UUID uuid, String command, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
title = ResponseHandler.replaceArgsVariables(title, command);
subTitle = ResponseHandler.replaceArgsVariables(subTitle, command);
if (!optPlayer.isPresent()) return;
Player player = optPlayer.get();
@@ -51,11 +63,14 @@ public class VelocityAction implements Action {
}
@Override
public void sendActionbar(String action, UUID uuid, String text) {
public void sendActionbar(String action, UUID uuid, String command, String message) {
Optional<Player> optPlayer = VelocityLoader.getServer().getPlayer(uuid);
if (!optPlayer.isPresent()) return;
message = ResponseHandler.replaceArgsVariables(message, command);
if (!optPlayer.isPresent())
return;
Player player = optPlayer.get();
player.sendActionBar(MiniMessage.miniMessage().deserialize(MessageTranslator.replaceMessage(StringUtils.replace(text, "%player%", player.getUsername()))));
player.sendActionBar(MiniMessage.miniMessage().deserialize(MessageTranslator.replaceMessage(StringUtils.replace(message, "%player%", player.getUsername()))));
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ description: Hide more than just your plugins. Hide almost everything!
website: https://www.rayzs.de/products/proantitab/page
author: Rayzs_YT
version: 2.0.4
version: 2.0.9
main: de.rayzs.pat.plugin.BungeeLoader
softDepends: [LuckPerms, PAPIProxyBridge]
@@ -32,6 +32,15 @@
# Syntax: effect::potionEffect::duration::amplifier
# Example: effect::BLINDNESS::45::1
# Possible variable:
# %args[from-to]% to get the command arguments
# Example if you've typed: /shop open gui user
# %args[1]% = shop
# %args[2]% = open
# %args[1-2]% = shop open
# %args[1-3]% = shop open gui
# %args[2-4]% = open gui user
# Here are a few examples:
# Example for all blocked commands.
@@ -26,6 +26,15 @@
# Syntax: title::title::subtitle::5::20::5
# Example: title::&aTest title::&cHello %player%!
# Possible variable:
# %args[from-to]% to get the command arguments
# Example if you've typed: /shop open gui user
# %args[1]% = shop
# %args[2]% = open
# %args[1-2]% = shop open
# %args[1-3]% = shop open gui
# %args[2-4]% = open gui user
# Here are a few examples:
# Example for all blocked commands.
+1 -1
View File
@@ -3,7 +3,7 @@ description: Hide more than just your plugins. Hide almost everything!
website: https://www.rayzs.de/products/proantitab/page
author: Rayzs_YT
version: 2.0.4
version: 2.0.9
api-version: 1.13
folia-supported: true
main: de.rayzs.pat.plugin.BukkitLoader