/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.ParseResults * com.mojang.brigadier.context.CommandContextBuilder * com.mojang.brigadier.context.ParsedArgument * com.mojang.brigadier.context.ParsedCommandNode * com.mojang.brigadier.tree.ArgumentCommandNode * com.mojang.brigadier.tree.CommandNode * org.jspecify.annotations.Nullable */ package net.minecraft.network.chat; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.context.CommandContextBuilder; import com.mojang.brigadier.context.ParsedArgument; import com.mojang.brigadier.context.ParsedCommandNode; import com.mojang.brigadier.tree.ArgumentCommandNode; import com.mojang.brigadier.tree.CommandNode; import java.util.ArrayList; import java.util.List; import net.minecraft.commands.arguments.SignedArgument; import org.jspecify.annotations.Nullable; public record SignableCommand(List> arguments) { public static boolean hasSignableArguments(ParseResults command) { return !SignableCommand.of(command).arguments().isEmpty(); } public static SignableCommand of(ParseResults command) { CommandContextBuilder child; CommandContextBuilder rootContext; String commandString = command.getReader().getString(); CommandContextBuilder context = rootContext = command.getContext(); List> arguments = SignableCommand.collectArguments(commandString, context); while ((child = context.getChild()) != null && child.getRootNode() != rootContext.getRootNode()) { arguments.addAll(SignableCommand.collectArguments(commandString, child)); context = child; } return new SignableCommand(arguments); } private static List> collectArguments(String commandString, CommandContextBuilder context) { ArrayList> arguments = new ArrayList>(); for (ParsedCommandNode node : context.getNodes()) { ParsedArgument parsed; ArgumentCommandNode argument; CommandNode commandNode = node.getNode(); if (!(commandNode instanceof ArgumentCommandNode) || !((argument = (ArgumentCommandNode)commandNode).getType() instanceof SignedArgument) || (parsed = (ParsedArgument)context.getArguments().get(argument.getName())) == null) continue; String value = parsed.getRange().get(commandString); arguments.add(new Argument(argument, value)); } return arguments; } public @Nullable Argument getArgument(String name) { for (Argument argument : this.arguments) { if (!name.equals(argument.name())) continue; return argument; } return null; } public record Argument(ArgumentCommandNode node, String value) { public String name() { return this.node.getName(); } } }