voidqz

Option 1: Short & Direct (Best for ChatGPT / AI)

Write a lightweight Paper Spigot Java plugin for version 1.21.1. The plugin should block players without operator status (op) from running /plugins, /pl, /bukkit:plugins, or any command aliased to /plugins. When a non-op player tries to run these commands, cancel the event and send them a custom message: &cYou do not have permission to view server plugins!. Include the complete plugin.yml file and the main Java listener class.

Kodari AI
KodariAug 30 at 3:29 pm 1
PluginCommandGuard
Lightweight Paper Spigot plugin for 1.21.1 that intercepts and blocks non-operator players from executing /plugins, /pl, /bukkit:plugins, or any aliased plugin-listing commands. Uses a Bukkit event listener to cancel the command event and sends a custom red-colored denial message to the player. Includes complete plugin.yml configuration and a single main listener class for minimal footprint and easy deployment.
  1. Create the Gradle project metadata for Paper 1.21.1.

  2. Add plugin.yml with the plugin main class and permission metadata.

  3. Add the listener that blocks /plugins, /pl, and namespaced forms for non-operators.

Created the Paper 1.21.1 plugin:

  • src/main/java/com/example/plugincommandblocker/PluginCommandBlocker.java

    • Blocks /plugins, /pl, and namespaced variants such as /bukkit:plugins.

    • Allows operators to use the commands.

    • Sends: &cYou do not have permission to view server plugins!

  • src/main/resources/plugin.yml

  • build.gradle

  • settings.gradle

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 81
src/main/java/com/example/plugincommandblocker/PluginCommandBlocker.java
package com.example.plugincommandblocker;

import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Locale;

public final class PluginCommandBlocker extends JavaPlugin implements Listener {

    private static final String DENIED_MESSAGE = "&cYou do not have permission to view server plugins!";

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

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
        if (event.getPlayer().isOp()) {
            return;
        }

        String command = event.getMessage().trim();
        if (command.startsWith("/")) {
            command = command.substring(1);
        }

        String label = command.split("\\s+", 2)[0].toLowerCase(Locale.ROOT);
        int namespaceSeparator = label.lastIndexOf(':');
        if (namespaceSeparator >= 0) {
            label = label.substring(namespaceSeparator + 1);
        }

        if (label.equals("plugins") || label.equals("pl")) {
            event.setCancelled(true);
            event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', DENIED_MESSAGE));
        }
    }
}