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

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.api.callbacks.MouseEvent;
import com.ptsmods.morecommands.miscellaneous.Command;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.InteractionEvent;
import dev.architectury.platform.Platform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Hand;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

public class PowerToolCommand extends Command {

    @Override
    public void preinit(boolean serverOnly) {
        if (Platform.getEnv() == EnvType.CLIENT) MouseEvent.EVENT.register((button, action, mods) -> checkPowerToolClient(action));
        else if (serverOnly) {
            InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> checkPowerToolServer(player, hand));
            InteractionEvent.RIGHT_CLICK_ITEM.register((player, hand) -> checkPowerToolServer(player, hand).isTrue() ?
                    CompoundEventResult.interruptTrue(player.getStackInHand(hand)) : CompoundEventResult.pass());
        }
    }

    @Environment(EnvType.CLIENT)
    private boolean checkPowerToolClient(int action) {
        PlayerEntity player = MinecraftClient.getInstance().player;
        if (player != null && action == 1 && MinecraftClient.getInstance().currentScreen == null) {
            String cmd = Optional.ofNullable(getPowerTool(player, Hand.MAIN_HAND)).orElse(getPowerTool(player, Hand.OFF_HAND));
            if (cmd != null) {
                MinecraftClient.getInstance().player.sendChatMessage("/" + cmd);
                return true;
            }
        }
        return false;
    }

    @Environment(EnvType.SERVER)
    private EventResult checkPowerToolServer(PlayerEntity player, Hand hand) {
        if (player != null) {
            String cmd = getPowerTool(player, hand);<commit_msg>Fix powertool commands being sent as messages<commit_after>package com.ptsmods.morecommands.commands.server.unelevated;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.ptsmods.morecommands.MoreCommands;
import com.ptsmods.morecommands.api.callbacks.MouseEvent;
import com.ptsmods.morecommands.api.util.compat.client.ClientCompat;
import com.ptsmods.morecommands.miscellaneous.Command;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.InteractionEvent;
import dev.architectury.platform.Platform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Hand;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

public class PowerToolCommand extends Command {

    @Override
    public void preinit(boolean serverOnly) {
        if (Platform.getEnv() == EnvType.CLIENT) MouseEvent.EVENT.register((button, action, mods) -> checkPowerToolClient(action));
        else if (serverOnly) {
            InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> checkPowerToolServer(player, hand));
            InteractionEvent.RIGHT_CLICK_ITEM.register((player, hand) -> checkPowerToolServer(player, hand).isTrue() ?
                    CompoundEventResult.interruptTrue(player.getStackInHand(hand)) : CompoundEventResult.pass());
        }
    }

    @Environment(EnvType.CLIENT)
    private boolean checkPowerToolClient(int action) {
        PlayerEntity player = MinecraftClient.getInstance().player;
        if (player != null && action == 1 && MinecraftClient.getInstance().currentScreen == null) {
            String cmd = Optional.ofNullable(getPowerTool(player, Hand.MAIN_HAND)).orElse(getPowerTool(player, Hand.OFF_HAND));
            if (cmd != null) {
                ClientCompat.get().sendMessageOrCommand("/" + cmd);
                return true;
            }
        }
        return false;
    }

    @Environment(EnvType.SERVER)
    private EventResult checkPowerToolServer(PlayerEntity player, Hand hand) {
        if (player != null) {
            String cmd = getPowerTool(player, hand);
{'fraction_non_alphanumeric': 0.10607940446650124, 'fraction_numerical': 0.00041356492969396195, 'mean_word_length': 4.054336468129572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '22587', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1357, 'n_words': 241}