Snxz26 GamingYT
๐Ÿ“Ž 1 file 1,064 chars
๐Ÿ“„
pasted-code-1794720005816.txt
txt 16 lines
โ–ถ
Create a Minecraft admin plugin using the latest Paper API (version 26.3) with the following features:

Op-toggle command
A configurable command (default /cc) that lets a permitted player toggle their own op status on and off without needing console access.
If they are currently opped, the command de-ops them. If they are currently de-opped, it re-ops them.
Permission-checked access
Only players with a specific configurable permission node (e.g., coreutils.toggle) can use the command.
All other players should have no access and receive no response if they try to use it.
Configurable settings
Command name, permission node, and plugin behavior should all be editable through a config file without touching the plugin code.
Quiet command output
Command feedback and responses should only be visible to the player who used the command, not broadcast to all players in chat.
Audit logging
All uses of the command should be logged clearly in the server console/log file for transparency.
Paper API 26.3
Must be built using the latest Paper API version 26.3 only.
Kodari AI
KodariNov 15 at 5:20 am 1
OpToggleManager
A Minecraft Paper plugin providing a configurable op-toggle command (default /cc) that lets permitted players toggle their own operator status on and off. The command name and permission node are configurable via a config file. Only players with the specified permission can use the command; unauthorized players receive no response. Command feedback is private to the user, not broadcast. All command uses are logged to the server console for audit transparency. Built exclusively with Paper API 26.3, featuring a lightweight command handler, YAML configuration loading, and permission-based access control for secure operator management.

Created the configurable, audited /cc op toggle. Unauthorized attempts receive no response.

Grant coreutils.toggle explicitly through a permissions plugin so players retain access after de-opping. Restart the server after changing the command or permission in config.yml.

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

import java.util.Locale;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.java.JavaPlugin;

public final class CoreUtils extends JavaPlugin implements Listener {
    private String commandName;
    private String permissionNode;
    private Permission registeredPermission;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        commandName = getConfig().getString("command", "cc").trim().toLowerCase(Locale.ROOT);
        permissionNode = getConfig().getString("permission", "coreutils.toggle").trim();
        if (!commandName.matches("[a-z0-9_-]+") || permissionNode.isEmpty()) {
            getLogger().severe("Invalid command or permission in config.yml; disabling CoreUtils.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        if (getServer().getPluginManager().getPermission(permissionNode) == null) {
            registeredPermission = new Permission(permissionNode, PermissionDefault.FALSE);
            getServer().getPluginManager().addPermission(registeredPermission);
        }
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        if (registeredPermission != null) {
            getServer().getPluginManager().removePermission(registeredPermission);
        }
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onCommand(PlayerCommandPreprocessEvent event) {
        String input = event.getMessage().substring(1);
        String label = input.split("\\s+", 2)[0];
        if (!label.equalsIgnoreCase(commandName)) {
            return;
        }
        event.setCancelled(true);
        Player player = event.getPlayer();
        UUID id = player.getUniqueId();
        if (!player.hasPermission(permissionNode)) {
            getLogger().info("Denied /" + commandName + " from " + player.getName() + " (" + id + ")");
            return;
        }
        boolean enable = !player.isOp();
        try {
            player.setOp(enable);
            getLogger().info(player.getName() + " (" + id + ") used /" + commandName
                    + ": operator status " + (enable ? "enabled" : "disabled"));
            String key = enable ? "messages.op-enabled" : "messages.op-disabled";
            String fallback = enable ? "&aOperator status enabled." : "&eOperator status disabled.";
            String message = getConfig().getString(key, fallback);
            if (message != null && !message.isEmpty()) {
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
            }
        } catch (RuntimeException ex) {
            getLogger().log(Level.SEVERE, "Failed /" + commandName + " for " + player.getName() + " (" + id + ")", ex);
            player.sendMessage(ChatColor.RED + "Could not change operator status; check the server log.");
        }
    }
}