package com.ptsmods.morecommands.commands.server.elevated;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.miscellaneous.Command;
import net.minecraft.item.ItemStack;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Formatting;

public class RenameCommand extends Command {
    @Override
    public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
        dispatcher.register(literalReqOp("rename")
                .then(argument("name", StringArgumentType.greedyString())
                        .executes(ctx -> {
                            ItemStack stack = ctx.getSource().getPlayerOrThrow().getMainHandStack();
                            if (stack.isEmpty()) sendError(ctx, "You are not holding an item.");
                            else {
                                String name = MoreCommands.translateFormattings(ctx.getArgument("name", String.class));
                                stack.setCustomName(literalText(name).build());
                                sendMsg(ctx, "The item has been renamed to " + name + Formatting.RESET + ".");
                                return 1;
                            }
                            return 0;
                        })));
    }

    @Override
    public String getDocsPath() {
        return "/elevated/rename";
    }
}

@@ -259,16 +259,77 @@
 ommand;%0A
+import com.ptsmods.morecommands.miscellaneous.MoreGameRules;%0A
 import n
@@ -1038,83 +1038,387 @@
 name
- = MoreCommands.translateFormattings(ctx.getArgument(%22name%22, String.class))
+Raw = ctx.getArgument(%22name%22, String.class);%0A                                String name = MoreGameRules.get().checkBooleanWithPerm(ctx.getSource().getWorld().getGameRules(),%0A                                        MoreGameRules.get().doItemColoursRule(), ctx.getSource().getEntity()) ?%0A                                        MoreCommands.translateFormattings(nameRaw) : nameRaw
 ;%0A  

Check gamerule before translating formattings