dripng

people are changing the last 4 letters of their ip so can you make it so theres a a plugin and if i add that ip to the config list that ip gets banned so this person ip is 184.21.311 make it so if i add 184.2 it will insta ban anyone that join with those numbers the same order i added

Kodari AI
KodariJul 18 at 10:19 pm 3
IpPrefixBan
A lightweight Minecraft server plugin that automatically bans players whose connecting IP address begins with a configured prefix. Administrators maintain a simple list of blocked IP prefixes in config.yml, allowing entries such as 184.2 to block every address beginning with those numbers, including changing final IP digits. Matching players are permanently added to the server IP ban list and kicked immediately when they join. The plugin supports configuration reloads through the /ipprefixban reload command and provides permission-based administration.
dripng

make it so it doesnt send them to other servers and it just kicks them cause i have velocity and it bans them from the hub it does the job but they get send to another server

Kodari AI
KodariJul 18 at 10:48 pm 2
  • Change the join enforcement to cancel the join before Velocity can route the player elsewhere.

  • Keep the existing IP-prefix ban behavior and use a direct kick message only.

Changed the plugin to check IP prefixes during AsyncPlayerPreLoginEvent, before the player joins the hub. Matching players are denied immediately with the configured kick message and cannot be redirected to another Velocity server.

dripng

add unban support cause i got banned and now i cnnot be unbanned make it so i cant even join if the ip is there and make it so if i delete the ip from the config im unbanned

Kodari AI
KodariJul 18 at 10:54 pm 8
  1. Use the config list as the source of truth and remove stale bans created by this plugin when settings reload.

  2. Add /ipprefixban unban <ip> for manual cleanup.

  3. Keep pre-login blocking so configured prefixes are rejected before Velocity can route them.

Updated the plugin so:

  • IP prefixes in config.yml are checked during pre-login, before the player can join.

  • Deleting an IP prefix and running /ipprefixban reload removes bans created by this plugin.

  • Added manual unban support:

    Plain Text
    /ipprefixban unban <ip>
    
  • The IP will be blocked again automatically if its prefix remains in the config.

  • /ipprefixban reload is still required after editing config.yml.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 172
src/main/java/com/kodari/ipprefixban/IpPrefixBanPlugin.java
package com.kodari.ipprefixban;

import org.bukkit.ChatColor;
import org.bukkit.BanList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Collections;
import java.util.List;
import java.util.Locale;

import org.bukkit.BanEntry;

public class IpPrefixBanPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private List<String> blockedPrefixes;
    private String banMessage;
    private String reloadMessage;
    private String noPermissionMessage;

    @Override
    public void onEnable() {
        loadSettings();
        getServer().getPluginManager().registerEvents(this, this);

        if (getCommand("ipprefixban") != null) {
            getCommand("ipprefixban").setExecutor(this);
        }
    }

    private void loadSettings() {
        saveDefaultConfig();

        blockedPrefixes = getConfig().getStringList("blocked-ip-prefixes").stream()
                .map(prefix -> prefix.trim().toLowerCase(Locale.ROOT))
                .filter(prefix -> !prefix.isEmpty())
                .toList();

        clearPluginIpBans();

        banMessage = getConfig().getString(
                "ban-message",
                "&cYour IP address is not allowed on this server."
        );
        reloadMessage = getConfig().getString(
                "reload-message",
                "&aIP prefix ban configuration reloaded."
        );
        noPermissionMessage = getConfig().getString(
                "no-permission-message",
                "&cYou do not have permission to use this command."
        );
    }

    @EventHandler
    public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
        String ipAddress = event.getAddress().getHostAddress().toLowerCase(Locale.ROOT);

        if (!isBlocked(ipAddress)) {
            return;
        }

        event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, colorize(banMessage));
    }

    private boolean isBlocked(String ipAddress) {
        return blockedPrefixes.stream().anyMatch(ipAddress::startsWith);
    }

    @SuppressWarnings("unchecked")
    private void clearPluginIpBans() {
        BanList banList = getServer().getBanList(BanList.Type.IP);

        for (Object obj : banList.getBanEntries()) {
            BanEntry entry = (BanEntry) obj;
            if ("IpPrefixBan".equals(entry.getSource())) {
                banList.pardon(entry.getTarget());
            }
        }
    }

    @Override
    public boolean onCommand(
            CommandSender sender,
            Command command,
            String label,
            String[] args
    ) {
        if (!sender.hasPermission("ipprefixban.reload")) {
            sender.sendMessage(colorize(noPermissionMessage));
            return true;
        }

        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            reloadConfig();
            loadSettings();
            sender.sendMessage(colorize(reloadMessage));
            return true;
        }

        if (args.length == 2 && args[0].equalsIgnoreCase("unban")) {
            BanList banList = getServer().getBanList(BanList.Type.IP);
            banList.pardon(args[1]);
            sender.sendMessage(ChatColor.GREEN + "IP unbanned: " + args[1]);
            return true;
        }

        sender.sendMessage(ChatColor.RED + "Usage: /ipprefixban reload | /ipprefixban unban <ip>");
        return true;
    }

    private String colorize(String message) {
        return ChatColor.translateAlternateColorCodes('&', message);
    }
}