forked from mmbednarek/minecpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimateBlocks.cpp
More file actions
59 lines (44 loc) · 1.66 KB
/
DecimateBlocks.cpp
File metadata and controls
59 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <minecpp/command/core/DecimateBlocks.h>
#include <minecpp/command/RuntimeContext.h>
#include "minecpp/entity/Aliases.hpp"
#include "minecpp/entity/component/Abilities.h"
namespace minecpp::command::core {
bool DecimateBlocks::is_flag(std::string_view /*name*/) const
{
return false;
}
Object::Ptr DecimateBlocks::run(RuntimeContext &ctx, CommandInput &input) const
{
bool should_enable = true;
if (input.arg_count() > 1)
return make_error(command_name, "too many arguments");
if (input.arg_count() == 1) {
auto enable = input.arg<std::string>(0);
if (enable == "off") {
should_enable = false;
} else if (enable != "on") {
return make_error(command_name, "invalid first argument");
}
}
auto *world = ctx.world();
if (world == nullptr)
return make_error(command_name, "command invoked outside of a world");
auto entity = ctx.entity();
if (not entity.has_value())
return make_error(command_name, "no active entity");
if (not entity->has_component<AbilitiesComponent>())
return make_error(command_name, "active entity doesn't have abilities");
entity->component<AbilitiesComponent>().set_can_instantly_destroy_blocks(*world, should_enable);
auto info = std::make_shared<FormattedString>();
info->bold(format::Color::Green, "INFO ");
info->text(format::Color::White, "instantly destroy blocks: ");
info->text(format::Color::Yellow, should_enable ? "on" : "off");
ctx.out().write(info);
// return info;
return nullptr;
}
ObjectType DecimateBlocks::return_type(RuntimeContext & /*ctx*/) const
{
return command_return_type;
}
}// namespace minecpp::command::core