ira_playz12

Make this command restriction same as on console (Like if anyone use The command on game and console they can't) Even at console everyone can't use that commands!

Kodari AI
KodariMay 23 at 8:53 pm 11,180 (v2)

I’ll help you restrict commands so they can’t be used by anyone, including console. Let me first examine your project files to see what commands and structure you have.

I can see your current setup blocks commands only for OP players. I’ll modify it so that the blocked commands are restricted for everyone, including console. Only whitelisted players will be able to use them.

Let me use a full file update instead since patching is having issues:

Perfect! I’ve updated your plugin with the following changes:

Changes made:

  1. CinderXListener.java:

    • Added ServerCommandEvent handler to block console commands

    • Removed the OP-only check from player commands - now blocks ALL players (not just OPs)

    • Only whitelisted players can bypass the restrictions

  2. CinderX.java:

    • Added getConsoleBlockedMessage() method for console-specific message

  3. config.yml:

    • Updated messages to reflect that commands are blocked for everyone

    • Added console-blocked-message configuration option

How it works now:

  • ✅ Blocked commands cannot be used by anyone (players or console)

  • ✅ Only players in the whitelist section can use blocked commands

  • ✅ Console is also completely blocked from using these commands

  • ✅ Commands like /stop, /op, /reload, etc. are blocked for everyone except whitelisted admins

The flight restriction still only applies to OP players as before.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
5 260
src/main/java/com/example/cinderx/CinderX.java
package com.example.cinderx;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public final class CinderX extends JavaPlugin {

    private CinderXListener listener;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        
        listener = new CinderXListener(this);
        getServer().getPluginManager().registerEvents(listener, this);
        
        getLogger().info("CinderX has been enabled!");
        getLogger().info("Whitelisted players: " + getWhitelist().size());
        getLogger().info("Blocked commands: " + getBlockedCommands().size());
    }

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

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (command.getName().equalsIgnoreCase("cinderx")) {
            if (!sender.hasPermission("cinderx.admin")) {
                sender.sendMessage(colorize("&cYou don't have permission to use this command!"));
                return true;
            }

            if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
                reloadConfig();
                listener.reloadCache();
                sender.sendMessage(colorize(getConfig().getString("settings.reload-message", "&aConfiguration reloaded!")));
                return true;
            }

            sender.sendMessage(colorize("&aCinderX v" + getDescription().getVersion()));
            sender.sendMessage(colorize("&7Usage: /cinderx reload"));
            return true;
        }
        return false;
    }

    public List<String> getBlockedCommands() {
        return getConfig().getStringList("blocked-commands");
    }

    public List<String> getWhitelist() {
        return getConfig().getStringList("whitelist");
    }

    public boolean isFlightBlocked() {
        return getConfig().getBoolean("settings.block-flight", true);
    }

    public String getFlightBlockedMessage() {
        return getConfig().getString("settings.flight-blocked-message", "&cYou cannot fly as an OP!");
    }

    public String getCommandBlockedMessage() {
        return getConfig().getString("settings.command-blocked-message", "&cYou cannot use this command as an OP!");
    }

    public String getConsoleBlockedMessage() {
        return getConfig().getString("settings.console-blocked-message", "&cThis command is blocked for console!");
    }

    public String colorize(String message) {
        return message.replace("&", "§");
    }
}