]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/commands/CommandHelper.java
Rework settings/config command
[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.tree.CommandNode;
5 import com.mojang.brigadier.tree.LiteralCommandNode;
6 import net.minecraft.command.CommandSource;
7 import net.minecraft.util.text.TextComponentTranslation;
8
9 class CommandHelper {
10     static void feedback(CommandContext<CommandSource> context, String format, Object... values) {
11         context.getSource().sendFeedback(new TextComponentTranslation(format, values), false);
12     }
13
14     static boolean lastNodeIsLiteral(CommandContext<CommandSource> context, String literal) {
15         CommandNode lastNode = getLastNode(context);
16         if (lastNode instanceof LiteralCommandNode) {
17             LiteralCommandNode literalCommandNode = (LiteralCommandNode) lastNode;
18             return literalCommandNode.getLiteral().equals(literal);
19         }
20         return false;
21     }
22
23     private static CommandNode getLastNode(CommandContext<CommandSource> context) {
24         CommandNode[] nodes = context.getNodes().keySet().toArray(new CommandNode[0]);
25         return nodes[nodes.length-1];
26     }
27 }