<commit_before>package com.ptsmods.morecommands.commands.server.unelevated;

import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.api.IDataTrackerHelper;
import com.ptsmods.morecommands.api.IMoreCommands;
import com.ptsmods.morecommands.miscellaneous.Command;
import com.ptsmods.morecommands.miscellaneous.MoreGameRules;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Style;
import net.minecraft.util.Formatting;

import java.util.List;
import java.util.Objects;

public class VaultCommand extends Command {
    public static final List<ScreenHandlerType<GenericContainerScreenHandler>> types = ImmutableList.of(ScreenHandlerType.GENERIC_9X1, ScreenHandlerType.GENERIC_9X2,
            ScreenHandlerType.GENERIC_9X3, ScreenHandlerType.GENERIC_9X4, ScreenHandlerType.GENERIC_9X5, ScreenHandlerType.GENERIC_9X6);

    @Override
    public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
        dispatcher.register(literalReq("vault")
                .then(argument("vault", IntegerArgumentType.integer(1))
                        .executes(ctx -> execute(ctx, ctx.getSource().getPlayerOrThrow()))
                        .then(argument("player", EntityArgumentType.player())
                                .requires(IS_OP)
                                .executes(ctx -> execute(ctx, EntityArgumentType.getPlayer(ctx, "player"))))));
    }

    public int execute(CommandContext<ServerCommandSource> ctx, ServerPlayerEntity owner) throws CommandSyntaxException {
        int vault = ctx.getArgument("vault", Integer.class);
        int maxVaults = getCountFromPerms(ctx.getSource(), "morecommands.vault.max.", ctx.getSource().getWorld().getGameRules().getInt(MoreGameRules.get().vaultsRule()));
        if (maxVaults == 0) sendError(ctx, "Vaults are disabled on this server.");
        else if (vault > maxVaults) sendError(ctx, (owner == ctx.getSource().getPlayerOrThrow() ? "You" : IMoreCommands.get().textToString(owner.getDisplayName(), Style.EMPTY.withColor(Formatting.RED), true)) +
                " may only have " + Formatting.DARK_RED + ctx.getSource().getWorld().getGameRules().getInt(MoreGameRules.get().vaultsRule()) + Formatting.RED + " vaults.");
        else {
            int rows = getCountFromPerms(ctx.getSource(), "morecommands.vault.rows.", ctx.getSource().getWorld().getGameRules().getInt(MoreGameRules.get().vaultRowsRule()));
            ctx.getSource().getPlayerOrThrow().openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, inv, player) -> new GenericContainerScreenHandler(types.get(rows - 1), syncId, inv,
                    Objects.requireNonNull(getVault(vault, owner)), rows), literalText("" + DF + Formatting.BOLD + "Vault " + SF + Formatting.BOLD + vault).build()));<commit_msg>Require perm for opening others' vaults instead of OP<commit_after>package com.ptsmods.morecommands.commands.server.unelevated;

import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.api.IDataTrackerHelper;
import com.ptsmods.morecommands.api.IMoreCommands;
import com.ptsmods.morecommands.miscellaneous.Command;
import com.ptsmods.morecommands.miscellaneous.MoreGameRules;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Style;
import net.minecraft.util.Formatting;

import java.util.List;
import java.util.Objects;

public class VaultCommand extends Command {
    public static final List<ScreenHandlerType<GenericContainerScreenHandler>> types = ImmutableList.of(ScreenHandlerType.GENERIC_9X1, ScreenHandlerType.GENERIC_9X2,
            ScreenHandlerType.GENERIC_9X3, ScreenHandlerType.GENERIC_9X4, ScreenHandlerType.GENERIC_9X5, ScreenHandlerType.GENERIC_9X6);

    @Override
    public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
        dispatcher.register(literalReq("vault")
                .then(argument("vault", IntegerArgumentType.integer(1))
                        .executes(ctx -> execute(ctx, ctx.getSource().getPlayerOrThrow()))
                        .then(argument("player", EntityArgumentType.player())
                                .requires(hasPermissionOrOp("morecommands.vault.others"))
                                .executes(ctx -> execute(ctx, EntityArgumentType.getPlayer(ctx, "player"))))));
    }

    public int execute(CommandContext<ServerCommandSource> ctx, ServerPlayerEntity owner) throws CommandSyntaxException {
        int vault = ctx.getArgument("vault", Integer.class);
        int maxVaults = getCountFromPerms(ctx.getSource(), "morecommands.vault.max.", ctx.getSource().getWorld().getGameRules().getInt(MoreGameRules.get().vaultsRule()));
        if (maxVaults == 0) sendError(ctx, "Vaults are disabled on this server.");
        else if (vault > maxVaults) sendError(ctx, (owner == ctx.getSource().getPlayerOrThrow() ? "You" : IMoreCommands.get().textToString(owner.getDisplayName(), Style.EMPTY.withColor(Formatting.RED), true)) +
                " may only have " + Formatting.DARK_RED + ctx.getSource().getWorld().getGameRules().getInt(MoreGameRules.get().vaultsRule()) + Formatting.RED + " vaults.");
        else {
            int rows = getCountFromPerms(ctx.getSource(), "morecommands.vault.rows.", ctx.getSource().getWorld().getGameRules().getInt(MoreGameRules.get().vaultRowsRule()));
            ctx.getSource().getPlayerOrThrow().openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, inv, player) -> new GenericContainerScreenHandler(types.get(rows - 1), syncId, inv,
                    Objects.requireNonNull(getVault(vault, owner)), rows), literalText("" + DF + Formatting.BOLD + "Vault " + SF + Formatting.BOLD + vault).build()));
{'fraction_non_alphanumeric': 0.11681537405628002, 'fraction_numerical': 0.004118050789293068, 'mean_word_length': 4.76880443388757, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4158653', 'n_tokens_mistral': 2090, 'n_tokens_neox': 2083, 'n_words': 323}