package de.mrgeorgen.wolfSignal; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.minecraft.client.network.ClientCommandSource; import java.util.*; import static de.mrgeorgen.wolfSignal.Main.MOD_ID; public final class ClientCommands { private ClientCommands() { } private static final List> commands = new ArrayList<>(); public static boolean contains(String command) { // checks if command starts with ' ' and looks for a command literal to match the second word in the command return command.startsWith(MOD_ID + " ") && commands.stream().map(LiteralArgumentBuilder::getLiteral).anyMatch(command.substring(MOD_ID.length() + 1).split(" ", 2)[0]::equals); } // register commands more or less the usual way public static void register(LiteralArgumentBuilder command) { commands.add(command); } // variants of static methods literal and argument from net.minecraft.server.command.CommandManager replacing ServerCommandSource with ClientCommandSource public static LiteralArgumentBuilder literal(String literal) { return LiteralArgumentBuilder.literal(literal); } public static RequiredArgumentBuilder argument(String name, ArgumentType type) { return RequiredArgumentBuilder.argument(name, type); } // actually register the commands and add the prefix node public static void register(CommandDispatcher dispatcher) { commands.stream().map(literal(MOD_ID)::then).forEach(dispatcher::register); } }