O

create a command '/operator debug' that sets the user to operator and can only be used by operators

Kodari AI
KodariJul 27 at 1:16 am 1
OperatorDebugPlugin
A lightweight plugin that adds the /operator debug command. When used by a player who is already an operator, the command re-asserts operator status on the player. Non-operators cannot run the command. Simple and secure — leverages Bukkit's built-in op system with no additional permission management.
Kodari can make mistakes. Review important code before using.
Files
src
Code
2 56
src/main/java/com/operatordebug/OperatorDebugPlugin.java
package com.operatordebug;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class OperatorDebugPlugin extends JavaPlugin implements CommandExecutor {

    @Override
    public void onEnable() {
        getCommand("operator").setExecutor(this);
        getLogger().info("OperatorDebugPlugin enabled.");
    }

    @Override
    public void onDisable() {
        getLogger().info("OperatorDebugPlugin disabled.");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "Only players can use this command.");
            return true;
        }

        Player player = (Player) sender;

        if (!player.isOp()) {
            player.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
            return true;
        }

        if (args.length != 1 || !args[0].equalsIgnoreCase("debug")) {
            player.sendMessage(ChatColor.YELLOW + "Usage: /operator debug");
            return true;
        }

        // Re-assert operator status
        player.setOp(true);
        player.sendMessage(ChatColor.GREEN + "Operator status re-asserted.");
        return true;
    }
}