feat: ip filter add username convert to ip automatically

This commit is contained in:
ChomeNS
2025-08-27 20:08:37 +07:00
parent e59e44a5fb
commit 1b4f1419c0
2 changed files with 14 additions and 3 deletions

View File

@@ -1 +1 @@
3645
3646

View File

@@ -5,6 +5,7 @@ import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
import me.chayapak1.chomens_bot.command.TrustLevel;
import me.chayapak1.chomens_bot.data.player.PlayerEntry;
import me.chayapak1.chomens_bot.plugins.DatabasePlugin;
import me.chayapak1.chomens_bot.plugins.IPFilterPlugin;
import net.kyori.adventure.text.Component;
@@ -16,11 +17,14 @@ import java.util.List;
import java.util.Map;
public class IPFilterCommand extends Command {
private static final String FORCE_IP_FLAG = "forceip";
public IPFilterCommand () {
super(
"ipfilter",
new String[] {
"add <ip> [reason]",
"add <player/ip> [reason]",
"-forceip add ...",
"remove <index>",
"clear",
"list"
@@ -39,9 +43,16 @@ public class IPFilterCommand extends Command {
switch (action) {
case "add" -> {
final String ip = context.getString(false, true);
final List<String> flags = context.getFlags(true, FORCE_IP_FLAG);
final String rawIP = context.getString(false, true);
final String reason = context.getString(true, false);
final PlayerEntry player = bot.players.getEntry(rawIP);
final String ip = (!flags.contains(FORCE_IP_FLAG) && player != null && player.persistingData.ip != null)
? player.persistingData.ip
: rawIP;
if (IPFilterPlugin.localList.containsKey(ip)) {
throw new CommandException(
Component.translatable(