]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/commands/CommandHelper.java
bd432de5121f0bea5fb6c8302d95874201df15e1
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / commands / CommandHelper.java
1 package com.irtimaled.bbor.client.commands;
2
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;
9
10 class CommandHelper {
11     static void feedback(CommandContext<CommandSource> context, String format, Object... values) {
12         context.getSource().sendFeedback(new TranslationTextComponent(format, values), false);
13     }
14
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);
20         }
21         return false;
22     }
23
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();
28     }
29 }