K

make a Minecraft plugin name PenGuard: this plugin have feature when player or someone try to use op command or anything but that player not whitelist in config it will ban player forever. and the command that execute also not working. author Kunthean.

Kodari AI
KodariMar 6 at 2:18 am 6,119 (v2)

I’ll create PenGuard, a security plugin that prevents unauthorized players from executing dangerous commands and permanently bans them.

PenGuard
A security plugin that monitors command execution and permanently bans non-whitelisted players who attempt to use restricted commands like op. Features configurable command blacklist, player whitelist system, automatic permanent bans, and command blocking to prevent unauthorized access. Protects servers from malicious users attempting privilege escalation.

Plugin created successfully! PenGuard will:

  • Monitor all commands executed by players

  • Block and ban non-whitelisted players who try restricted commands (op, deop, stop, etc.)

  • Cancel the command execution before it runs

  • Permanently ban offending players with configurable messages

  • Notify admins in real-time about security attempts

  • Log all incidents to console

K

Make it blocked all command that only op player can execute. Add discord webhook for alert etc. add more feature for staff or admin to see player or protect security server. And more config. Make hex color support

Kodari AI
KodariMar 6 at 2:22 am 20,661 (v2)

I’ll analyze the current code and enhance PenGuard with command blocking, Discord webhooks, staff monitoring features, and hex color support.

I’ll enhance PenGuard with comprehensive security features including OP command blocking, Discord webhooks, staff monitoring tools, and hex color support.

Enhanced PenGuard with comprehensive security features including OP command detection, Discord webhooks with embeds, player data tracking, command history, IP logging, suspicious activity detection, staff monitoring commands, and full hex color + gradient support.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
Code
12 1,205
src/main/java/com/kunthean/penguard/PenGuard.java
package com.kunthean.penguard;

import com.kunthean.penguard.commands.PenGuardCommand;
import com.kunthean.penguard.listeners.CommandListener;
import com.kunthean.penguard.listeners.SecurityListener;
import com.kunthean.penguard.managers.PlayerDataManager;
import com.kunthean.penguard.managers.SecurityManager;
import com.kunthean.penguard.utils.DiscordWebhook;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;
import java.util.stream.Collectors;

@Getter
public class PenGuard extends JavaPlugin {

    private List<String> whitelistedPlayers;
    private List<String> blockedCommands;
    private String banReason;
    private String banMessage;
    private String attemptMessage;
    private boolean enableLogging;
    private boolean notifyAdmins;

    private PlayerDataManager playerDataManager;
    private SecurityManager securityManager;
    private DiscordWebhook discordWebhook;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadConfiguration();

        this.playerDataManager = new PlayerDataManager(this);
        this.securityManager = new SecurityManager(this);

        if (getConfig().getBoolean("discord.enabled")) {
            this.discordWebhook = new DiscordWebhook(this);
        }

        Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
        Bukkit.getPluginManager().registerEvents(new SecurityListener(this), this);

        PenGuardCommand commandExecutor = new PenGuardCommand(this);
        getCommand("penguard").setExecutor(commandExecutor);
        getCommand("penguard").setTabCompleter(commandExecutor);

        getLogger().info("PenGuard has been enabled!");
        getLogger().info("Whitelisted players: " + whitelistedPlayers.size());
        getLogger().info("Blocked commands: " + blockedCommands.size());
        
        if (getConfig().getBoolean("block-op-only-commands")) {
            getLogger().info("OP-only command blocking: ENABLED");
        }
        
        if (getConfig().getBoolean("discord.enabled")) {
            getLogger().info("Discord webhook: ENABLED");
        }
    }

    @Override
    public void onDisable() {
        getLogger().info("PenGuard has been disabled!");
    }

    public void loadConfiguration() {
        FileConfiguration config = getConfig();

        whitelistedPlayers = config.getStringList("whitelisted-players")
                .stream()
                .map(String::toLowerCase)
                .collect(Collectors.toList());

        blockedCommands = config.getStringList("blocked-commands")
                .stream()
                .map(String::toLowerCase)
                .collect(Collectors.toList());

        banReason = config.getString("messages.ban-reason", "<#ff0000>You have been permanently banned for attempting to execute unauthorized commands.");
        banMessage = config.getString("messages.ban-message", "<#ff0000><bold>[PenGuard]</bold> <#ffaa00>Player <#ff0000>{player} <#ffaa00>has been permanently banned for attempting: <#ff0000>{command}");
        attemptMessage = config.getString("messages.attempt-message", "<#ff0000><bold>[SECURITY]</bold> <#ff0000>{player} <#ffaa00>tried to execute: <#ff0000>{command}");
        enableLogging = config.getBoolean("enable-logging", true);
        notifyAdmins = config.getBoolean("notify-admins", true);

        if (config.getBoolean("discord.enabled") && discordWebhook == null) {
            this.discordWebhook = new DiscordWebhook(this);
        }
    }
}