mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 09:31:54 +00:00
Add allowlist show command with optional search filter
Co-authored-by: funkemunky <30784509+funkemunky@users.noreply.github.com>
This commit is contained in:
+54
-6
@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class AllowlistCommand extends Command {
|
public class AllowlistCommand extends Command {
|
||||||
|
|
||||||
private static final String[] secondArgs = new String[] {"add", "remove"};
|
private static final String[] secondArgs = new String[] {"add", "remove", "show"};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String permission() {
|
public String permission() {
|
||||||
@@ -53,7 +53,7 @@ public class AllowlistCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String usage() {
|
public String usage() {
|
||||||
return "<add/remove> <player/uuid/ip>";
|
return "<add <player/uuid/ip> | remove <player/uuid/ip> | show [search]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,6 +72,49 @@ public class AllowlistCommand extends Command {
|
|||||||
return "&cUsage: /antivpn allowlist " + usage();
|
return "&cUsage: /antivpn allowlist " + usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(args[0].equalsIgnoreCase("show")) {
|
||||||
|
String search = args.length > 1 ? args[1].toLowerCase() : null;
|
||||||
|
// Strip color code characters to prevent formatting injection in output
|
||||||
|
String safeSearch = search != null ? search.replace("&", "") : null;
|
||||||
|
boolean databaseEnabled = AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled();
|
||||||
|
|
||||||
|
List<UUID> uuids = databaseEnabled
|
||||||
|
? AntiVPN.getInstance().getDatabase().getAllWhitelisted()
|
||||||
|
: new ArrayList<>(AntiVPN.getInstance().getExecutor().getWhitelisted());
|
||||||
|
List<CIDRUtils> ips = databaseEnabled
|
||||||
|
? AntiVPN.getInstance().getDatabase().getAllWhitelistedIps()
|
||||||
|
: new ArrayList<>(AntiVPN.getInstance().getExecutor().getWhitelistedIps());
|
||||||
|
|
||||||
|
List<String> messages = new ArrayList<>();
|
||||||
|
messages.add("&8&m-----------------------------------------------------");
|
||||||
|
messages.add("&6&lAllowlist Entries" + (safeSearch != null ? " &7(search: &f" + safeSearch + "&7)" : ""));
|
||||||
|
messages.add("");
|
||||||
|
|
||||||
|
boolean any = false;
|
||||||
|
for (UUID uuid : uuids) {
|
||||||
|
String entry = uuid.toString();
|
||||||
|
if (search == null || entry.toLowerCase().contains(search)) {
|
||||||
|
messages.add("&7- &fUUID: &e" + entry);
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CIDRUtils cidr : ips) {
|
||||||
|
String entry = cidr.getCidr();
|
||||||
|
if (search == null || entry.toLowerCase().contains(search)) {
|
||||||
|
messages.add("&7- &fIP: &e" + entry);
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!any) {
|
||||||
|
messages.add(safeSearch != null
|
||||||
|
? "&cNo allowlist entries matching &f\"" + safeSearch + "&c\" were found."
|
||||||
|
: "&cThe allowlist is empty.");
|
||||||
|
}
|
||||||
|
messages.add("&8&m-----------------------------------------------------");
|
||||||
|
return String.join("\n", messages);
|
||||||
|
}
|
||||||
|
|
||||||
if(args.length == 1)
|
if(args.length == 1)
|
||||||
return "&cYou have to provide a player to allow or deny exemption.";
|
return "&cYou have to provide a player to allow or deny exemption.";
|
||||||
|
|
||||||
@@ -201,10 +244,15 @@ public class AllowlistCommand extends Command {
|
|||||||
case 1 -> Arrays.stream(secondArgs)
|
case 1 -> Arrays.stream(secondArgs)
|
||||||
.filter(narg -> narg.toLowerCase().startsWith(args[0].toLowerCase()))
|
.filter(narg -> narg.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
case 2 -> AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
case 2 -> {
|
||||||
.map(APIPlayer::getName)
|
if (args[0].equalsIgnoreCase("show")) {
|
||||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
yield Collections.emptyList();
|
||||||
.collect(Collectors.toList());
|
}
|
||||||
|
yield AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
||||||
|
.map(APIPlayer::getName)
|
||||||
|
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
default -> Collections.emptyList();
|
default -> Collections.emptyList();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user