package net.minecraft.server.commands;

import com.mojang.brigadier.Message;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.MinecraftServer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.dimension.DimensionType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.world.Difficulty;
import net.minecraft.commands.Commands;
import net.minecraft.commands.CommandSourceStack;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;

public class DifficultyCommand {
    private static final DynamicCommandExceptionType ERROR_ALREADY_DIFFICULT;
    
    public static void register(final CommandDispatcher<CommandSourceStack> commandDispatcher) {
        final LiteralArgumentBuilder<CommandSourceStack> literalArgumentBuilder2 = Commands.literal("difficulty");
        for (final Difficulty aji6 : Difficulty.values()) {
            literalArgumentBuilder2.then(Commands.literal(aji6.getKey()).executes(commandContext -> setDifficulty((CommandSourceStack)commandContext.getSource(), aji6)));
        }
        commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)literalArgumentBuilder2.requires(cq -> cq.hasPermission(2))).executes(commandContext -> {
            final Difficulty aji2 = ((CommandSourceStack)commandContext.getSource()).getLevel().getDifficulty();
            ((CommandSourceStack)commandContext.getSource()).sendSuccess(new TranslatableComponent("commands.difficulty.query", new Object[] { aji2.getDisplayName() }), false);
            return aji2.getId();
        }));
    }
    
    public static int setDifficulty(final CommandSourceStack cq, final Difficulty aji) throws CommandSyntaxException {
        final MinecraftServer minecraftServer3 = cq.getServer();
        if (minecraftServer3.getLevel(DimensionType.OVERWORLD).getDifficulty() == aji) {
            throw DifficultyCommand.ERROR_ALREADY_DIFFICULT.create(aji.getKey());
        }
        minecraftServer3.setDifficulty(aji, true);
        cq.sendSuccess(new TranslatableComponent("commands.difficulty.success", new Object[] { aji.getDisplayName() }), true);
        return 0;
    }
    
    static {
        final TranslatableComponent translatableComponent;
        ERROR_ALREADY_DIFFICULT = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("commands.difficulty.failure", new Object[] { object });
            return translatableComponent;
        });
    }
}
