/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.StringReader * com.mojang.brigadier.arguments.ArgumentType * com.mojang.brigadier.context.CommandContext * com.mojang.brigadier.exceptions.CommandSyntaxException * com.mojang.brigadier.exceptions.DynamicCommandExceptionType * com.mojang.datafixers.util.Either * com.mojang.datafixers.util.Pair */ package net.minecraft.commands.arguments.item; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.network.chat.Component; import net.minecraft.resources.Identifier; public class FunctionArgument implements ArgumentType { private static final Collection EXAMPLES = Arrays.asList("foo", "foo:bar", "#foo"); private static final DynamicCommandExceptionType ERROR_UNKNOWN_TAG = new DynamicCommandExceptionType(tag -> Component.translatableEscape("arguments.function.tag.unknown", tag)); private static final DynamicCommandExceptionType ERROR_UNKNOWN_FUNCTION = new DynamicCommandExceptionType(value -> Component.translatableEscape("arguments.function.unknown", value)); public static FunctionArgument functions() { return new FunctionArgument(); } public Result parse(StringReader reader) throws CommandSyntaxException { if (reader.canRead() && reader.peek() == '#') { reader.skip(); final Identifier id = Identifier.read(reader); return new Result(){ @Override public Collection> create(CommandContext c) throws CommandSyntaxException { return FunctionArgument.getFunctionTag(c, id); } @Override public Pair, Collection>>> unwrap(CommandContext context) throws CommandSyntaxException { return Pair.of((Object)id, (Object)Either.right(FunctionArgument.getFunctionTag(context, id))); } @Override public Pair>> unwrapToCollection(CommandContext context) throws CommandSyntaxException { return Pair.of((Object)id, FunctionArgument.getFunctionTag(context, id)); } }; } final Identifier id = Identifier.read(reader); return new Result(){ @Override public Collection> create(CommandContext c) throws CommandSyntaxException { return Collections.singleton(FunctionArgument.getFunction(c, id)); } @Override public Pair, Collection>>> unwrap(CommandContext context) throws CommandSyntaxException { return Pair.of((Object)id, (Object)Either.left(FunctionArgument.getFunction(context, id))); } @Override public Pair>> unwrapToCollection(CommandContext context) throws CommandSyntaxException { return Pair.of((Object)id, Collections.singleton(FunctionArgument.getFunction(context, id))); } }; } private static CommandFunction getFunction(CommandContext c, Identifier id) throws CommandSyntaxException { return ((CommandSourceStack)c.getSource()).getServer().getFunctions().get(id).orElseThrow(() -> ERROR_UNKNOWN_FUNCTION.create((Object)id.toString())); } private static Collection> getFunctionTag(CommandContext c, Identifier id) throws CommandSyntaxException { List> tag = ((CommandSourceStack)c.getSource()).getServer().getFunctions().getTag(id); if (tag == null) { throw ERROR_UNKNOWN_TAG.create((Object)id.toString()); } return tag; } public static Collection> getFunctions(CommandContext context, String name) throws CommandSyntaxException { return ((Result)context.getArgument(name, Result.class)).create(context); } public static Pair, Collection>>> getFunctionOrTag(CommandContext context, String name) throws CommandSyntaxException { return ((Result)context.getArgument(name, Result.class)).unwrap(context); } public static Pair>> getFunctionCollection(CommandContext context, String name) throws CommandSyntaxException { return ((Result)context.getArgument(name, Result.class)).unwrapToCollection(context); } public Collection getExamples() { return EXAMPLES; } public static interface Result { public Collection> create(CommandContext var1) throws CommandSyntaxException; public Pair, Collection>>> unwrap(CommandContext var1) throws CommandSyntaxException; public Pair>> unwrapToCollection(CommandContext var1) throws CommandSyntaxException; } }