Create a Paper 1.21.11-compatible Minecraft server plugin that disables command-block functionality, controlled only from the server panel/console. Implement a console-only command (not usable by players or command blocks) named /commandblocks with a simple on/off toggle or explicit on/off argument; default to disabled. Ensure command block execution is prevented while disabled, and can be re-enabled with the command. Persist the selected state across restarts using plugin configuration. Register command and permissions appropriately; console access should not depend on a player permission. Give clear feedback and reject non-console senders. Include plugin metadata/config as needed. Do not add tests. Build feature code only; do not build.

Kodari AI
KodariOct 30 at 10:44 pm 1
CommandBlockToggle
Console-only Minecraft plugin that toggles command block functionality globally. Registers a /commandblocks command restricted to server console, defaulting to disabled state. Prevents command block execution when disabled while allowing re-enable via console. Persists state in plugin configuration across restarts. Rejects non-console senders with clear feedback, requires no player permissions for console access, and provides explicit on/off argument support.
  1. Create the Paper plugin metadata and default-disabled persisted config.

  2. Add a console-only /commandblocks [on|off] toggle and block command-block command execution while disabled.

Created the Paper 1.21.11 plugin. Command-block execution defaults to disabled and is persisted in config.yml. The console can use /commandblocks to toggle it or /commandblocks on|off to set it explicitly; other senders are rejected. No player permission is required. No build or tests were run.

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

import org.bukkit.block.CommandBlock;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class CommandBlocksPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private boolean commandBlocksEnabled;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        commandBlocksEnabled = getConfig().getBoolean("enabled", false);
        getCommand("commandblocks").setExecutor(this);
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof ConsoleCommandSender)) {
            sender.sendMessage("Only the server console can use this command.");
            return true;
        }

        if (args.length > 1) {
            sender.sendMessage("Usage: /commandblocks [on|off]");
            return true;
        }

        if (args.length == 0) {
            commandBlocksEnabled = !commandBlocksEnabled;
        } else if (args[0].equalsIgnoreCase("on")) {
            commandBlocksEnabled = true;
        } else if (args[0].equalsIgnoreCase("off")) {
            commandBlocksEnabled = false;
        } else {
            sender.sendMessage("Usage: /commandblocks [on|off]");
            return true;
        }

        getConfig().set("enabled", commandBlocksEnabled);
        saveConfig();
        sender.sendMessage("Command blocks are now " + (commandBlocksEnabled ? "enabled" : "disabled") + ".");
        return true;
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onServerCommand(ServerCommandEvent event) {
        if (!commandBlocksEnabled && event.getSender() instanceof BlockCommandSender) {
            event.setCancelled(true);
        }
    }
}