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.server.command.ServerCommandSource;
8 import net.minecraft.text.MutableText;
9 import net.minecraft.text.TranslatableTextContent;
12 static void feedback(CommandContext<ServerCommandSource> context, String format, Object... values) {
13 context.getSource().sendFeedback(MutableText.of(new TranslatableTextContent(format, values)), false);
16 static boolean lastNodeIsLiteral(CommandContext<ServerCommandSource> context, String literal) {
17 CommandNode lastNode = getLastNode(context);
18 if (lastNode instanceof LiteralCommandNode) {
19 LiteralCommandNode literalCommandNode = (LiteralCommandNode) lastNode;
20 return literalCommandNode.getLiteral().equals(literal);
25 private static CommandNode getLastNode(CommandContext<ServerCommandSource> context) {
26 ParsedCommandNode[] nodes = context.getNodes().toArray(new ParsedCommandNode[0]);
27 if (nodes.length == 0) return null;
28 return nodes[nodes.length - 1].getNode();