1 package com.irtimaled.bbor.client.commands;
3 import com.mojang.brigadier.context.CommandContext;
4 import com.mojang.brigadier.context.ParsedCommandNode;
5 import com.mojang.brigadier.tree.CommandNode;
6 import com.mojang.brigadier.tree.LiteralCommandNode;
7 import net.minecraft.command.CommandSource;
8 import net.minecraft.util.text.TranslationTextComponent;
11 static void feedback(CommandContext<CommandSource> context, String format, Object... values) {
12 context.getSource().sendFeedback(new TranslationTextComponent(format, values), false);
15 static boolean lastNodeIsLiteral(CommandContext<CommandSource> context, String literal) {
16 CommandNode lastNode = getLastNode(context);
17 if (lastNode instanceof LiteralCommandNode) {
18 LiteralCommandNode literalCommandNode = (LiteralCommandNode) lastNode;
19 return literalCommandNode.getLiteral().equals(literal);
24 private static CommandNode getLastNode(CommandContext<CommandSource> context) {
25 ParsedCommandNode[] nodes = context.getNodes().toArray(new ParsedCommandNode[0]);
26 if (nodes.length == 0) return null;
27 return nodes[nodes.length - 1].getNode();