35class CommandRegistrar {
38 std::unique_ptr<Impl> impl;
41 CommandRegistrar(
bool isClient);
43 void disableModCommands(std::string_view modName);
45 char const* addText(CommandHandle&, std::string_view);
50 LLNDAPI
static CommandRegistrar& getInstance(
bool isClientSide);
52 [[nodiscard]]
static CommandRegistrar& getClientInstance() {
return getInstance(
true); }
54 [[nodiscard]]
static CommandRegistrar& getServerInstance() {
return getInstance(
false); }
58 LLNDAPI CommandHandle& getOrCreateCommand(
59 std::string
const& name,
60 std::string
const& description = {},
61 CommandPermissionLevel requirement = CommandPermissionLevel::Any,
63 std::weak_ptr<mod::Mod> mod = mod::NativeMod::current()
66 LLNDAPI Expected<std::unique_ptr<::Command>> compileCommand(
67 std::string_view commandStr,
69 ::CurrentCmdVersion version = CurrentCmdVersion::Latest
73 std::string_view commandStr,
75 ::CommandOutputType outputType = CommandOutputType::AllOutput,
76 ::CurrentCmdVersion version = CurrentCmdVersion::Latest
79 LLAPI
bool hasEnum(std::string
const& name);
81 LLAPI
bool tryRegisterEnum(
82 std::string
const& name,
83 std::vector<std::pair<std::string, uint64>> values,
85 CommandRegistry::ParseFunction parser
87 LLAPI
bool addEnumValues(
88 std::string
const& name,
89 std::vector<std::pair<std::string, uint64>> values,
93 LLAPI
bool tryRegisterRuntimeEnum(std::string
const& name, std::vector<std::pair<std::string, uint64>> values);
94 LLAPI
bool addRuntimeEnumValues(std::string
const& name, std::vector<std::pair<std::string, uint64>> values);
96 LLAPI
bool hasSoftEnum(std::string
const& name);
98 LLAPI
bool tryRegisterSoftEnum(std::string
const& name, std::vector<std::string> values);
100 LLAPI
bool addSoftEnumValues(std::string
const& name, std::vector<std::string> values);
102 LLAPI
bool removeSoftEnumValues(std::string
const& name, std::vector<std::string> values);
104 LLAPI
bool setSoftEnumValues(std::string
const& name, std::vector<std::string> values);
106 template <concepts::Require<std::is_enum> T>
107 inline bool tryRegisterEnum() {
108 static std::vector<std::pair<std::string, uint64>> values{[] {
109 std::vector<std::pair<std::string, uint64>> vals;
110 if constexpr (magic_enum::enum_count<T>() > 0) {
111 magic_enum::enum_for_each<T>([&](T enumVal) {
112 vals.emplace_back(magic_enum::enum_name(enumVal), (uint64)enumVal);
117 return tryRegisterEnum(
118 ::ll::command::enum_name_v<T>,
120 Bedrock::type_id<CommandRegistry, T>(),
121 &CommandRegistry::parse<T>
124 template <concepts::Require<std::is_enum> T>
125 inline bool tryRegisterRuntimeEnum() {
126 static std::vector<std::pair<std::string, uint64>> values{[] {
127 std::vector<std::pair<std::string, uint64>> vals;
128 if constexpr (magic_enum::enum_count<T>() > 0) {
129 magic_enum::enum_for_each<T>([&](T enumVal) {
130 vals.emplace_back(magic_enum::enum_name(enumVal), (uint64)enumVal);
135 return tryRegisterRuntimeEnum(::ll::command::enum_name_v<T>, values);
138 template <concepts::Specializes<SoftEnum> T>
139 inline bool tryRegisterSoftEnum() {
140 static std::vector<std::string> values{[] {
141 std::vector<std::string> vals;
142 using enum_type = remove_soft_enum_t<T>;
143 if constexpr (magic_enum::enum_count<enum_type>() > 0) {
144 magic_enum::enum_for_each<enum_type>([&](enum_type enumVal) {
145 vals.emplace_back(magic_enum::enum_name(enumVal));
150 return tryRegisterSoftEnum(::ll::command::enum_name_v<T>, values);