mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-01 04:49:44 -05:00
Code Improvement
This commit is contained in:
1 parent
3d369aa595
commit
8802642796
16 files changed
+72
-83
No files matched your search
@@ -24,6 +24,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
private static Plugin plugin;
|
||||
private static java.util.logging.Logger logger;
|
||||
private static boolean loaded = false;
|
||||
private int updaterTaskId;
|
||||
|
||||
@Override
|
||||
@@ -52,6 +53,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
if(Storage.BUNGEECORD)
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, ClientCommunication::sendRequest, 40, 20*10);
|
||||
else {
|
||||
loaded = true;
|
||||
GroupManager.initialize();
|
||||
PacketAnalyzer.injectAll();
|
||||
|
||||
@@ -89,6 +91,10 @@ public class BukkitLoader extends JavaPlugin {
|
||||
Storage.TURN_BLACKLIST_TO_WHITELIST = turn;
|
||||
|
||||
if(Reflection.getMinor() >= 18) BukkitAntiTabListener.handleTabCompletion(commands);
|
||||
if(!loaded) {
|
||||
loaded = true;
|
||||
Logger.info("First data has arrived successfully!");
|
||||
}
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
@@ -135,7 +141,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
public static List<String> getNotBlockedCommands() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
Bukkit.getHelpMap().getHelpTopics().stream()
|
||||
.filter(topic -> !topic.getName().contains(":") && topic.getName().startsWith("/") && !Storage.isCommandBlocked(topic.getName().replaceFirst("/", "")))
|
||||
.filter(topic -> !topic.getName().contains(":") && topic.getName().startsWith("/") && !Storage.isBlocked(topic.getName().replaceFirst("/", ""), false))
|
||||
.forEach(topic -> commands.add(topic.getName().replaceFirst("/", "")));
|
||||
return commands;
|
||||
}
|
||||
@@ -147,4 +153,8 @@ public class BukkitLoader extends JavaPlugin {
|
||||
public static java.util.logging.Logger getPluginLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
@@ -39,8 +39,13 @@ public class ClientCommunication {
|
||||
client.setFeedback(true);
|
||||
client.syncTime();
|
||||
Storage.SERVER_DATA_SYNC_COUNT++;
|
||||
sendInformation("receive-info::" + Storage.TOKEN_KEY + "::" + client.getId() + "::" + client.getName());
|
||||
}
|
||||
break;
|
||||
case "receive-info":
|
||||
if(!args[2].equals(ClientCommunication.SERVER_ID.toString()) || Storage.SERVER_NAME != null || args.length != 4 || !args[1].equals(Storage.TOKEN_KEY)) return;
|
||||
Storage.SERVER_NAME = args[3];
|
||||
break;
|
||||
case "receive-commands":
|
||||
if(args.length != 4 || !args[1].equals(Storage.TOKEN_KEY)) return;
|
||||
BukkitLoader.synchronizeCommandData(Boolean.parseBoolean(args[2]), args[3].equals("§") ? new ArrayList<>() : Arrays.asList(args[3].split(";")));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.utils.*;
|
||||
@@ -16,11 +17,8 @@ public class BukkitAntiTabListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
if (PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getCommands().removeIf(command -> {
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isCommandBlocked(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
});
|
||||
if(!BukkitLoader.isLoaded()) event.getCommands().clear();
|
||||
else event.getCommands().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
|
||||
@@ -47,19 +47,14 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
}
|
||||
|
||||
if((Storage.TURN_BLACKLIST_TO_WHITELIST)) {
|
||||
if(Storage.isCommandBlockedPrecise(command)) return;
|
||||
if(Storage.isBlocked(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.contains(":")) {
|
||||
String[] commandSplit = command.split(":");
|
||||
if(commandSplit.length > 1) command = commandSplit[1];
|
||||
}
|
||||
|
||||
if (!Storage.isCommandBlocked(commandLowerCased)) return;
|
||||
if (!Storage.isBlocked(commandLowerCased, false)) return;
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
|
||||
@@ -17,11 +17,7 @@ public class BungeeAntiTabListener implements Listener {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> {
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isCommandBlocked(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
});
|
||||
event.getSuggestions().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -31,10 +27,6 @@ public class BungeeAntiTabListener implements Listener {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> {
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isCommandBlocked(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
});
|
||||
event.getSuggestions().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
}
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
|
||||
if(Storage.isCommandBlockedPrecise(command)) return;
|
||||
if(Storage.isBlocked(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
@@ -50,12 +50,7 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.contains(":")) {
|
||||
String[] commandSplit = command.split(":");
|
||||
if(commandSplit.length > 1) command = commandSplit[1];
|
||||
}
|
||||
|
||||
if(!Storage.isCommandBlocked(command) || PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
if(!Storage.isBlocked(command, false) || PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) Logger.info(alertMessage);
|
||||
|
||||
@@ -17,12 +17,6 @@ public class WaterfallAntiTabListener implements Listener {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getCommands().entrySet().removeIf(entry -> {
|
||||
String command = entry.getKey();
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isCommandBlocked(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
});
|
||||
event.getCommands().entrySet().removeIf(entry -> Storage.hasNoAccess(player, entry.getKey()));
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,7 @@ public class VelocityAntiTabListener {
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> {
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isCommandBlocked(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
});
|
||||
event.getSuggestions().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
}
|
||||
|
||||
@Subscribe (order = PostOrder.FIRST)
|
||||
@@ -36,12 +32,7 @@ public class VelocityAntiTabListener {
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getRootNode().getChildren().removeIf(command -> {
|
||||
String commandName = command.getName();
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(commandName) && !PermissionUtil.hasBypassPermission(player, commandName);
|
||||
else return Storage.isCommandBlocked(commandName) && !PermissionUtil.hasBypassPermission(player, commandName);
|
||||
});
|
||||
event.getRootNode().getChildren().removeIf(command -> Storage.hasNoAccess(player, command.getName()));
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
|
||||
+2
-7
@@ -43,7 +43,7 @@ public class VelocityBlockCommandListener {
|
||||
}
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
|
||||
if(Storage.isCommandBlockedPrecise(command)) return;
|
||||
if(Storage.isBlocked(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", command.replaceFirst("/", "")));
|
||||
@@ -51,12 +51,7 @@ public class VelocityBlockCommandListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.contains(":")) {
|
||||
String[] commandSplit = command.split(":");
|
||||
if(commandSplit.length > 1) command = commandSplit[1];
|
||||
}
|
||||
|
||||
if(!Storage.isCommandBlocked(command) || PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
if(!Storage.isBlocked(command, false) || PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", command.replaceFirst("/", "")));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) MessageTranslator.send(server.getConsoleCommandSource(), alertMessage);
|
||||
|
||||
@@ -38,8 +38,8 @@ public class LegacyPacketHandler implements PacketHandler {
|
||||
input = input.replace("/", "");
|
||||
if(input.contains(" ")) input = input.split(" ")[0];
|
||||
|
||||
cancelsBeforeHand = Storage.isCommandBlockedPrecise(input) && !PermissionUtil.hasBypassPermission(player, input)
|
||||
|| Storage.isCommandBlocked(input) && !PermissionUtil.hasBypassPermission(player, input);
|
||||
cancelsBeforeHand = Storage.isBlocked(input, true) && !PermissionUtil.hasBypassPermission(player, input)
|
||||
|| Storage.isBlocked(input, false) && !PermissionUtil.hasBypassPermission(player, input);
|
||||
}
|
||||
|
||||
for (Field field : Reflection.getFields(packetObj)) {
|
||||
@@ -57,7 +57,7 @@ public class LegacyPacketHandler implements PacketHandler {
|
||||
tempName = s.replaceFirst("/", "");
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
|
||||
if(!Storage.isCommandBlockedPrecise(tempName)) continue;
|
||||
if(!Storage.isBlocked(tempName, true)) continue;
|
||||
if(PermissionUtil.hasBypassPermission(player, tempName)) continue;
|
||||
newResultList.add(s);
|
||||
continue;
|
||||
@@ -65,8 +65,8 @@ public class LegacyPacketHandler implements PacketHandler {
|
||||
|
||||
if (tempName.contains(":")) tempName = tempName.split(":")[1];
|
||||
|
||||
if (!Storage.isCommandBlocked(tempName)
|
||||
|| Storage.isCommandBlocked(tempName)
|
||||
if (!Storage.isBlocked(tempName, false)
|
||||
|| Storage.isBlocked(tempName, false)
|
||||
&& PermissionUtil.hasBypassPermission(player, tempName))
|
||||
newResultList.add(s);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ public class ModernPacketHandler implements PacketHandler {
|
||||
String[] split = input.split(" ");
|
||||
if(input.contains(" ")) input = split[0];
|
||||
|
||||
cancelsBeforeHand = !Storage.TURN_BLACKLIST_TO_WHITELIST && Storage.isCommandBlockedPrecise(input) && !PermissionUtil.hasBypassPermission(player, input)
|
||||
|| Storage.TURN_BLACKLIST_TO_WHITELIST && !Storage.isCommandBlocked(input) && !PermissionUtil.hasBypassPermission(player, input);
|
||||
cancelsBeforeHand = !Storage.TURN_BLACKLIST_TO_WHITELIST && Storage.isBlocked(input, true) && !PermissionUtil.hasBypassPermission(player, input)
|
||||
|| Storage.TURN_BLACKLIST_TO_WHITELIST && !Storage.isBlocked(input, false) && !PermissionUtil.hasBypassPermission(player, input);
|
||||
}
|
||||
|
||||
Suggestions suggestions = (Suggestions) suggestionsMethod.invoke(packetObj);
|
||||
@@ -58,8 +58,8 @@ public class ModernPacketHandler implements PacketHandler {
|
||||
suggestions.getList().removeIf(suggestion -> {
|
||||
String command = suggestion.getText();
|
||||
if (Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isCommandBlockedPrecise(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isCommandBlocked(command) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
return !Storage.isBlocked(command, true) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
else return Storage.isBlocked(command, false) && !PermissionUtil.hasBypassPermission(player, command);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public class CommandProcess {
|
||||
String task, sub, extra, confirmationString;
|
||||
Group group;
|
||||
boolean bool;
|
||||
|
||||
if(!PermissionUtil.hasPermissionWithResponse(sender, "use")) return;
|
||||
|
||||
if(Storage.BUNGEECORD) {
|
||||
|
||||
@@ -45,6 +45,12 @@ public class CommandSender {
|
||||
else if(sender instanceof org.bukkit.command.CommandSender) ((org.bukkit.command.CommandSender) sender).sendMessage(text);
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
if(Reflection.isVelocityServer()) return sender instanceof com.velocitypowered.api.proxy.Player ? ((com.velocitypowered.api.proxy.Player) sender).getCurrentServer().get().getServer().getServerInfo().getName() : Storage.SERVER_NAME;
|
||||
else if(Reflection.isProxyServer()) return sender instanceof ProxiedPlayer ? ((ProxiedPlayer) sender).getServer().getInfo().getName() : Storage.SERVER_NAME;
|
||||
return Storage.SERVER_NAME;
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
if(Reflection.isVelocityServer()) return sender instanceof com.velocitypowered.api.proxy.Player ? ((com.velocitypowered.api.proxy.Player) sender).getUniqueId() : CONSOLE_UUID;
|
||||
else if(Reflection.isProxyServer()) return sender instanceof ProxiedPlayer ? ((ProxiedPlayer) sender).getUniqueId() : CONSOLE_UUID;
|
||||
|
||||
@@ -20,9 +20,19 @@ public class PermissionUtil {
|
||||
public static boolean hasBypassPermission(Object targetObj, String command) {
|
||||
return hasBypassPermission(targetObj)
|
||||
|| hasPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
|| hasServerPermission(targetObj, "bypass." + command.toLowerCase(), Storage.SERVER_NAME)
|
||||
|| GroupManager.canAccessCommand(targetObj, command);
|
||||
}
|
||||
|
||||
public static boolean hasServerPermission(Object target, String permission, String server) {
|
||||
String targetServerName = Storage.SERVER_NAME;
|
||||
if(target instanceof CommandSender) targetServerName = ((CommandSender) target).getServerName();
|
||||
if(targetServerName == null) return false;
|
||||
|
||||
String permissionString = permission + "." + Storage.SERVER_NAME;
|
||||
return hasPermission(target, permissionString) || hasPermission(target, permissionString + ".*") && server.startsWith(targetServerName);
|
||||
}
|
||||
|
||||
public static boolean hasPermissionWithResponse(Object targetObj, String command) {
|
||||
boolean permitted = hasPermission(targetObj, command);
|
||||
if(!permitted) {
|
||||
|
||||
@@ -9,7 +9,7 @@ public class Storage {
|
||||
COMMANDS = Configurator.get("commands"),
|
||||
TOKEN = Configurator.get("token");
|
||||
|
||||
public static String CURRENT_VERSION_NAME = "", NEWEST_VERSION_NAME = "";
|
||||
public static String CURRENT_VERSION_NAME = "", NEWEST_VERSION_NAME = "", SERVER_NAME = null;
|
||||
public static List<String> UNKNOWN_COMMAND, CANCEL_COMMANDS_MESSAGE, STATS, BLOCKED_COMMANDS_LIST, COMMAND_HELP, CUSTOM_SERVER_BRANDS, UPDATE_NOTIFICATION, CUSTOM_PLUGINS;
|
||||
public static List<UUID> NOTIFY_PLAYERS = new ArrayList<>();
|
||||
public static String TOKEN_KEY = UUID.randomUUID().toString(), BUNGEECORD_MESSAGE, NOTIFY_ALERT, NOTIFY_ENABLED, NOTIFY_DISABLED, COMMAND_UNKNOWN, NO_PERMISSIONS, RELOAD_LOADING, RELOAD_DONE,
|
||||
@@ -164,36 +164,33 @@ public class Storage {
|
||||
STORAGE.setAndSave("commands", BLOCKED_COMMANDS_LIST);
|
||||
}
|
||||
|
||||
public static boolean isCommandBlocked(String command) {
|
||||
public static boolean isBlocked(String command, boolean intensive) {
|
||||
command = command.toLowerCase();
|
||||
if(command.startsWith("/")) command = command.replaceFirst("/", "");
|
||||
|
||||
String[] split;
|
||||
if(command.contains(" ")) {
|
||||
split = command.split(" ");
|
||||
if(split.length > 0) command = split[0];
|
||||
command = command.split(" ")[0];
|
||||
}
|
||||
if(command.contains(":")) {
|
||||
|
||||
if(intensive && command.contains(":")) {
|
||||
split = command.split(":");
|
||||
if(split.length > 0) command = command.replaceFirst(split[0] + ":", "");
|
||||
if(split.length > 0)
|
||||
command = command.replaceFirst(split[0] + ":", "");
|
||||
}
|
||||
for (String blockedCommand : BLOCKED_COMMANDS_LIST) {
|
||||
|
||||
if (blockedCommand.equals(command.toLowerCase())) return true;
|
||||
for (String blockedCommand : BLOCKED_COMMANDS_LIST)
|
||||
if(blockedCommand.equals(command)) return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCommandBlockedPrecise(String command) {
|
||||
String[] split;
|
||||
if(command.contains(" ")) {
|
||||
split = command.split(" ");
|
||||
if(split.length > 0) command = split[0];
|
||||
command = command.split(" ")[0];
|
||||
}
|
||||
for (String blockedCommand : BLOCKED_COMMANDS_LIST) {
|
||||
if(blockedCommand.equals(command.toLowerCase())) return true;
|
||||
}
|
||||
return false;
|
||||
public static boolean hasNoAccess(Object target, String command) {
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST)
|
||||
return !Storage.isBlocked(command, false) && !PermissionUtil.hasBypassPermission(target, command);
|
||||
else return Storage.isBlocked(command, false) && !PermissionUtil.hasBypassPermission(target, command);
|
||||
}
|
||||
|
||||
public static boolean isPluginsCommand(String command) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Group {
|
||||
}
|
||||
|
||||
public boolean hasPermission(Object targetObj) {
|
||||
return PermissionUtil.hasPermission(targetObj, "group." + groupName);
|
||||
return PermissionUtil.hasPermission(targetObj, "group." + groupName) || PermissionUtil.hasServerPermission(targetObj, "group." + groupName, Storage.SERVER_NAME);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
Reference in new issue
Block a user