]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/commands/CommandHelper.java
Port to 1.19
[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.server.command.ServerCommandSource;
8 import net.minecraft.text.MutableText;
9 import net.minecraft.text.TranslatableTextContent;
10
11 class CommandHelper {
12     static void feedback(CommandContext<ServerCommandSource> context, String format, Object... values) {
13         context.getSource().sendFeedback(MutableText.of(new TranslatableTextContent(format, values)), false);
14     }
15
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);
21         }
22         return false;
23     }
24
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();
29     }
30 }