From fb09799670f0f913318f6c1477a55a04d904663d Mon Sep 17 00:00:00 2001 From: engsr6982 <109733049+engsr6982@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:13:31 +0800 Subject: [PATCH] chore: add command and form --- src/Command/Command.cpp | 81 +++++++++++++++++++++++++++++++++++++++++ src/Command/Command.h | 7 ++++ src/Config/Config.h | 4 +- src/Entry/Entry.cpp | 6 +++ src/Form/index.cpp | 20 ++++++++++ src/Form/index.h | 8 ++++ 6 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/Command/Command.cpp create mode 100644 src/Command/Command.h create mode 100644 src/Form/index.cpp create mode 100644 src/Form/index.h diff --git a/src/Command/Command.cpp b/src/Command/Command.cpp new file mode 100644 index 0000000..8b6d7f2 --- /dev/null +++ b/src/Command/Command.cpp @@ -0,0 +1,81 @@ +#include "Command.h" +#include "Config/Config.h" + +#include "form/index.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace tools::command { + +// clang-format off +#define CHECK_COMMAND_TYPE(currentType, targetType) \ + if (currentType != targetType) { \ + std::string targetTypeStr; \ + switch (targetType) { \ + case CommandOriginType::Player: targetTypeStr = "players"; break; \ + case CommandOriginType::CommandBlock: targetTypeStr = "command blocks"; break; \ + case CommandOriginType::MinecartCommandBlock: targetTypeStr = "minecart command blocks"; break; \ + case CommandOriginType::DevConsole: targetTypeStr = "the developer console"; break; \ + case CommandOriginType::Test: targetTypeStr = "test origins"; break; \ + case CommandOriginType::AutomationPlayer: targetTypeStr = "automation players"; break; \ + case CommandOriginType::ClientAutomation: targetTypeStr = "client automation"; break; \ + case CommandOriginType::DedicatedServer: targetTypeStr = "dedicated servers"; break; \ + case CommandOriginType::Entity: targetTypeStr = "entities"; break; \ + case CommandOriginType::Virtual: targetTypeStr = "virtual origins"; break; \ + case CommandOriginType::GameArgument: targetTypeStr = "game argument origins"; break; \ + case CommandOriginType::EntityServer: targetTypeStr = "entity servers"; break; \ + case CommandOriginType::Precompiled: targetTypeStr = "precompiled origins"; break; \ + case CommandOriginType::GameDirectorEntityServer: targetTypeStr = "game director entity servers"; break; \ + case CommandOriginType::Scripting: targetTypeStr = "scripting origins"; break; \ + case CommandOriginType::ExecuteContext: targetTypeStr = "execute contexts"; break; \ + default: targetTypeStr = "unknown"; \ + } \ + return output.error("This command is available to [" + targetTypeStr + "] only!"); \ + } +// clang-format on + +bool regCommand() { + auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand( + config::cfg.command.commandName, + config::cfg.command.commandDescription + ); + + // tools + cmd.overload().execute<[&](CommandOrigin const& origin, CommandOutput& output) { + CHECK_COMMAND_TYPE(origin.getOriginType(), CommandOriginType::Player); + Actor* entity = origin.getEntity(); + if (entity) { + auto& player = *static_cast(entity); + tools::form::index(player); + } + }>(); + + return true; +} + +} // namespace tools::command diff --git a/src/Command/Command.h b/src/Command/Command.h new file mode 100644 index 0000000..64aebe7 --- /dev/null +++ b/src/Command/Command.h @@ -0,0 +1,7 @@ + + +namespace tools::command { + +bool regCommand(); + +} \ No newline at end of file diff --git a/src/Config/Config.h b/src/Config/Config.h index 391d616..2c25c90 100644 --- a/src/Config/Config.h +++ b/src/Config/Config.h @@ -5,8 +5,8 @@ namespace tools::config { struct Configs { int version = 1; struct Command { - std::string commandName; - std::string commandDescription; + std::string commandName = "toosl"; + std::string commandDescription = "LeviOPTools"; } command; }; diff --git a/src/Entry/Entry.cpp b/src/Entry/Entry.cpp index 703fa62..ec83fc0 100644 --- a/src/Entry/Entry.cpp +++ b/src/Entry/Entry.cpp @@ -3,6 +3,10 @@ #include #include +// my files +#include "Command/Command.h" +#include "Config/Config.h" + namespace entry { entry::entry() = default; @@ -19,6 +23,7 @@ bool entry::load(ll::plugin::NativePlugin& self) { getSelf().getLogger().info("loading..."); // Code for loading the plugin goes here. + tools::config::loadConfig(); return true; } @@ -27,6 +32,7 @@ bool entry::enable() { getSelf().getLogger().info("enabling..."); // Code for enabling the plugin goes here. + tools::command::regCommand(); return true; } diff --git a/src/Form/index.cpp b/src/Form/index.cpp new file mode 100644 index 0000000..2e4222c --- /dev/null +++ b/src/Form/index.cpp @@ -0,0 +1,20 @@ +#include + +#include "Form/index.h" +#include "mc/world/actor/player/Player.h" + +namespace tools::form { + +void index(Player& player) { + using SimpleForm = ll::form::SimpleForm; + + SimpleForm fm; + fm.setTitle("default"); + fm.appendButton("call", [&](Player& player) { player.sendMessage("button 1"); }); + fm.sendTo(player, [](Player& player, int id) { + player.sendMessage("send"); // def + }); +} + + +} // namespace tools::form \ No newline at end of file diff --git a/src/Form/index.h b/src/Form/index.h new file mode 100644 index 0000000..6c2c061 --- /dev/null +++ b/src/Form/index.h @@ -0,0 +1,8 @@ +#include "mc/world/actor/player/Player.h" + +namespace tools::form { + +void index(Player& player); + + +} // namespace tools::form \ No newline at end of file