Itzalphadp

Act as an expert Minecraft Spigot/Paper Plugin Developer. Write a complete, production-ready Spigot/Paper plugin (compatible with 1.20+) that integrates directly with LuckPerms API to automatically create ranks, set prefixes, and batch-assign permissions using a single command.

Key Requirements & Features:

  1. LuckPerms API Hook:

- Softdepend or Depend on 'LuckPerms' in plugin.yml. - Hook into LuckPerms using LuckPermsProvider.get() on plugin enable. - Safely handle cases where LuckPerms is not installed or loaded.

  1. Command Functionality:

- Command: /createrank <rank_name> <prefix> [permission1,permission2,...] - Permission required: rankcreator.admin

  1. Execution Logic (Using LuckPerms API):

- Check if group/rank exists; if not, create it asynchronously using GroupManager#createAndLoadGroup(name). - Add a prefix node with priority 100 using PrefixNode.builder(prefix, 100).build(). Replace underscores _ with spaces in prefix formatting. - Parse comma-separated permissions (e.g., essentials.fly,essentials.heal) and add each as a PermissionNode. - Save the modified group back to LuckPerms using GroupManager#saveGroup(group).

  1. Deliverables:

- Complete plugin.yml with command definitions, LuckPerms dependency, and API version. - Fully written, functional Java main class with all necessary imports, color-formatted sender messages, and clean error handling. Do not use pseudocode or placeholders.

Kodari AI
KodariSep 21 at 6:40 pm 1
RankCreatorPlugin
Automates rank creation in LuckPerms via a single command. Creates groups asynchronously, sets prefixes with priority, and batch-assigns permissions. Integrates with LuckPerms API, handles missing dependency gracefully, and provides color-formatted feedback. Command: /createrank with rankcreator.admin permission.

Plan:

  1. Add the Gradle project configuration for Paper 1.20+ and LuckPerms API.

  2. Add the plugin descriptor with the command, permission, and LuckPerms soft dependency.

  3. Add the main plugin class with safe LuckPerms hooking, asynchronous rank creation/update, and sender feedback.

Created the complete RankCreator plugin project:

  • Added Gradle configuration for Paper 1.20+ and LuckPerms API.

  • Added plugin.yml with:

    • /createrank <rank_name> <prefix> [permission1,permission2,...]

    • rankcreator.admin permission

    • LuckPerms soft dependency

  • Added RankCreatorPlugin with:

    • Safe LuckPerms detection and runtime recovery

    • Asynchronous group creation/loading and saving

    • Prefix creation at priority 100

    • Underscore-to-space prefix formatting

    • Comma-separated permission assignment

    • Color-formatted success and error messages

    • Existing group update support

Itzalphadp

Done

Kodari AI
KodariSep 21 at 6:41 pm 1

The RankCreator plugin is complete and ready to build and deploy with LuckPerms installed.

Itzalphadp

Install

Kodari AI
KodariSep 21 at 6:43 pm 1

I can’t deploy directly to a live server without access to its files or host. Install it manually:

  1. Build the plugin:

    Shell
    ./gradlew build
    
  2. Copy the generated JAR from:

    Plain Text
    build/libs/
    

    into your server’s:

    Plain Text
    plugins/
    
  3. Ensure LuckPerms is also installed in plugins/.

  4. Restart the server.

  5. Verify with:

    Plain Text
    /plugins
    
  6. Create a rank:

    Plain Text
    /createrank moderator &bModerator essentials.fly,essentials.heal
    

The executing account must have rankcreator.admin.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 174
src/main/java/com/kodari/rankcreator/RankCreatorPlugin.java
package com.kodari.rankcreator;

import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.node.types.PermissionNode;
import net.luckperms.api.node.types.PrefixNode;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.concurrent.CompletableFuture;

public final class RankCreatorPlugin extends JavaPlugin implements CommandExecutor {

    private LuckPerms luckPerms;

    @Override
    public void onEnable() {
        try {
            this.luckPerms = LuckPermsProvider.get();
            getLogger().info("Hooked into LuckPerms.");
        } catch (IllegalStateException exception) {
            this.luckPerms = null;
            getLogger().warning("LuckPerms is not available. /createrank will be unavailable until it is loaded.");
        }

        if (getCommand("createrank") == null) {
            getLogger().severe("The createrank command is missing from plugin.yml.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        getCommand("createrank").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("rankcreator.admin")) {
            sendMessage(sender, "&cYou do not have permission to use this command.");
            return true;
        }

        if (args.length < 2 || args.length > 3) {
            sendMessage(sender, "&eUsage: /createrank <rank_name> <prefix> [permission1,permission2,...]");
            return true;
        }

        if (luckPerms == null) {
            try {
                this.luckPerms = LuckPermsProvider.get();
            } catch (IllegalStateException exception) {
                sendMessage(sender, "&cLuckPerms is not installed or is not loaded yet.");
                return true;
            }
        }

        String rankName = args[0].trim();
        String prefix = args[1].replace('_', ' ');
        String permissions = args.length == 3 ? args[2] : "";

        if (rankName.isEmpty()) {
            sendMessage(sender, "&cThe rank name cannot be empty.");
            return true;
        }

        createOrUpdateRank(sender, rankName, prefix, permissions);
        sendMessage(sender, "&7Creating or updating rank &f" + rankName + "&7...");
        return true;
    }

    private void createOrUpdateRank(CommandSender sender, String rankName, String prefix, String rawPermissions) {
        var groupManager = luckPerms.getGroupManager();
        Group existingGroup = groupManager.getGroup(rankName);

        CompletableFuture<Group> groupFuture = existingGroup == null
                ? groupManager.createAndLoadGroup(rankName)
                : CompletableFuture.completedFuture(existingGroup);

        groupFuture
                .thenCompose(group -> {
                    group.data().add(PrefixNode.builder(prefix, 100).build());

                    for (String permission : rawPermissions.split(",")) {
                        String trimmedPermission = permission.trim();
                        if (!trimmedPermission.isEmpty()) {
                            group.data().add(PermissionNode.builder(trimmedPermission).build());
                        }
                    }

                    return groupManager.saveGroup(group).thenApply(ignored -> group);
                })
                .whenComplete((group, throwable) -> Bukkit.getScheduler().runTask(this, () -> {
                    if (throwable != null) {
                        Throwable cause = rootCause(throwable);
                        String reason = cause.getMessage();
                        if (reason == null || reason.isBlank()) {
                            reason = "an unknown error occurred";
                        }
                        sendMessage(sender, "&cCould not save rank &f" + rankName + "&c: " + reason);
                        getLogger().warning("Could not save LuckPerms group '" + rankName + "': " + reason);
                        return;
                    }

                    sendMessage(sender, "&aRank &f" + rankName + " &awas created or updated successfully.");
                }));
    }

    private Throwable rootCause(Throwable throwable) {
        Throwable cause = throwable;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        return cause;
    }

    private void sendMessage(CommandSender sender, String message) {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&bRankCreator&8] &r" + message));
    }
}