Fixed ArrayOutOfBounds-Exception
This commit is contained in:
Alihan authored and GitHub committed 2023-11-18 21:22:33 +01:00
1 parent 181c326ce6
commit a127838615
4 files changed
+29 -23

No files matched your search

@@ -6,6 +6,9 @@ import de.rayzs.pat.utils.*;
import org.bukkit.event.*;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.List;
public class BukkitAntiTabListener implements Listener {
@EventHandler (priority = EventPriority.LOWEST)
@@ -13,36 +16,30 @@ public class BukkitAntiTabListener implements Listener {
Player player = event.getPlayer();
if(PermissionUtil.hasBypassPermission(player)) return;
for (int i = 0; i < event.getCommands().size(); i++) {
String command = (String) event.getCommands().toArray()[i], tempName = command;
List<String> dummy = new ArrayList<>(event.getCommands()),
commands = new ArrayList<>();
for (int i = 0; i < dummy.size(); i++) {
String command = dummy.get(i), tempName = command;
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
if(!PermissionUtil.hasBypassPermission(player, tempName)) {
if(Storage.isCommandBlockedPrecise(tempName)) {
event.getCommands().add(command);
if (!event.getCommands().contains(tempName)) event.getCommands().add(tempName);
} else {
event.getCommands().remove(command);
if(event.getCommands().contains(tempName)) event.getCommands().remove(tempName);
}
}
if(!PermissionUtil.hasBypassPermission(player, tempName) && Storage.isCommandBlockedPrecise(tempName))
commands.add(command);
continue;
}
if (tempName.contains(":")) tempName = tempName.split(":")[1];
if (Storage.isCommandBlocked(tempName)) {
if(PermissionUtil.hasBypassPermission(player, tempName)) {
event.getCommands().add(command);
if(!event.getCommands().contains(tempName)) event.getCommands().add(tempName);
}
else {
event.getCommands().remove(command);
if(event.getCommands().contains(tempName)) event.getCommands().remove(tempName);
}
if(PermissionUtil.hasBypassPermission(player, tempName)) continue;
event.getCommands().remove(command);
if(event.getCommands().contains(tempName)) event.getCommands().remove(tempName);
}
}
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
event.getCommands().clear();
event.getCommands().addAll(commands);
}
}
public static void updateCommands() {
@@ -28,7 +28,10 @@ public class BukkitBlockCommandListener implements Listener {
return;
}
if (command.contains(":")) command = command.split(":")[1];
if (command.contains(":")) {
String[] commandSplit = command.split(":");
if(commandSplit.length > 1) command = commandSplit[1];
}
if (!Storage.isCommandBlocked(commandLowerCased)) return;
if (PermissionUtil.hasBypassPermission(player, command)) return;
@@ -61,7 +61,10 @@ public class BungeeAntiTabListener implements Listener {
continue;
}
if (tempName.contains(":")) tempName = tempName.split(":")[1];
if (tempName.contains(":")) {
String[] tempCommandSplit = tempName.split(":");
if(tempCommandSplit.length > 1) tempName = tempCommandSplit[1];
}
if (!Storage.isCommandBlocked(tempName)) continue;
if(PermissionUtil.hasBypassPermission(player, tempName)) continue;
@@ -32,7 +32,10 @@ public class BungeeBlockCommandListener implements Listener {
return;
}
if(command.contains(":")) command = command.split(":")[1];
if (command.contains(":")) {
String[] commandSplit = command.split(":");
if(commandSplit.length > 1) command = commandSplit[1];
}
if(!Storage.isCommandBlocked(command) || PermissionUtil.hasBypassPermission(player, command)) return;
player.sendMessage(Storage.CANCEL_COMMANDS_MESSAGE.replace("%command%", rawCommand.replaceFirst("/", "")));