-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "Command.h" | ||
#include "Config/Config.h" | ||
|
||
#include "form/index.h" | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <iostream> | ||
#include <ll/api/Logger.h> | ||
#include <ll/api/command/Command.h> | ||
#include <ll/api/command/CommandHandle.h> | ||
#include <ll/api/command/CommandRegistrar.h> | ||
#include <ll/api/plugin/NativePlugin.h> | ||
#include <ll/api/service/Bedrock.h> | ||
#include <ll/api/utils/HashUtils.h> | ||
#include <mc/entity/utilities/ActorType.h> | ||
#include <mc/server/commands/CommandOrigin.h> | ||
#include <mc/server/commands/CommandOriginType.h> | ||
#include <mc/server/commands/CommandOutput.h> | ||
#include <mc/server/commands/CommandParameterOption.h> | ||
#include <mc/server/commands/CommandPermissionLevel.h> | ||
#include <mc/server/commands/CommandRegistry.h> | ||
#include <mc/server/commands/CommandSelector.h> | ||
#include <mc/world/actor/Actor.h> | ||
#include <mc/world/actor/player/Player.h> | ||
#include <memory> | ||
#include <numeric> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <utility> | ||
|
||
|
||
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<Player*>(entity); | ||
tools::form::index(player); | ||
} | ||
}>(); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace tools::command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
namespace tools::command { | ||
|
||
bool regCommand(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <ll/api/form/SimpleForm.h> | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "mc/world/actor/player/Player.h" | ||
|
||
namespace tools::form { | ||
|
||
void index(Player& player); | ||
|
||
|
||
} // namespace tools::form |